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

Open
github-bot wants to merge 1 commit from github-bot/gh-2006 into main AGit
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-25 17:57 UTC · original
abnalstlll-byte:feat/import-call-sites-direct-ff15 → main · +84 −6 · 3 files · 1 commits · open

Claimed in the coordination issue as: IMPORT-CALL-SITES-DIRECT-FF15-CALLS (#1608)

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)

**@⁠abnalstlll-byte** on GitHub · 2026-11-25 17:57 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2006) `abnalstlll-byte:feat/import-call-sites-direct-ff15` → `main` · +84 −6 · 3 files · 1 commits · open Claimed in the coordination issue as: IMPORT-CALL-SITES-DIRECT-FF15-CALLS (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### 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)
Support direct import calls through call qword [rip+disp32] (\xff\x15)
in tools/import_call_sites.py alongside thunks (jmp qword [rip+disp32] / \xff\x25).
This enables discovering call sites in images where imports are called
directly without an intermediate jmp thunk (e.g. XboxBvhBuilder.dll calls).
Harden tools/import_fail_fast.py to identify instruction boundary sizes
(5 bytes for E8 vs 6 bytes for FF 15) when classifying call sites.
Add unit tests in tests/test_import_call_sites.py for direct slot call
detection, combined thunk/direct calls, non-slot skips, and CLI reports.

AI-assisted (Claude Code)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:14:32 +00:00
Author
Owner

@⁠MSedgeMC on GitHub · 2026-11-25 18:57 UTC · original · approved these changes

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.

**@⁠MSedgeMC** on GitHub · 2026-11-25 18:57 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2006#pullrequestreview-6063280688) · **approved these changes** 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.
Author
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-25 21:27 UTC · original

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)

**@⁠abnalstlll-byte** on GitHub · 2026-11-25 21:27 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2006#issuecomment-7175111014) 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)
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2006/head:github-bot/gh-2006'
git switch 'github-bot/gh-2006'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2006'
git switch 'github-bot/gh-2006'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2006'
git switch 'github-bot/gh-2006'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2006'
git switch 'main'
git merge --squash 'github-bot/gh-2006'
git switch 'main'
git merge --ff-only 'github-bot/gh-2006'
git switch 'main'
git merge 'github-bot/gh-2006'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.