OLD-7998: restore old upstream PR 7998 - d3d12_device_calls: count the ID3D12Device slots the retail executable calls, from the file alone #697

Merged
aslan2142 merged 5 commits from upstream-pr/697 into main 2026-11-25 22:22:35 +00:00
aslan2142 commented 2026-11-24 12:17:25 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-24T12:17:25Z.


Claimed in the coordination issue as: OLD-7998 https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7131077757

Restoration of my original pull request, old upstream PR 7998 in ItsNotRexed/Leonida, which was closed unmerged when that repository went private on 2026-11-23 (old numbers link nowhere now). Rebased onto main at 21625bca8c; the docs/README.md conflict is resolved by keeping main's index and extending its retail_boot_chain.md row with this tool, and the old pull request numbers in the docs, test comments and commit messages are now plain text. The code is unchanged.

What and why

  • New tools/d3d12_device_calls.py (standard library, python -I). It counts which ID3D12Device vtable slots the executable calls and how often. It reads only the file; nothing is run.
  • It follows the out-pointer of D3D12XboxCreateDevice / D3D12CreateDevice to the globals and stack slots that hold the device. Then it counts the call [vtable+disp], call reg and verified-dispatch (method in rax) sites for each slot.
  • For each slot it also records:
    • the call and tail-jump counts;
    • which register holds the device (rcx, or rdx for the console's return-buffer form);
    • an estimated argument count.
  • It walks forward branches inside a function. A jmp inside the walked range is a branch, not a tail call.
  • It counts what it cannot follow and never guesses a slot for it:
    • vtable loads with no matching call;
    • calls to targets that are not verified dispatch routines;
    • the device passed to another function or stored to non-stack memory;
    • creator out-pointers it cannot follow.
  • The text report holds only slot numbers and counts. The JSON also holds each site's RVA for local follow-up. --out is required.
  • docs/retail_boot_chain.md §5 describes the method, its limits and the census.
  • Census on the 1.0.2.1 executable:
    • 1 creator call site;
    • 95 sites across 42 slots: 94 calls and 1 tail jump;
    • 12 sites not resolved.
  • A slot with no row is not shown to be uncalled.

Tested

  • Linux, Python 3.14.10, CPU only. The tests use synthetic, hand-built PE fixtures; no game files are needed.
  • python -I tests/test_d3d12_device_calls.py:
    • on main: fails at import (ModuleNotFoundError, the tool is missing);
    • on this branch: 15 of 15 pass.
  • python -m compileall -q tools tests: clean.
  • tests/test_docs_*.py and tests/test_text_write_line_endings.py: 56 tests in 13 files pass, the same as on main.
  • git diff --check: clean.
  • python -I scripts/check_no_game_data.py on the four changed files: clean.

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5471982457 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/697). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-24T12:17:25Z. --- Claimed in the coordination issue as: OLD-7998 https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7131077757 Restoration of my original pull request, old upstream PR 7998 in `ItsNotRexed/Leonida`, which was closed unmerged when that repository went private on 2026-11-23 (old numbers link nowhere now). Rebased onto main at 21625bca8c675c62f9dbffc318ce6a59d57faf31; the `docs/README.md` conflict is resolved by keeping main's index and extending its `retail_boot_chain.md` row with this tool, and the old pull request numbers in the docs, test comments and commit messages are now plain text. The code is unchanged. ### What and why - New `tools/d3d12_device_calls.py` (standard library, `python -I`). It counts which `ID3D12Device` vtable slots the executable calls and how often. It reads only the file; nothing is run. - It follows the out-pointer of `D3D12XboxCreateDevice` / `D3D12CreateDevice` to the globals and stack slots that hold the device. Then it counts the `call [vtable+disp]`, `call reg` and verified-dispatch (`method in rax`) sites for each slot. - For each slot it also records: - the call and tail-jump counts; - which register holds the device (`rcx`, or `rdx` for the console's return-buffer form); - an estimated argument count. - It walks forward branches inside a function. A `jmp` inside the walked range is a branch, not a tail call. - It counts what it cannot follow and never guesses a slot for it: - vtable loads with no matching call; - calls to targets that are not verified dispatch routines; - the device passed to another function or stored to non-stack memory; - creator out-pointers it cannot follow. - The text report holds only slot numbers and counts. The JSON also holds each site's RVA for local follow-up. `--out` is required. - `docs/retail_boot_chain.md` §5 describes the method, its limits and the census. - Census on the 1.0.2.1 executable: - 1 creator call site; - 95 sites across 42 slots: 94 calls and 1 tail jump; - 12 sites not resolved. - A slot with no row is not shown to be uncalled. ### Tested - Linux, Python 3.14.10, CPU only. The tests use synthetic, hand-built PE fixtures; no game files are needed. - `python -I tests/test_d3d12_device_calls.py`: - on main: fails at import (`ModuleNotFoundError`, the tool is missing); - on this branch: 15 of 15 pass. - `python -m compileall -q tools tests`: clean. - `tests/test_docs_*.py` and `tests/test_text_write_line_endings.py`: 56 tests in 13 files pass, the same as on main. - `git diff --check`: clean. - `python -I scripts/check_no_game_data.py` on the four changed files: clean. GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. AI-assisted (Claude Code, Claude Opus 5.5).
abnalstlll-byte commented 2026-11-24 12:20:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T12:20:22Z.

Review: APPROVED


Reviewed and verified OLD-7998 restoration. The tool ools/d3d12_device_calls.py correctly conducts static inspection of ID3D12Device vtable dispatch call sites from PE headers and bytecode without loading or executing the binary. All synthetic unit tests in ests/test_d3d12_device_calls.py adhere strictly to standard library requirements and clean-room constraints. Documentation update in docs/retail_boot_chain.md matches measured behavior. LGTM.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6039082922 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/697#pullrequestreview-6039082922). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T12:20:22Z. **Review:** APPROVED --- Reviewed and verified OLD-7998 restoration. The tool ools/d3d12_device_calls.py correctly conducts static inspection of ID3D12Device vtable dispatch call sites from PE headers and bytecode without loading or executing the binary. All synthetic unit tests in ests/test_d3d12_device_calls.py adhere strictly to standard library requirements and clean-room constraints. Documentation update in docs/retail_boot_chain.md matches measured behavior. LGTM.
aslan2142 commented 2026-11-25 22:22:37 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-25T22:22:37Z.


Merged: d3d12_device_calls counts the ID3D12Device slots the retail executable calls, from the file alone.

  • Changed since review: Nothing. It merges cleanly with main, and no review point is open.
  • Tested: tests/test_d3d12_device_calls.py passes on main + this head (Linux, CPython 3.14).
  • Checked on main 83f791ae4 + 0a5c8d56e: the semantic suite passes (492 files, 6,315 tests, 0 files failed); test_d3d12_device_calls pass; the 15 docs and writer tests pass; check_no_game_data.py is clean on the 4 changed files.

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7176284987 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/697#issuecomment-7176284987). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-25T22:22:37Z. --- Merged: `d3d12_device_calls` counts the ID3D12Device slots the retail executable calls, from the file alone. - **Changed since review:** Nothing. It merges cleanly with `main`, and no review point is open. - **Tested:** `tests/test_d3d12_device_calls.py` passes on `main` + this head (Linux, CPython 3.14). - **Checked on `main` `83f791ae4` + `0a5c8d56e`:** the semantic suite passes (492 files, 6,315 tests, 0 files failed); `test_d3d12_device_calls` pass; the 15 docs and writer tests pass; `check_no_game_data.py` is clean on the 4 changed files. AI-assisted (Claude Code, Claude Opus 5.5).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!697
No description provided.