zip_header.nx
buildroot/runtime/zip_header.nx
about
zip_header.nx -- parse PKZIP APPNOTE 6.3.x framing.
Parses two key structures in a .zip archive:
1. Local File Header (LFH) -- one per stored file, prefixes
each compressed payload. Signature 0x04034b50.
2. End of Central Directory record (EOCD) -- at the tail of
the archive; points to the central directory. Signature
0x06054b50.
This module does NOT parse the central directory entries (CDFH)
or decompress payloads. With just LFH + EOCD the Nishi stack
can: detect zip framing, count members, read filenames,
identify compression method (0=stored, 8=DEFLATE, 14=LZMA,
93=Zstd...), and find the offset of each file's raw bytes.
All multi-byte values in ZIP are little-endian.
Invariants:
Z1 LFH signature must be 0x04034b50.
Z2 EOCD signature must be 0x06054b50 (may be preceded by a
variable-length ZIP comment; caller scans backward).
Z3 Filenames are stored raw; if bit 11 of general-purpose
flag is set, they are UTF-8; otherwise CP437. We expose
offset+length and let caller decide.
Z4 Compressed-size / uncompressed-size may be 0xFFFFFFFF to
indicate Zip64 extensions; we surface that as a sentinel
for now.
dependencies 1 imports · 0 importers
imports: syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 39 | struct ZipLocalHeader { |
| 54 | struct ZipEndOfCentralDir { |
consts
| 31 | const ZIP_LFH_SIG: i64 = 0x04034b50 |
| 32 | const ZIP_EOCD_SIG: i64 = 0x06054b50 |
| 34 | const ZIP_ERR_FORMAT: i64 = -1 |
| 35 | const ZIP_ERR_SHORT: i64 = -2 |
| 37 | const ZIP64_MARKER: i64 = 0xFFFFFFFF |
functions
| 66 | func zip_read_u16(buf: *u8, off: i64) -> i64 { |
| 70 | func zip_read_u32(buf: *u8, off: i64) -> i64 { |
| 80 | func zip_parse_lfh(buf: *u8, n: i64, off: i64, h: *ZipLocalHeader) -> i64 { |
| 108 | func zip_find_eocd(buf: *u8, n: i64) -> i64 { |
| 123 | func zip_parse_eocd(buf: *u8, n: i64, off: i64, |
| 144 | func zip_method_known(method: i64) -> i64 {
called by 1: main |
| 155 | func main() -> i64 { |