OLD-7282: restore old upstream PR 7282 - pe_inspect: read the resource directory and the RT_VERSION block without its strings #649

Manually merged
github merged 1 commit from gh-pr/649/head into gh-pr/649/base 2026-11-26 09:13:52 +00:00
Owner

@⁠aslan2142 on GitHub · 2026-11-24 10:57 UTC · original
aslan2142:pe-inspect-rt-version → main · +498 −0 · 3 files · 1 commits · merged 2026-11-25 22:20 UTC

Claimed in the coordination issue as: OLD-7282 #14

Restoration of my original pull request, old upstream PR 7282 in ItsNotRexed/Leonida, which was closed unmerged when that repository went private on 2026-11-23 (old numbers link nowhere now). Rebased onto main at 21625bca8c; no changes beyond the rebase.

Depends on: #45 (draft; not a dependency, but both change tools/pe_inspect.py and conflict there)

What and why

  • tools/pe_inspect.py never read data directory 2, so the report said nothing about the version block, the one part of a PE that names its build.
  • Resources: the types present, with entry and byte counts. Named types are counted, not named.
  • Version: the fixed file info's numbers (file and product version, flags with their names, OS, type, subtype, date), the translations, and for each string table each standard key with its value's length and SHA-256.
  • No values: string values are free UTF-16 text that can name the title, so no value is written. Two builds compare by hash. A key outside the standard names is listed by its hash.
  • Problems: a resource tree or version block that is cut short, loops, points outside the file or has a bad signature is listed in problems (offsets and counts only). The rest of the report is still written.
  • Output: the Markdown report gets a "Resources" section, and stdout gets one line per image that has a version block.
  • docs/design.md describes the new resources field next to the PE report steps.

Tested

Linux, Python 3.14.10, CPU only, synthetic inputs (the tests build the resource tree and the version block by hand; no game files).

  • python -I tests/test_pe_inspect.py:
    • main at the base: 60 tests, OK (1 skipped).
    • main with only this PR's test changes: all 9 new test methods fail.
    • this branch: 69 tests, OK (1 skipped).
  • The tests check that the made-up values reach no output. They also cover a missing directory, a file cut at every length inside the block, malformed blocks and a loop in the tree.
  • python -I tests/test_docs_design_rows.py and python -I tests/test_design_contract_rows.py: OK.
  • python -m compileall -q tools tests, git diff --check and python -I scripts/check_no_game_data.py on the three changed files: clean.

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-24 10:57 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/649) `aslan2142:pe-inspect-rt-version` → `main` · +498 −0 · 3 files · 1 commits · merged 2026-11-25 22:20 UTC Claimed in the coordination issue as: OLD-7282 https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14 Restoration of my original pull request, old upstream PR 7282 in `ItsNotRexed/Leonida`, which was closed unmerged when that repository went private on 2026-11-23 (old numbers link nowhere now). Rebased onto main at 21625bca8c675c62f9dbffc318ce6a59d57faf31; no changes beyond the rebase. Depends on: #45 (draft; not a dependency, but both change `tools/pe_inspect.py` and conflict there) ### What and why - `tools/pe_inspect.py` never read data directory 2, so the report said nothing about the version block, the one part of a PE that names its build. - **Resources:** the types present, with entry and byte counts. Named types are counted, not named. - **Version:** the fixed file info's numbers (file and product version, flags with their names, OS, type, subtype, date), the translations, and for each string table each standard key with its value's length and SHA-256. - **No values:** string values are free UTF-16 text that can name the title, so no value is written. Two builds compare by hash. A key outside the standard names is listed by its hash. - **Problems:** a resource tree or version block that is cut short, loops, points outside the file or has a bad signature is listed in `problems` (offsets and counts only). The rest of the report is still written. - **Output:** the Markdown report gets a "Resources" section, and stdout gets one line per image that has a version block. - `docs/design.md` describes the new `resources` field next to the PE report steps. ### Tested Linux, Python 3.14.10, CPU only, synthetic inputs (the tests build the resource tree and the version block by hand; no game files). - `python -I tests/test_pe_inspect.py`: - main at the base: 60 tests, OK (1 skipped). - main with only this PR's test changes: all 9 new test methods fail. - this branch: 69 tests, OK (1 skipped). - The tests check that the made-up values reach no output. They also cover a missing directory, a file cut at every length inside the block, malformed blocks and a loop in the tree. - `python -I tests/test_docs_design_rows.py` and `python -I tests/test_design_contract_rows.py`: OK. - `python -m compileall -q tools tests`, `git diff --check` and `python -I scripts/check_no_game_data.py` on the three changed files: clean. GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) AI-assisted (Claude Code, Claude Opus 5.5).
Data directory 2 was never read, so the report said nothing about the version block, the one part of a PE that
names its build. The block's values are free UTF-16 text that can name the title, so the report holds no value:

- resources: the types present with entry and byte counts; named types are counted, not named.
- version: the fixed file info's numbers (file and product version, flags with their names, OS, type, subtype,
  date), the translations, and per string table each standard key with its value's length and SHA-256. A key
  outside the standard names is listed by its hash.
- problems: a resource tree or version block that is cut short, loops, points outside the file or has a bad
  signature is listed (offsets and counts only); the rest of the report is still written.

The Markdown report gets a Resources section and stdout one line per image with a version block. The tests build
a resource tree and a version block by hand, check that the made-up values reach no output, and cover a missing
directory, a cut file, malformed blocks and a loop in the tree.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:13:51 +00:00
github manually merged commit b8951357f1 into gh-pr/649/base 2026-11-26 09:13:52 +00:00
Author
Owner

@⁠kirigayakazima on GitHub · 2026-11-24 11:48 UTC · original

Reviewed on Windows 11 x64 (Python 3.14.7, CPU only, synthetic PEs only — no game files) against head commit b8951357f12bf7bdc80e46b8f31d42fb1bdc3c9c.

Verdict: Looks good — clean implementation of PE resource / RT_VERSION metadata extraction with strong redaction/hashing guarantees and bounds/cycle handling.

Checks run locally

  • Clean merge with main (21625bca): git merge-tree --write-tree upstream/main HEAD exited 0; git diff --check upstream/main...HEAD clean.
  • python -I tests/test_pe_inspect.py -v: 69 tests, OK (0 skipped) (note: unlike Linux where test_system_dll_is_classified_system skips, all 69 execute and pass on Windows).
  • Doc tests (python -I): all 13 files passed — test_docs_cli_flags.py (4), test_docs_design_rows.py (5), test_docs_encoding.py (1), test_docs_env_vars.py (4), test_docs_links.py (16), test_docs_list_items.py (3), test_docs_pr_template.py (2), test_docs_python_deps.py (3), test_docs_repeated_lines.py (2), test_docs_repo_paths.py (3), test_docs_table_ids.py (2), test_docs_table_rows.py (2), test_design_contract_rows.py (5).
  • python -I tests/test_ci_registration.py: 15 tests, OK.
  • python -I tests/test_text_write_line_endings.py: 3 tests, OK.
  • python -I scripts/check_no_game_data.py tools/pe_inspect.py tests/test_pe_inspect.py docs/design.md and python -m compileall -q tools tests: exit 0.

