tools/import_call_sites: scan direct call qword [rip+disp32] (FF 15) import call sites (IMPORT-CALL-SITES-DIRECT-FF15-CALLS) #2006

Merged
leonida/mandy
abnalstlll-byte merged 1 commit from feat/import-call-sites-direct-ff15 into main 2026-11-28 10:48:05 +00:00

Pull request successfully merged and closed

abnalstlll-byte commented 2026-11-25 17:57:23 +00:00

Claimed in the coordination issue as: IMPORT-CALL-SITES-DIRECT-FF15-CALLS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7170156749)

What and why

  • tools/import_call_sites.py searches for thunks (jmp qword [rip+disp32] / \xff\x25) and relative branches (E8/E9 rel32) to those thunks. However, MSVC and compilers also emit direct call qword [rip+disp32] (\xff\x15) targeting the import's IAT slot directly without an intermediate jmp thunk (as noted in BubsMcgee's finding and docs/xdxr.md §6 for XboxBvhBuilder.dll call sites).
  • Add CALL_INDIRECT = re.compile(b"\xff\x15") and scan executable sections for direct calls targeting import slots, recording them in entry["call"].
  • Update tools/import_fail_fast.py to identify instruction boundary sizes (rva + 6 for 0xFF 0x15 vs rva + 5 for 0xE8) and deduplicate call sites when classifying results.
  • Add unit tests in tests/test_import_call_sites.py covering:
    • direct slot call counted without a thunk
    • combined thunk and direct calls sorted by RVA
    • direct call targeting non-slot ignored
    • direct call truncated near section boundary
    • CLI JSON and table outputs

Tested

  • python -I tests/test_import_call_sites.py -> Ran 26 tests in 0.091s, OK
  • python -I tests/test_import_fail_fast.py -> Ran 10 tests in 0.066s, OK
  • python -I tests/test_int3_cause.py -> Ran 15 tests in 0.022s, OK
  • python -I tests/test_x86_high_byte_writes.py -> Ran 4 tests in 0.001s, OK
  • python -I tests/test_text_write_line_endings.py -> Ran 3 tests in 12.225s, OK
  • python -I scripts/check_no_game_data.py tools/import_call_sites.py tools/import_fail_fast.py tests/test_import_call_sites.py -> exit 0
  • python -m compileall -q make_game.py tools tests -> exit 0
  • git diff --check -> clean

Tested on Windows 11 x64 (Python 3.12, stdlib tests, no game data needed).
AI-assisted (Claude Code)

Claimed in the coordination issue as: IMPORT-CALL-SITES-DIRECT-FF15-CALLS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7170156749) ### What and why - `tools/import_call_sites.py` searches for thunks (`jmp qword [rip+disp32]` / `\xff\x25`) and relative branches (`E8`/`E9 rel32`) to those thunks. However, MSVC and compilers also emit direct `call qword [rip+disp32]` (`\xff\x15`) targeting the import's IAT slot directly without an intermediate jmp thunk (as noted in BubsMcgee's finding and `docs/xdxr.md` §6 for `XboxBvhBuilder.dll` call sites). - Add `CALL_INDIRECT = re.compile(b"\xff\x15")` and scan executable sections for direct calls targeting import slots, recording them in `entry["call"]`. - Update `tools/import_fail_fast.py` to identify instruction boundary sizes (`rva + 6` for `0xFF 0x15` vs `rva + 5` for `0xE8`) and deduplicate call sites when classifying results. - Add unit tests in `tests/test_import_call_sites.py` covering: - direct slot call counted without a thunk - combined thunk and direct calls sorted by RVA - direct call targeting non-slot ignored - direct call truncated near section boundary - CLI JSON and table outputs ### Tested - `python -I tests/test_import_call_sites.py` -> `Ran 26 tests in 0.091s`, `OK` - `python -I tests/test_import_fail_fast.py` -> `Ran 10 tests in 0.066s`, `OK` - `python -I tests/test_int3_cause.py` -> `Ran 15 tests in 0.022s`, `OK` - `python -I tests/test_x86_high_byte_writes.py` -> `Ran 4 tests in 0.001s`, `OK` - `python -I tests/test_text_write_line_endings.py` -> `Ran 3 tests in 12.225s`, `OK` - `python -I scripts/check_no_game_data.py tools/import_call_sites.py tools/import_fail_fast.py tests/test_import_call_sites.py` -> `exit 0` - `python -m compileall -q make_game.py tools tests` -> `exit 0` - `git diff --check` -> `clean` Tested on Windows 11 x64 (Python 3.12, stdlib tests, no game data needed). AI-assisted (Claude Code)
MSedgeMC approved these changes 2026-11-25 18:57:18 +00:00
MSedgeMC left a comment

