Skip to content

Count call sites for delay-loaded imports - #7915

Open
EdenBendheim wants to merge 1 commit into
ItsNotRexed:mainfrom
EdenBendheim:fix/import-call-sites-delay-imports
Open

EdenBendheim wants to merge 1 commit into
ItsNotRexed:mainfrom
EdenBendheim:fix/import-call-sites-delay-imports

Conversation

@EdenBendheim

Copy link
Copy Markdown

Claim: #7804 (comment)

What changed

  • tools/pe_inspect.py: Share the bounded descriptor parser (import_descriptors) with tools/import_call_sites.py, adding optional va_entries support in thunk_names() for legacy VA delay-import lookup entries while keeping pe_inspect's own output unchanged.
  • tools/import_call_sites.py: Enumerate PE32+ delay-loaded import IAT slots (named and ordinal, RVA and legacy VA descriptors) alongside ordinary imports so calls and tail jumps targeting delay-import thunks are counted. Requires positive, mapped szName, pIAT, and pINT RVAs (rejecting missing/underflowed pINT rather than falling back to resolver addresses, and rejecting a legacy DLL-name VA normalizing to RVA 0). Ordinary imports take precedence on slot collision, and distinct slots with the same DLL!NAME merge into one entry.
  • tests/test_import_call_sites.py: Synthetic PE32+ tests covering RVA and legacy VA descriptors (including VA-encoded named lookup entries), named and ordinal delay imports, coexistence and slot collisions with ordinary imports, missing/underflowed pINT, RVA-0 DLL-name rejection, and malformed/truncated tables. Assertions check owned fields (thunks, call, jmp) so they stay compatible with import_call_sites: detect direct IAT call [rip+disp32] (FF 15) sites #7116.

Testing & Disclosure

  • AI-assisted: Implemented with Codex (gpt-6.2-sol) and reviewed with Codex (gpt-6.2-astra).
  • Environment: macOS 27.3, Apple M1 Max (CPU-only, synthetic fixtures, zero game data).
  • Commands run:
    • python3 -I tests/test_import_call_sites.py < /dev/null — 18/18 passed
    • python3 -I tests/test_pe_inspect.py < /dev/null — 59 passed, 1 Windows-only skip
    • python3 -m compileall -q make_game.py tools tests < /dev/null — passed
    • python3 -I scripts/check_no_game_data.py tools/import_call_sites.py tools/pe_inspect.py tests/test_import_call_sites.py < /dev/null — passed

@Batushn

Batushn commented Nov 23, 2026

Copy link
Copy Markdown

Tested 34016784 on Windows 11, Python 3.12.10 (CPU only, synthetic PEs, no game data): pass.

  • python -I tests/test_import_call_sites.py -v: 18 passed
  • python -I tests/test_pe_inspect.py -v: 59 passed, 1 skipped (60 run)
  • python -m compileall -q tools/pe_inspect.py tools/import_call_sites.py tests/test_import_call_sites.py: exit 0

One minor review note: pe_inspect._imports() unpacks _va_entries from img.import_descriptors(index, delay=delay) and leaves it unused (img.thunk_names(lookup)), whereas import_call_sites passes va_entries=va_entries for legacy VA delay descriptors. Keeping _imports() unchanged is fine if intentional, or passing va_entries=_va_entries would let pe_inspect decode legacy VA delay-import names the same way.

AI-assisted.

@RAINighty

Copy link
Copy Markdown

Tested 34016784c merged with main dde82f27e (clean merge) on Windows 11 (10.0.26300), Python 3.13.15 (venv with the pinned tests/requirements.txt), with llvm-mc 21.1.8 (AMDGPU) and SPIRV-Tools v2026.4 on PATH: pass.

  • tests/test_import_call_sites.py with this PR: passes (Ran 18 tests in 0.011s, OK). On main: passes (Ran 8 tests in 0.007s, OK).
  • Negative control: this PR's test with main's version of tools/import_call_sites.py, tools/pe_inspect.py fails (Ran 18 tests in 0.012s, FAILED (failures=5, errors=4)), so the new test does catch the problem.
  • Code not reviewed beyond running it. No GPU or game files.

AI-assisted (Claude Code).

@azterixx

Copy link
Copy Markdown

checked: #7915 | with: python -I -m unittest discover -s tests -p test_import_call_sites.py | on: Debian 13, Intel i7-8700, CPython 3.13.5, head 3401678, CPU only | result: pass (18 tests; main@dde82f27e: Ran 8 tests OK)

@airp1ane

Copy link
Copy Markdown
Contributor

Tested 3401678 on Windows 11, Python 3.15.2, NVIDIA RTX 4060 Ti (driver 621.24; CPU-only checks, no game files, no GPU/llvm-mc/MSVC used): pass.

Ran the test files this PR adds or changes, from a clean checkout of the PR head: test_import_call_sites.py - all exit 0.

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