Format:EXEPACK
| On this wiki | Facts · Code · Notes · Topics |
|---|
Microsoft's EXEPACK (EXEPACK.EXE, also built into LINK /EXEPACK) compresses a DOS MZ executable: a small decoder plus an "RB"-terminated header sit at the entry point, the program is RLE-compressed and the relocation table is stored packed after the decoder.
Identification
An EXEPACK file is an ordinary MZ executable (Format:DOS MZ executable) whose entry point CS:IP is header_size bytes into a segment, where the EXEPACK header lives: IP is 16, 18 or 20 (the header length), the MZ header has no relocations (the real table is packed inside), and the two bytes just before the entry point are the ASCII signature RB (52 42). The decoder code follows; it ends with the epilog CD 21 B8 FF 4C CD 21 (int 21h; mov ax,4CFFh; int 21h) which is followed by the 22-byte message "Packed file is corrupt" and then the compressed relocation table. Deark accepts a file when the 64 bytes at the entry point match one of three known decoder fingerprints, or when SP is 128 and RB is present, and finds the epilog 200-300 bytes after the entry point.
Header
Little-endian words starting at the entry segment (CS:0): real IP, real CS (signed, relative), mem_start (a placeholder), exepack_size (the packed size of header, decoder and relocation table), [20-byte header only: one extra word], real SP, real SS (signed), dest_len (the unpacked size in paragraphs), [18- and 20-byte headers: skip_len; the 16-byte form behaves as skip_len 1], then RB.
Decoder variants
Decoder lengths seen run from 256 to 291 bytes. Deark names these variants by a CRC of the decoder: common258 (EXEPACK 3.00/4.00 and others), common277 (LINK 3.60), common279 (EXEPACK 4.03), common283 (EXEPACK 4.05/4.06), common290 (LINK 5.60). To find the packed relocation table, take the pointer stored before the byte pattern 0E 1F 8B 1E 04 00 FC 33 (known at entry+135 to entry+148) and subtract IP; if that fails, use the pointer before the epilog plus 22.
Unpacking
Unpack by running deark's exepack module or an UNP-style tool; to do it by hand, decode the compressed stream (its records end with an opcode byte of B1 or B3, which the cited source treats as normal completion; Unverified: that opcodes B0/B2 are the non-final fill and copy forms, and that decoding runs backwards from the end of the image) and rebuild the MZ header and relocation table from the packed table. Unverified: the exact opcode semantics beyond what the cited source's completion test shows (it breaks the loop on opcode B1 or B3).
Code & repositories
- https://github.com/jsummers/deark @
8997059c4f32af79978fb6c83be7c1c26c259afa· license: MIT (declared by the contributor for the files used; GitHub reports MIT (read from COPYING; GitHub's API was busy) for the repository)
Deark (MIT): modules exepack, lzexe, pklite, diet, mscompress and the shared EXE detection in src/fmtutil-exe.c are the most complete open documentation of DOS packer recognition, MZ size computation and header layouts.
Tested on: source read, not run: Read the cited files at this commit; nothing built or run. · checked 2026-10-19
Pitfalls
- Unverified: some third-party tools patch the decoder ("EXPAKFIX" is one named in deark's comments), so fingerprints fail while the
RBplus epilog test still works.