Format:ZIP
| Vendor | PKWARE |
|---|---|
| Magic | 50 4B 03 04 (local header); 50 4B 05 06 (empty archive) |
| Extensions | .zip, .jar, .apk, .ipa, .msix, .pt |
| Endianness | little-endian |
| On this wiki | Facts · Code · Notes · Topics |
ZIP archive (PKWARE APPNOTE): per-file local headers PK\x03\x04, a central directory PK\x01\x02 and an end-of-central-directory record PK\x05\x06 at the end; the container under APK, JAR, IPA, MSIX, PyTorch and many other formats.
Overview
A ZIP file is read from the end: find the End Of Central Directory record (EOCD), follow it to the central directory, and from each central entry to its local header and data. Files may be prepended with other data (self-extractors, APK signing blocks), so offsets are relative to the start of the ZIP part and the EOCD is searched backwards from the end of the file (the trailing comment is at most 65535 bytes).
Record signatures (little-endian)
| Record | Signature | Bytes | Fixed size |
|---|---|---|---|
| Local file header | 0x04034b50 | 50 4B 03 04 | 30 + name + extra |
| Central directory header | 0x02014b50 | 50 4B 01 02 | 46 + name + extra + comment |
| End of central directory | 0x06054b50 | 50 4B 05 06 | 22 + comment |
| ZIP64 EOCD record | 0x06064b50 | 50 4B 06 06 | |
| ZIP64 EOCD locator | 0x07064b50 | 50 4B 06 07 | 20 |
| Data descriptor (optional signature) | 0x08074b50 | 50 4B 07 08 | 16, or 24 with ZIP64 |
Local file header offsets
0 signature, 4 version needed (2), 6 general-purpose flags (2), 8 compression method (2), 10 DOS time, 12 DOS date, 14 CRC-32, 18 compressed size, 22 uncompressed size, 26 name length, 28 extra length, 30 name. The central header adds version made by at 4 and shifts the rest by 2: flags 8, method 10, time 12, date 14, CRC 16, sizes 20 and 24, name len 28, extra len 30, comment len 32, disk start 34, internal attributes 36, external attributes 38 (Unix mode in the high 16 bits when made-by host is Unix), local header offset 42, name 46.
EOCD offsets
0 signature, 4 this disk, 6 disk of central directory, 8 entries on this disk, 10 total entries, 12 central directory size, 16 central directory offset, 20 comment length. The central directory is authoritative; local headers can disagree (a classic source of parser differentials and malware tricks).
General-purpose flags
Bit 0 encrypted; bit 3 sizes and CRC are zero in the local header and follow the data in a data descriptor; bit 6 strong encryption; bit 11 file name and comment are UTF-8; bit 13 central directory masked. Bits 1-2 refine the Deflate level (or LZMA end marker).
Compression methods
0 stored, 8 deflate, 9 deflate64, 12 bzip2, 14 LZMA, 93 Zstandard, 95 XZ, 98 PPMd, 99 WinZip AES. Deflate (raw, no zlib header) and stored cover almost every APK/JAR/IPA.
ZIP64
When a size, offset or count does not fit (0xFFFFFFFF or 0xFFFF in the 32/16-bit field), the real 64-bit values are in the extra field with id 0x0001, in the order uncompressed size, compressed size, local header offset, disk number, only for fields that were set to the maximum. For the EOCD, a ZIP64 locator sits just before it and points to the ZIP64 EOCD record.
Common extra-field ids
0x0001 ZIP64; 0x000a NTFS times; 0x5455 'UT' extended timestamp; 0x7875 'ux' Unix uid/gid; 0x7075 'up' Info-ZIP Unicode path (a UTF-8 name with a CRC of the header name); 0x6375 'uc' Info-ZIP Unicode comment (ZIP_EF_UTF_8_COMMENT in libzip; 0x7075 is ZIP_EF_UTF_8_NAME); 0x9901 WinZip AES; 0xCAFE JAR marker: java.util.jar.JarOutputStream.putNextEntry adds a zero-length 0xCAFE extra field to the first entry (JAR_MAGIC = 0xCAFE; openjdk/jdk @ 3104115c2a, src/java.base/share/classes/java/util/jar/JarOutputStream.java), which is how an executable JAR is recognised; it is not zipalign's; 0xD935 Android alignment padding.
Checked 2026-10-18: 0xD935 is ALIGNMENT_ZIP_EXTRA_DATA_FIELD_HEADER_ID in AOSP platform/tools/apksig ApkSigner.java (main @ 184702d9d1), with a minimum field size of 6 bytes, used to align uncompressed entries; AOSP's older C++ zipalign (platform/build tools/zipalign/ZipEntry.cpp) contains no such id. Compression method numbers 0, 8, 9, 12, 14, 93, 95, 98 match ZIP_CM_* in libzip lib/zip.h (nih-at/libzip @ a18bc6b560).
Reversing notes
- Identify ZIP-based formats by content: Format:APK (AndroidManifest.xml, classes.dex), Format:JAR (META-INF/MANIFEST.MF), Format:IPA (Payload/*.app), Format:MSIX package ([Content_Types].xml, AppxManifest.xml), Format:PyTorch model archive (data.pkl, uses Format:Python pickle).
- Stored entries can be read in place and are often aligned (zipalign, PyTorch 64-byte alignment) for mmap.
- Duplicate names, mismatched local/central data and overlapping entries are used to hide payloads; always prefer the central directory and compare.
Sources
PKWARE APPNOTE.TXT (zip file format specification); signatures and offsets also checked against miniz in https://github.com/kuba--/zip (src/miniz.h, Unlicense) and zlib contrib/minizip. The method ids, flags and extra ids other than 0x0001 come from the APPNOTE and are not re-read from code here.
Code & repositories
- https://github.com/kuba--/zip @
dd80aeab4293d1e11e31af20fabfd538d88625ef· license: MIT
Small zip library embedding miniz; header constants in src/miniz.h
Tested on: source read, not run: read miniz.h constants · checked 2026-10-18; last activity 2026-08-25
See also
Format:APK, Format:JAR, Format:IPA, Format:MSIX package, Format:PyTorch model archive, Format:Python pickle