Synthetic edge-case probes

  1. No-string-leak coverage: Populated unique sentinels across standard StringFileInfo values, a custom StringFileInfo key, a non-8-hex StringTable key, a non-VS_VERSION_INFO root key, unknown top-level / VarFileInfo child keys, and two distinct named resource types. Running pe_inspect.main leaked zero sentinel strings across JSON, Markdown, and stdout, and aggregated both named resource types into named_types: 2 ((named)).
  2. Boundary & malformed RT_VERSION cases:
    • First RT_VERSION leaf with data_size = 0 followed by a valid RT_VERSION leaf: recorded the 0 bytes problem and continued parsing the second leaf cleanly.
    • VarFileInfo Translation with odd byte counts (6 and 2 bytes): safely ignored trailing incomplete bytes (['040904b0'], []).
    • VS_VERSIONINFO with wValueLength = 0 (omitted VS_FIXEDFILEINFO): fixed: None, no spurious problem, parsed tables/translations and printed "no fixed info" summary.
  3. Minor observation (non-blocking): In _version_info, string values slice data[s["value"]:s["end"]] rather than s["value"]:s["value_end"] and split at the first \0. That sensibly tolerates builders with miscounted wValueLength when a NUL terminator is present, though on a synthetic string without \0 before trailing block padding/slack bytes (e.g., wValueLength = 0 with non-zero slack or wValueLength = 3 without NUL), those trailing bytes inside wLength get included in chars/sha256. Worth keeping as-is if real binaries rely on NUL termination, or clamping by wValueLength only when non-zero if strict header lengths are desired.

AI-assisted: yes

**@⁠kirigayakazima** on GitHub · 2026-11-24 11:48 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/649#issuecomment-7130571887) Reviewed on Windows 11 x64 (`Python 3.14.7`, CPU only, synthetic PEs only — no game files) against head commit `b8951357f12bf7bdc80e46b8f31d42fb1bdc3c9c`. **Verdict: Looks good** — clean implementation of PE resource / `RT_VERSION` metadata extraction with strong redaction/hashing guarantees and bounds/cycle handling. ### Checks run locally - Clean merge with `main` (`21625bca`): `git merge-tree --write-tree upstream/main HEAD` exited `0`; `git diff --check upstream/main...HEAD` clean. - `python -I tests/test_pe_inspect.py -v`: **69 tests, OK (0 skipped)** (note: unlike Linux where `test_system_dll_is_classified_system` skips, all 69 execute and pass on Windows). - Doc tests (`python -I`): all 13 files passed — `test_docs_cli_flags.py` (4), `test_docs_design_rows.py` (5), `test_docs_encoding.py` (1), `test_docs_env_vars.py` (4), `test_docs_links.py` (16), `test_docs_list_items.py` (3), `test_docs_pr_template.py` (2), `test_docs_python_deps.py` (3), `test_docs_repeated_lines.py` (2), `test_docs_repo_paths.py` (3), `test_docs_table_ids.py` (2), `test_docs_table_rows.py` (2), `test_design_contract_rows.py` (5). - `python -I tests/test_ci_registration.py`: **15 tests, OK**. - `python -I tests/test_text_write_line_endings.py`: **3 tests, OK**. - `python -I scripts/check_no_game_data.py tools/pe_inspect.py tests/test_pe_inspect.py docs/design.md` and `python -m compileall -q tools tests`: exit `0`. ### Synthetic edge-case probes 1. **No-string-leak coverage**: Populated unique sentinels across standard `StringFileInfo` values, a custom `StringFileInfo` key, a non-8-hex `StringTable` key, a non-`VS_VERSION_INFO` root key, unknown top-level / `VarFileInfo` child keys, and two distinct named resource types. Running `pe_inspect.main` leaked zero sentinel strings across JSON, Markdown, and stdout, and aggregated both named resource types into `named_types: 2` (`(named)`). 2. **Boundary & malformed `RT_VERSION` cases**: - First `RT_VERSION` leaf with `data_size = 0` followed by a valid `RT_VERSION` leaf: recorded the `0 bytes` problem and continued parsing the second leaf cleanly. - `VarFileInfo` `Translation` with odd byte counts (`6` and `2` bytes): safely ignored trailing incomplete bytes (`['040904b0']`, `[]`). - `VS_VERSIONINFO` with `wValueLength = 0` (omitted `VS_FIXEDFILEINFO`): `fixed: None`, no spurious problem, parsed tables/translations and printed `"no fixed info"` summary. 3. **Minor observation (non-blocking)**: In `_version_info`, string values slice `data[s["value"]:s["end"]]` rather than `s["value"]:s["value_end"]` and split at the first `\0`. That sensibly tolerates builders with miscounted `wValueLength` when a NUL terminator is present, though on a synthetic string without `\0` before trailing block padding/slack bytes (e.g., `wValueLength = 0` with non-zero slack or `wValueLength = 3` without NUL), those trailing bytes inside `wLength` get included in `chars`/`sha256`. Worth keeping as-is if real binaries rely on NUL termination, or clamping by `wValueLength` only when non-zero if strict header lengths are desired. AI-assisted: yes
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-24 19:30 UTC · original