Verified on the PR branch: python3 -m unittest discover -s tests -p 'test_import_call_sites*.py' -> 26 tests OK, including the 5 new DirectSlotCallsTest cases (direct FF 15 calls to IAT slots counted without a thunk, combined+deduped with thunk calls, non-slot targets ignored, truncated instruction at section end, CLI --json output). The change extends call-site recovery to obfuscated binaries where the import thunk has been removed — a real capability improvement, Python-only. Advisory: branch carries ~29 older commits not on current main; rebase before merge to keep history clean.

Verified on the PR branch: python3 -m unittest discover -s tests -p 'test_import_call_sites*.py' -> 26 tests OK, including the 5 new DirectSlotCallsTest cases (direct FF 15 calls to IAT slots counted without a thunk, combined+deduped with thunk calls, non-slot targets ignored, truncated instruction at section end, CLI --json output). The change extends call-site recovery to obfuscated binaries where the import thunk has been removed — a real capability improvement, Python-only. Advisory: branch carries ~29 older commits not on current main; rebase before merge to keep history clean.
abnalstlll-byte commented 2026-11-25 21:27:52 +00:00

Rebased cleanly onto latest \main\ (\e34ff17e9). Verified: 26/26 tests in \ est_import_call_sites.py\ and 10/10 tests in \ est_import_fail_fast.py\ pass.

AI-assisted (Claude Code)

Rebased cleanly onto latest \main\ (\e34ff17e9\). Verified: 26/26 tests in \ est_import_call_sites.py\ and 10/10 tests in \ est_import_fail_fast.py\ pass. AI-assisted (Claude Code)
sodove commented 2026-11-28 10:11:42 +00:00

#2006 | head 369bf541b14abeff8c67a5e4b631b1996e41910e | python3 -I tests/test_import_call_sites.py -v | red: 26 run, 3 failures | green: 26 passed | Red → green

Direct calls to import slots were absent from the baseline scan results on the synthetic fixtures.

Pinned main 33db04a7010e81c40a7a6a15624525aa0c4a3a58, merged into this PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Full suite: not run. AI-assisted: OpenAI Codex. Batch claim.

#2006 | head `369bf541b14abeff8c67a5e4b631b1996e41910e` | `python3 -I tests/test_import_call_sites.py -v` | red: 26 run, 3 failures | green: 26 passed | **Red → green** Direct calls to import slots were absent from the baseline scan results on the synthetic fixtures. Pinned main `33db04a7010e81c40a7a6a15624525aa0c4a3a58`, merged into this PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Full suite: not run. AI-assisted: OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7237628300).
DadaCap commented 2026-11-28 10:48:08 +00:00

Merged, thank you @abnalstlll-byte!

What it does: tools/import_call_sites: scan direct call qword [rip+disp32] (FF 15) import call sites (IMPORT-CALL-SITES-DIRECT-FF15-CALLS)

How it was checked: sodove tested this PR at head 369bf541b on main 33db04a70: the PR's own test fails on main and passes with this PR merged in (his result is linked from the batch summary in #1608). We then re-ran the same test locally on Windows 11 and got the same verdict: on main, red (3 failures); with the PR, green (26 OK).

CI: the red jobs on this PR fail the same way on main, or on the older main it was built on (the cs_dpp_cmp.asm translator fixture, since fixed on main, and the Windows runner's Visual Studio setup), so none comes from this change.

Merged one by one with 20 other PRs of the same reviewed batch, pinned to the tested head.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

Merged, thank you @abnalstlll-byte! **What it does:** tools/import_call_sites: scan direct call qword [rip+disp32] (FF 15) import call sites (IMPORT-CALL-SITES-DIRECT-FF15-CALLS) **How it was checked:** sodove tested this PR at head `369bf541b` on main `33db04a70`: the PR's own test fails on main and passes with this PR merged in (his result is linked from the batch summary in #1608). We then re-ran the same test locally on Windows 11 and got the same verdict: on main, red (3 failures); with the PR, green (26 OK). **CI:** the red jobs on this PR fail the same way on main, or on the older main it was built on (the `cs_dpp_cmp.asm` translator fixture, since fixed on main, and the Windows runner's Visual Studio setup), so none comes from this change. Merged one by one with 20 other PRs of the same reviewed batch, pinned to the tested head. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.
Sign in to join this conversation.
No description provided.