Tool:UPX
| Developer | Markus Oberhumer, Laszlo Molnar and John Reiser |
|---|---|
| License | GPL-2.0-or-later with special exceptions |
| Website | https://upx.github.io |
| On this wiki | Facts · Code · Notes · Topics |
UPX is the open-source executable packer (GPL-2.0+ with a stub exception) for PE, ELF, Mach-O, DOS and other formats; packed files carry the magic "UPX!" and can normally be restored with upx -d.
Overview
UPX compresses an executable and adds a decompression stub; the packed program decompresses itself in memory on start. Compression methods in the source (src/conf.h): NRV2B/NRV2D/NRV2E (LE32, 8 and LE16 variants, ids 2-10) and LZMA (14); ids 15-17 (deflate, zstd, bzip2) are reserved and not used. Version read: 5.3.0.
Recognising UPX
- The 4 bytes
55 50 58 21("UPX!") start the pack header; in the stub source the next four bytes are A1 D8 D0 D5 (UPX_MAGIC2) and are overwritten at pack time with version, format, method and level. - PE files: sections
UPX0(virtual only, raw size 0: the decompression target),UPX1(stub plus compressed data) andUPX2or.rsrc(resources, imports). Section names can be renamed by hand to hide the packer; the "UPX!" header normally remains. - ELF and Mach-O: an
l_infotrailer (12 bytes) with the magic "UPX!" andb_infoblock headers (12 bytes each).
Pack header
See Fact:UPX/struct/Pack header (32 bytes for PE/ELF/Mach-O; 22 for DOS COM/SYS, 27 for DOS EXE). Byte 5 is the format id (UPX_F_xxx), byte 6 the compression method; the last byte is a checksum over the preceding bytes.
Unpacking
upx -d file restores the original (documented in doc/upx.pod). If the stub was altered (magic changed, header zeroed), restore the markers first or unpack by running to the OEP in a sandbox. Debug information is stripped by packing, so it is gone for good.
Source
Repository https://github.com/upx/upx; read: src/conf.h, src/packhead.cpp, src/packhead.h, src/pefile.cpp, src/stub/src/include/bsd.h, src/stub/src/include/header.S.
General background: Technique:Executable packing.
Code & repositories
- https://github.com/upx/upx @
c068381dfb00bfee2f754eaa313152ede043db82· license: GPL-2.0-or-later WITH LicenseRef-UPX-exception (declared by the contributor; GitHub's detector did not recognize LICENSE)
UPX source repository (packer for PE, ELF, Mach-O and other formats)
Tested on: source read, not run: source read only · checked 2026-10-18