Thanks for the review and the probes.

  • On the _version_info slice: reading a string to s["end"] and stopping at the first NUL is on purpose. A String block's wValueLength isn't reliable across resource compilers (some count characters with the NUL, some count bytes, some write 0), so clamping to value_end would cut real values short or read past them depending on the builder.
  • A string with no NUL before the block's slack is malformed (version strings are NUL-terminated), so the only effect is a different chars / sha256 for that malformed value. No text is written either way. I'd keep it as is unless a real file shows otherwise.
  • The red stdlib-tests-linux / macos-python checks are test_tool_stdout_encoding on tools/exe_sha.py and tools/pr_conflict_label.py, which this PR doesn't touch. main has those guards now (#605).

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-24 19:30 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/649#issuecomment-7142206369) Thanks for the review and the probes. - On the `_version_info` slice: reading a string to `s["end"]` and stopping at the first NUL is on purpose. A `String` block's `wValueLength` isn't reliable across resource compilers (some count characters with the NUL, some count bytes, some write 0), so clamping to `value_end` would cut real values short or read past them depending on the builder. - A string with no NUL before the block's slack is malformed (version strings are NUL-terminated), so the only effect is a different `chars` / `sha256` for that malformed value. No text is written either way. I'd keep it as is unless a real file shows otherwise. - The red `stdlib-tests-linux` / `macos-python` checks are `test_tool_stdout_encoding` on `tools/exe_sha.py` and `tools/pr_conflict_label.py`, which this PR doesn't touch. `main` has those guards now (#605). AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 22:20 UTC · original

Merged: pe_inspect reads the resource directory and the RT_VERSION block without its strings.

  • Changed since review: Nothing; it merges cleanly with main and with #653. On the _version_info slice from review: reading to the block end and stopping at the first NUL is on purpose, because wValueLength differs between resource compilers. A string with no NUL is malformed, and no text is written either way.
  • Tested: tests/test_pe_inspect.py passes on main + #653 + this head (Linux, CPython 3.14).
  • Checked on main b4ae8916e + b8951357f: the semantic suite passes (492 files, 6,315 tests, 0 files failed); test_pe_inspect pass; the 15 docs and writer tests pass; check_no_game_data.py is clean on the 3 changed files.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-25 22:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/649#issuecomment-7176249290) Merged: `pe_inspect` reads the resource directory and the RT_VERSION block without its strings. - **Changed since review:** Nothing; it merges cleanly with `main` and with #653. On the `_version_info` slice from review: reading to the block end and stopping at the first NUL is on purpose, because `wValueLength` differs between resource compilers. A string with no NUL is malformed, and no text is written either way. - **Tested:** `tests/test_pe_inspect.py` passes on `main` + #653 + this head (Linux, CPython 3.14). - **Checked on `main` `b4ae8916e` + `b8951357f`:** the semantic suite passes (492 files, 6,315 tests, 0 files failed); `test_pe_inspect` pass; the 15 docs and writer tests pass; `check_no_game_data.py` is clean on the 3 changed files. AI-assisted (Claude Code, Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.