Format:LZX
| On this wiki | Facts · Code · Notes · Topics |
|---|
Microsoft's LZ77 + Huffman compression used in cabinet (.cab) files, CHM help, WIM images, Xbox 360 XEX2 images and MS-PATCH deltas: 32 KiB blocks, verbatim / aligned-offset / uncompressed block types and x86 E8 call translation.
In a cabinet the LZX window size (in bits) is stored in bits 8-12 of the folder's compression type; see Format:Microsoft Cabinet.
Overview
LZX (Microsoft) is an LZ77 coder with canonical Huffman codes, window sizes 2^15 to 2^21 bytes in the classic form (the later MS-PATCH "LZX DELTA" variant adds windows up to 2^25 and reference data). In CAB it is compression type 3 with the window order in bits 8-12 of the type word (libmspack cabd.c line 1249 at 55d5019761 passes (ct >> 8) & 0x1f to lzxd_init); see Format:WIM for the WIM use. Unverified: it also appears in CHM, WIM (window and chunk size 32768), the compressed base image of the Xbox 360 Format:XEX2 (Xbox 360 executable) and Windows patch files. LZX has no magic of its own; the container tells you the window size.
Structure (from the wimlib decoder)
- Block types: 1 verbatim, 2 aligned offset, 3 uncompressed (see Fact:LZX/enum/Block types).
- Match lengths 2 to 257; 8 length headers (7 primary lengths plus an escape to a length tree); up to 50 offset slots; three recent offsets with an offset adjustment of 2; extra offset bits up to 17; an aligned offset tree of 8 symbols (3-bit lengths); a pretree of 20 symbols (4-bit lengths); maximum codeword length 16 for main and length trees (Fact:LZX/behavior/Format limits).
- E8 preprocessing: x86 CALL (opcode E8) targets are converted from relative to absolute before compression and converted back after decompression, unless the stream cannot contain E8 bytes. In WIM the translation file size is fixed at 12,000,000; in the cabinet form the stream carries it (see Cabinet LZX details below). It is disabled in the last 6 bytes. It is harmless but useless on non-x86 data.
- The 1997 "Microsoft LZX Data Compression Format" document contains errors; wimlib's author points to [MS-PATCH] (2014) as the corrected specification.
Cabinet LZX details (libmspack)
From kyz/libmspack libmspack/mspack/lzxd.c at 55d5019761:
- Window size: regular LZX windows are 2^15 to 2^21 bytes, the LZX DELTA variant 2^17 to 2^25 (lines 289-296). Output is produced in frames of 32768 bytes (
LZX_FRAME_SIZE, lzx.h line 46). - Stream header (lines 447-452): one bit; if set, a 16-bit high word and a 16-bit low word form
intel_filesize; if clear it is 0 and no E8 translation is done. - E8 translation is applied to a frame only if
intel_startedandintel_filesizeare nonzero, the frame number is below 32768 and the frame is longer than 10 bytes (lines 706-708);intel_startedis set when the main tree gives the E8 literal a nonzero length (line 495) or when an uncompressed block is met (line 503). This differs from WIM, where wimlib says translation is always on with the fixed size 12000000 and is not switched off after the 32768th chunk (src/lzx_common.clines 147-167). - An uncompressed block aligns to a byte boundary and then carries 12 bytes: the three recent offsets R0, R1, R2 (lines 499-512). Block types are 1 verbatim, 2 aligned offset, 3 uncompressed.
Identification in binaries
Decoders carry offset-slot base and extra-bits tables (the maximum extra bits is 17, LZX_MAX_NUM_EXTRA_BITS, and there are at most 50 offset slots); the constant 12000000 (0xB71B00, LZX_WIM_MAGIC_FILESIZE in wimlib include/wimlib/lzx_constants.h line 94) points at a WIM-style decoder. libmspack's position-slot base table is in lzxd.c from line 218 (it starts 768, 1024, 1536).
Code & repositories
- https://github.com/ebiggers/wimlib @
cd5e231c348c255ae5088873b5a66ee0eb96fa07· license: LGPL-3.0-or-later OR GPL-3.0-or-later (declared by the contributor; GitHub's detector did not recognize COPYING)
Windows imaging library with small, commented LZX, XPRESS and LZMS decoders (LGPL-3.0-or-later; individual files LGPL-3.0/2.1+). Used here only for constants and format description.
Tested on: source read, not run: source read · checked 2026-10-18; last activity 2026-01-30 - https://github.com/kyz/libmspack @
55d501976171397ccd5d5a7a1ca7da065b1d9a06· license: LGPL-2.1-only (declared by the contributor; GitHub's detector did not recognize a license file)
libmspack (cabextract's library): CAB, CHM, LIT, HLP, KWAJ and SZDD decompressors with LZX, MSZIP and Quantum; mspack/cab.h defines the cabinet field offsets.
Tested on: source read, not run: source reading only · checked 2026-10-18; last activity 2026-07-21
See also
Format:Xpress, Format:LZNT1, Technique:Identifying compression libraries in binaries