Validate DXContainers and mapped PE section bounds in call_evidence #130

Merged
alexander-src merged 3 commits from upstream-pr/131 into main 2026-11-21 17:46:10 +00:00
alexander-src commented 2026-11-21 16:47:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by alexander-src on 2026-11-21T16:47:24Z.


Change

Align tools/call_evidence.py's shader_containers() with tools/resource_inventory.py's DXContainer validation rules (commits fadc3cd and e69639d) and require mapped PE section extents before recording a container or size/pointer pair:

  • Reuse resource_inventory.parts() instead of the duplicate ascending-offset loop so valid DXContainers with unordered part-offset tables are indexed (and their RTS0 root header extracted) while containers with overlapping physical parts or duplicate FourCC tags are rejected before they can break tools/probe_roots.py.
  • Replace raw pe.get_rva_from_offset() calls with _mapped_rva(pe, offset, length) backed by pe.get_section_by_offset(), skipping containers or (size, pointer) pairs that fall in unmapped PE overlays, headers, zero-PointerToRawData sections, or cross past section bounds instead of raising TypeError when get_rva_from_offset() returns None (or returning bogus header RVAs on small overlays below the first section's VirtualAddress).
  • Add synthetic PE32+ regression coverage in tests/dxcontainer_part_offsets_check.py exercising unordered directories with an RTS0 header, duplicate FourCC rejection, overlapping part rejection, and unmapped overlays at both < 0x1000 and > 0x1000 file offsets.

Verification

Tested on Linux x86_64 (Python 3.14, pefile) at commit 2a3f6ec (based on fd1ff2a):

  • python3 -B tests/dxcontainer_part_offsets_check.py -v: 5 tests passed (including test_call_evidence_matches_dxcontainer_rules_and_skips_unmapped_bytes for both 0x200 and 0x1200 section sizes).
  • python3 -B tests/script_state_check.py: 3 tests passed.
  • python3 -B tests/bcpack_check.py: 3 tests passed.
  • python3 -B tests/resource_ranges_check.py: 3 tests passed.
  • python3 -B tests/layout_chunks_check.py: passed (layout chunk summary ok).
  • python3 -B tests/intake/paths_check.py: passed.

Evidence and follow-up

All new test inputs are synthetic byte buffers generated in tests/dxcontainer_part_offsets_check.py (original MIT-licensed code, no third-party binaries or game assets).

The Windows C++ build and dumpbin invocation path in call_evidence.inspect() were not run locally on Linux and remain covered by Windows CI.

AI-assisted: yes.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6531636306 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/131). Originally posted by [alexander-src](https://github.com/alexander-src) on 2026-11-21T16:47:24Z. --- ## Change Align `tools/call_evidence.py`'s `shader_containers()` with `tools/resource_inventory.py`'s DXContainer validation rules (commits `fadc3cd` and `e69639d`) and require mapped PE section extents before recording a container or size/pointer pair: - Reuse `resource_inventory.parts()` instead of the duplicate ascending-offset loop so valid DXContainers with unordered part-offset tables are indexed (and their `RTS0` root header extracted) while containers with overlapping physical parts or duplicate FourCC tags are rejected before they can break `tools/probe_roots.py`. - Replace raw `pe.get_rva_from_offset()` calls with `_mapped_rva(pe, offset, length)` backed by `pe.get_section_by_offset()`, skipping containers or `(size, pointer)` pairs that fall in unmapped PE overlays, headers, zero-`PointerToRawData` sections, or cross past section bounds instead of raising `TypeError` when `get_rva_from_offset()` returns `None` (or returning bogus header RVAs on small overlays below the first section's `VirtualAddress`). - Add synthetic PE32+ regression coverage in `tests/dxcontainer_part_offsets_check.py` exercising unordered directories with an `RTS0` header, duplicate FourCC rejection, overlapping part rejection, and unmapped overlays at both `< 0x1000` and `> 0x1000` file offsets. ## Verification Tested on Linux x86_64 (`Python 3.14`, `pefile`) at commit `2a3f6ec` (based on `fd1ff2a`): - `python3 -B tests/dxcontainer_part_offsets_check.py -v`: 5 tests passed (including `test_call_evidence_matches_dxcontainer_rules_and_skips_unmapped_bytes` for both `0x200` and `0x1200` section sizes). - `python3 -B tests/script_state_check.py`: 3 tests passed. - `python3 -B tests/bcpack_check.py`: 3 tests passed. - `python3 -B tests/resource_ranges_check.py`: 3 tests passed. - `python3 -B tests/layout_chunks_check.py`: passed (`layout chunk summary ok`). - `python3 -B tests/intake/paths_check.py`: passed. ## Evidence and follow-up All new test inputs are synthetic byte buffers generated in `tests/dxcontainer_part_offsets_check.py` (original MIT-licensed code, no third-party binaries or game assets). The Windows C++ build and `dumpbin` invocation path in `call_evidence.inspect()` were not run locally on Linux and remain covered by Windows CI. AI-assisted: yes.
upstream-sync closed this pull request 2026-11-24 06:41:27 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!130
No description provided.