Skip to content

d3d12_guid_sites: use PE32 thunk width for separate IAT slots - #7676

Open
space-de wants to merge 1 commit into
ItsNotRexed:mainfrom
space-de:fix/guid-sites-pe32-iat-width
Open

space-de wants to merge 1 commit into
ItsNotRexed:mainfrom
space-de:fix/guid-sites-pe32-iat-width

Conversation

@space-de

Copy link
Copy Markdown

Claimed in the coordination issue as: GUID-SITES-PE32-IAT-WIDTH (claim).

What and why

Image.iat_slots() already reads PE32 imports with four-byte entries, but copying entries from a separate import lookup table to the IAT used an eight-byte stride for both addresses. A synthetic PE32 image with named/ordinal/named imports therefore raises KeyError: 8272; running the real scanner exits 1 with a traceback instead of producing its import report.

Use the existing width for both addresses. This is one production-line change plus regression tests; it fixes the existing import parser without adding x86 instruction decoding. Microsoft specifies four-byte entries for PE32 and eight-byte entries for PE32+, with matching IAT structure (PE specification).

Checked the current #7599 body/comments, preceding #7496, and all-state PR searches for d3d12_guid_sites, iat_slots, and PE32. No matching claim or fix found. Builds on no other PR.

Tested

Windows 11, CPython 3.14.10. CPU only; no GPU/driver, SDK, or game files needed. Base: f875cda2d785d0c9f50aeec4d09d12c2587edf7d.

  • Before the fix, both new tests fail: the PE32 separate-table unit case raises KeyError, and the CLI exits 1. After: python -I tests/test_d3d12_guid_sites.py -v passes all 10 tests. Literal expected slot RVAs cover PE32/PE32+, separate/shared tables, and named/ordinal imports; the CLI checks the resulting JSON import report.
  • tests/test_d3d12_iid_scan.py: 13 passed; tests/test_report_paths.py: 22 passed; tests/test_ci_registration.py: 14 tests OK, one skipped.
  • compileall over make_game.py/tools/tests, make_game.py --help, changed-file no-game-data check, and git diff --check: passed.
  • Full semantic suite: 447 files / 5,956 tests, two failing files (test_image_atomics_guard, test_image_store_d16). Both failures reproduce on an untouched archive of the base. The newline check also reproduces its existing failure on the base (leonida_tui.py:753, wave_diff.py:373). These are outside this patch; tests: fix image atomics guard and image_store d16 tests after #4473 and #6805 #7608 and tools, workflows: reconfigure stdout error handling and pin text write newlines #7589 address them separately.
  • Independent local review confirmed the fixture layout and reproduced the base crash; no issues found.

AI-assisted: yes.

Checklist

  • No game data, keys or decryption, including in logs/reports quoted here. Fixtures are generated synthetic PE bytes.
  • No new translator rule; design contract update is not applicable.

@slint6614-dev

Copy link
Copy Markdown
Contributor

Checked on Linux: merged onto main 77fa308 (merges cleanly).

  • python3 -B tests/test_d3d12_guid_sites.py → OK
  • Negative control: with tools/d3d12_guid_sites.py reverted to main and the new test kept, 3 tests fail, so the test catches the bug.

Read the diff as well; it looks right to me.

@LAKSHYA-cmd-tech LAKSHYA-cmd-tech left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent Windows CPU verification at 8aeaa5717b3708969d0b2571551299220ab032e7.

Environment & Test Suite

  • Platform: Native Windows 11 x64, Python 3.12 / 3.13, CPU-only.
  • Clean-room: Pure synthetic test fixtures only, zero game data (scripts/check_no_game_data.py passes with exit 0).

Verification

  • python -I tests/test_d3d12_guid_sites.py ran 10 tests, OK (0.35s).
  • Verified test_pe32_separate_lookup_table_handles_four_byte_thunks:
    • Image.iat_slots() in tools/d3d12_guid_sites.py now uses the 4-byte entry width for PE32 when transferring from a separate Import Lookup Table (ILT) to the IAT instead of hardcoding 8-byte strides.
    • Resolves KeyError: 8272 on PE32 images with non-contiguous/separate ILT/IAT tables.
  • Merges cleanly into current upstream/main (bf85ff703) with zero conflicts.
  • python -I -m compileall tools/d3d12_guid_sites.py tests/test_d3d12_guid_sites.py: clean, exit 0.
  • git diff --check: clean (0).

LGTM. Approved.

@garuspl

garuspl commented Nov 23, 2026

Copy link
Copy Markdown

Tested 8aeaa57 on Windows 11 (CPU only, no GPU needed): pass

Windows 11 Pro, Python 3.14.7, no GPU or game files involved; pytest/numpy/Pillow pinned from tests/requirements.txt in a fresh venv. Method: PR head merged onto main bf85ff7, the PR's test files run with python -m pytest before and after the merge, plus python -m compileall -q on the changed files (clean).

  • tests/test_d3d12_guid_sites.py: main 8 passed; with the PR 10 passed (6 subtests).

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

@AsgerCode

Copy link
Copy Markdown

Tested 8aeaa57 on Windows 11 (NTFS), Python 3.12.10 (CPU only, no GPU, no game files): pass

What I ran:

  • python -I tests/test_d3d12_guid_sites.py -v: 10 tests, OK.
  • python -I tests/test_missing_input_exit_codes.py (the other test file that runs this tool): 2 tests, OK.
  • Negative control (merge base's tools/d3d12_guid_sites.py, PR tests kept): 2 tests fail. test_import_slots_use_the_images_entry_width (subtest bits=32, shared=False) gives KeyError: 8272, and test_cli_reports_pe32_imports_without_a_traceback gets exit 1. The new tests catch the bug.
  • Merge with current main (dde82f2): clean. main has not changed either file since the merge base.

Own hand-built images, written with a separate builder (not the test file's pe_import_tables). There are three import descriptors: a.dll with a separate lookup table and IAT (named, ordinal #7, named), b.dll separate (2 named), and c.dll with an IAT only (OriginalFirstThunk = 0). The expected slot RVAs were computed apart from the tool:

Image This PR Merge base
PE32 (4-byte entries) iat_slots() matches all 12 slots; CLI exit 0, all three DLLs in imports_of_note KeyError: 8304, CLI exit 1
PE32+ (8-byte entries), plus mov rax, [rip+disp] aimed at a.dll's third IAT slot matches all 12 slots; CLI exit 0; iat_guid_loads names IID_A3 same as this PR

So the PE32+ result does not change, and PE32 now uses the 4-byte stride for both the lookup and IAT addresses. No other line in iat_slots() or imports() assumes 8 bytes: both already take width/flag from pe32plus.

Overlap: no other open PR changes iat_slots(). Six open PRs change tools/d3d12_guid_sites.py. #6512 ("a section's zero-filled tail is not the next section's bytes") merges cleanly with main, but has a text conflict with this PR in tests/test_d3d12_guid_sites.py only. Both add tests in the same place, so whichever merges second needs a small rebase. #7012 and #5737 already conflict with main without this PR.

AI-assisted (Claude Code).

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.

5 participants