Skip to content

d3d12_guid_sites: scan the last whole slot of every section (pointer, queue desc, movabs) - #6421

Open
cynbun wants to merge 1 commit into
ItsNotRexed:mainfrom
cynbun:fix-guid-sites-section-end
Open

cynbun wants to merge 1 commit into
ItsNotRexed:mainfrom
cynbun:fix-guid-sites-section-end

Conversation

@cynbun

@cynbun cynbun commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claim: #6214 (comment) (finding + claiming, new item)

Cause

Three scans in tools/d3d12_guid_sites.py stop one step before the end of the section they walk:

  • tools/d3d12_guid_sites.py:248 (absolute_refs): range(0, len(blob) - 8, 8) never reads the 8-byte slot at len - 8. Section raw sizes are multiples of 8, so the last pointer of every data section was skipped.
  • tools/d3d12_guid_sites.py:322 (queue descriptions): range(0, len(blob) - 16, 4) skips the 16-byte window at len - 16.
  • tools/d3d12_guid_sites.py:229 (movabs_pairs): range(len(blob) - 10) skips a 10-byte REX.W B8+r imm64 that ends the code section.

A GUID pointer, a D3D12_COMMAND_QUEUE_DESC or a movabs GUID half in that last slot was dropped with no message. The tool's docstring says it "scans data sections for absolute 8-byte pointers" and reports "data windows referenced by code that parse as a D3D12_COMMAND_QUEUE_DESC". rip_refs in the same file already uses the right bound: range(len(blob) - 6) for a 7-byte instruction, with the comment "must fit entirely".

Fix

Use len(blob) - 7, len(blob) - 15 and len(blob) - 9, so the last whole slot is included. A truncated section still can't read past its bytes.

Tests

tests/test_d3d12_guid_sites.py gets three new cases. Each is built with the file's own pe32plus()/lea() builders and puts the candidate at the very end of its section: a queue description in the last 16 bytes of .rdata, an absolute pointer to a GUID in the last 8 bytes of .rdata, and a movabs pair that ends .text. On origin/main all three fail with an empty result, and they pass with the fix.

Tested on Linux, Python 3.14.8 (no GPU needed):

Synthetic inputs only, no game data.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

absolute_refs, the queue-description windows and movabs_pairs stopped one
step short: range(0, len - 8, 8), range(0, len - 16, 4) and range(len - 10)
never reach the 8-byte slot, 16-byte window or 10-byte instruction that ends
exactly at the section end. A GUID pointer, queue description or movabs GUID
half there was silently dropped. Use len - 7, len - 15 and len - 9, the same
"must fit entirely" bound rip_refs already uses, and test each scan on a
hand-built PE32+ whose candidate ends its section.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jadiac5

Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 928633e on Windows 11, Python 3.12 (CPU only): pass

  • python -I tests/test_d3d12_guid_sites.py: 10 tests OK. Negative control with tools/d3d12_guid_sites.py from the merge base: 3 failures, one per new test (queue desc in the last 16 bytes, absolute pointer in the last 8 bytes, movabs pair ending the section).
  • Read the three changed loop bounds (movabs_pairs, absolute_refs, scan). The rip_refs loop already had len - 6 for a 7-byte instruction, so no loop of the same kind is left in the file.
  • Own inputs on the CLI, path with a space, head vs base: empty file and a 3,000-byte zero file are skipped with "not an MZ image", a 2-byte MZ file is skipped with the struct error, exit 0, all same as base. A missing path and a folder give a traceback (exit 1), same as base.
  • Not done: no real PE images.

AI-assisted (Claude Code).

@memorypressure

Copy link
Copy Markdown

Verified against main 1cc6e3c: merges cleanly; test_d3d12_guid_sites.py runs Ran 10 OK (re-run), and on a clean main worktree exactly the three new last-whole-slot tests fail — a clean differential. The bound fixes are correct at the edges (last valid start = len−N, alignment preserved on the 8-byte stride loop), and the tests assert concrete RVA/type values rather than just non-crash. Checks pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@kapitche

Copy link
Copy Markdown
Contributor

Tested 928633e merged with main 5e54bda on Linux/Python 3.12.16: pass

Merge was clean (tools/d3d12_guid_sites.py, tests/test_d3d12_guid_sites.py).

  • python -I tests/test_d3d12_guid_sites.py: Ran 11 tests, OK.
  • Negative control (tools/d3d12_guid_sites.py restored from upstream/main, tests from the PR): Ran 11 tests, FAILED (failures=3): test_queue_desc_in_the_last_16_bytes_of_a_section, test_absolute_pointer_in_the_last_8_bytes_of_a_section and test_movabs_pair_that_ends_the_code_section. PR version restored afterwards.

Diff read: three loop bounds that skipped the last whole item of a section are corrected: len(blob) - 10 to - 9 (a 10-byte movabs that ends the section), range(0, len - 8, 8) to - 7 (the last 8-byte slot) and range(0, len - 16, 4) to - 15 (the last 16-byte window). Each new bound keeps i + width <= len(blob), and each test puts the item exactly at the end of a synthetic section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants