rpf: review nits; the ImHex pattern names +12 trailer_size

movies.md says the bink_index counts for movies.rpf are derived, not a rerun, and names the 8 undecided
archives; rpf.md's small-block entropy wording; bink_index drops a redundant max().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alex Collini
2026-11-23 00:02:12 +01:00
parent 03a3558ef4
commit 93cb49a099
5 changed files with 12 additions and 12 deletions

View File

@ -112,8 +112,8 @@ and then only to a temporary file that is deleted.
On this archive both tools find the same 515 streams, the same 8,831,336,892 bytes, 1,094,744 bytes of zero
padding and 22,812 bytes after the last stream. Those 22,812 are 3,884 zero bytes and the 18,928-byte RPF trailer
(counted by reading the tail directly); `bink_index.py` now reports them as zero padding and `rpf_trailer`, so its
`unread_bytes` for this archive is 0 and its zero padding 1,098,628. Running `bink_index.py` on the 515 carved
(counted by reading the tail directly); `bink_index.py` now counts them as zero padding and `rpf_trailer`, which for
this archive gives `unread_bytes` 0 and zero padding 1,098,628 (derived from the measured tail, not a rerun). Running `bink_index.py` on the 515 carved
`.bk2` files finds 515 streams with zero unread bytes, which confirms the stored sizes cover each file exactly.
## 4. Decoding
@ -216,8 +216,8 @@ The raw buffer and PNG stay in temp. FFmpeg is only the raw-to-PNG step here; it
Xbox semantics, not necessarily `malloc`.
- **What the RPF trailer holds.** The 22,812 bytes after the last stream are no longer unexplained (ASSET-318):
3,884 zeros pad to a 4 KiB boundary, and the remaining 18,928 bytes, to EOF, are exactly the header's `u32 +12`,
the RPF9 trailer ([rpf.md](rpf.md#the-trailer-at-eof); confirmed in 14 of the package's 22 archives, none
against). Its contents are high-entropy (7.99 bits per byte) with no zlib or `KB2` header, like the TOC; this
the RPF9 trailer ([rpf.md](rpf.md#the-trailer-at-eof); confirmed in 14 of the package's 22 archives, 8
undecided, none against). Its contents are high-entropy (7.99 bits per byte) with no zlib or `KB2` header, like the TOC; this
project does not decode them.
- **Whether all 515 streams are playable by the game.** Nine were decoded as a sample; the other 506 were only
header-validated. A full decode pass would need the same DLL experiment for every stream and is not part of the

View File

@ -131,16 +131,16 @@ and `core_bvh4.rpf`, and its role is not established.
No archive contradicts the rule, but 8 don't test it. In the 14, the trailer starts with no zlib or Bink 2 header and is
high-entropy like the TOC after the header: 7.95 to 8.00 bits per byte in the nine of 3 KiB or more, and 6.6 to 7.9
in the five smaller ones (a 144-byte block can't reach much more than 6.7 even when random); what they hold is not
in the five smaller ones (random 144-byte blocks average about 6.7); what they hold is not
decoded here. `tools/bink_index.py` counts it as `rpf_trailer` instead of unread bytes; in `movies.rpf` it is the
18,928 bytes after 3,884 zeros that [movies.md](movies.md) listed as unread.
### Viewing a header in ImHex
[tools/imhex/rpf9.hexpat](../tools/imhex/rpf9.hexpat) is a pattern for the [ImHex](https://imhex.werwolv.net/) hex
editor. It names the magic and the data offset at `+4`, shows the u32s at `+8` and `+12` unnamed, and shows the range
from `+0x10` to the data offset (the rest of the header and the TOC) as one opaque byte array. It decodes nothing in
that range. `python -I tests/test_imhex_patterns.py` runs it on a synthetic header when ImHex is installed.
editor. It names the magic, the data offset at `+4` and the trailer size at `+12`, shows the u32 at `+8` unnamed,
and shows the range from `+0x10` to the data offset (the rest of the header and the TOC) as one opaque byte array.
It decodes nothing in that range. `python -I tests/test_imhex_patterns.py` runs it on a synthetic header when ImHex is installed.
## Limits

View File

@ -195,7 +195,7 @@ class PatternsInImHex(unittest.TestCase):
self.assertIsNotNone(got, log)
self.assertEqual(got["header"]["magic"], "9FPR")
self.assertEqual(got["header"]["data_offset"], 0x100)
self.assertEqual((got["header"]["u32_08"], got["header"]["u32_0c"]), (0x11, 0x22))
self.assertEqual((got["header"]["u32_08"], got["header"]["trailer_size"]), (0x11, 0x22))
self.assertEqual(len(got["header_rest_and_toc"]), 0x100 - 0x10)
def test_psin_matches_psin_index_and_psin_data(self):

View File

@ -169,7 +169,7 @@ def scan_file(path, source):
rows.append(row)
last = match.start() + row["size"]
pos = last
trailer = trailer_size if 0 < trailer_size <= len(data) - max(last, start) else 0
trailer = trailer_size if 0 < trailer_size <= len(data) - last else 0
z, u = _gap(data, last, len(data) - trailer)
zero += z
unread += u

View File

@ -4,7 +4,7 @@
// 0x00 "9FPR" RPF9 stored little-endian
// 0x04 data offset u32, where the data area (zlib streams laid end to end) starts
// 0x08 u32 present in every header; meaning not established
// 0x0C u32 present in every header; meaning not established
// 0x0C trailer size u32, the size of the block that ends the file (docs/rpf.md, The trailer at EOF)
// Everything from 0x10 to the data offset is the rest of the header and the table of contents. The TOC is
// encrypted/packed: this pattern shows that range as opaque bytes and decodes nothing in it (no keys, no decryption).
//
@ -22,7 +22,7 @@ struct Rpf9Header {
char magic[4] [[comment("\"9FPR\": RPF9 stored little-endian")]];
u32 data_offset [[comment("start of the data area (docs/rpf.md)")]];
u32 u32_08 [[comment("meaning not established")]];
u32 u32_0c [[comment("meaning not established")]];
u32 trailer_size [[comment("size of the block at EOF (docs/rpf.md)")]];
};
Rpf9Header header @ 0x00;