Extractor | Pk2
# Decompress if needed (zlib) if flags & 1: data = zlib.decompress(data)
In this post, I’ll walk through the PK2 format, write a lightweight Python extractor from scratch, and show you how to unpack those archives in seconds. After reversing a few sample PK2 files (and thanks to open-source community notes), the format breaks down like this: pk2 extractor
for _ in range(num_files): # Read index entry (adjust offsets/sizes based on your game) name_offset, file_offset, uncompressed_size, compressed_size, flags = struct.unpack( "<IIIII", f.read(20) ) # Decompress if needed (zlib) if flags & 1: data = zlib
| Offset | Size (bytes) | Description | |--------|--------------|-------------| | 0 | 4 | Magic header ( PK20 or PK2 ) | | 4 | 4 | Version (usually 2) | | 8 | 4 | Number of files | | 12 | 4 | Offset to file index table | | 16 | 4 | Unknown/Reserved | | 20 | ... | File index entries | I’ll walk through the PK2 format
# Jump to index table f.seek(index_offset)
– [Your Name]
