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

Closed
opened 2026-11-26 20:18:53 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/697
Author: @aslan2142
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142

Base: main ← Head: rt566-d3d12-device-calls


📝 Commits (5)

  • d13044b d3d12_device_calls: count the ID3D12Device slots the executable calls, from the file alone (RT-566)
  • 117d6b2 d3d12_device_calls: count a method in rax only through a verified dispatch routine (review of old upstream PR 7998)
  • ff4392e docs/retail_boot_chain.md §5: the census reads the executable only; TreXito's call shapes for unnamed slots
  • c9013c0 d3d12_device_calls: a jmp within the walked function is a branch, not a tail call (review of old upstream PR 7998)
  • 0a5c8d5 d3d12_device_calls: summary counts calls and tail jumps apart; wording; tupacfan04's open points (old upstream PR 7998)

📊 Changes

4 files changed (+1048 additions, -1 deletions)

View changed files

📝 docs/README.md (+1 -1)
📝 docs/retail_boot_chain.md (+50 -0)
➕ tests/test_d3d12_device_calls.py (+409 -0)
➕ tools/d3d12_device_calls.py (+588 -0)

📄 Description

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).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/697 **Author:** [@aslan2142](https://github.com/aslan2142) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `rt566-d3d12-device-calls` --- ### 📝 Commits (5) - [`d13044b`](https://github.com/ubiquitarianism/leonida/commit/d13044b778034b7ac7066211865f2c06ba8e6048) d3d12_device_calls: count the ID3D12Device slots the executable calls, from the file alone (RT-566) - [`117d6b2`](https://github.com/ubiquitarianism/leonida/commit/117d6b2c5ac4626ab34fc2703f6dc124a5133cfc) d3d12_device_calls: count a method in rax only through a verified dispatch routine (review of old upstream PR 7998) - [`ff4392e`](https://github.com/ubiquitarianism/leonida/commit/ff4392ef70724a3809a7607cd7538fc0c9567891) docs/retail_boot_chain.md §5: the census reads the executable only; TreXito's call shapes for unnamed slots - [`c9013c0`](https://github.com/ubiquitarianism/leonida/commit/c9013c0af1aa8a43f703f2f7dbd5f0ad40605f6a) d3d12_device_calls: a jmp within the walked function is a branch, not a tail call (review of old upstream PR 7998) - [`0a5c8d5`](https://github.com/ubiquitarianism/leonida/commit/0a5c8d56ebd9270355168205f4dba76832d5d397) d3d12_device_calls: summary counts calls and tail jumps apart; wording; tupacfan04's open points (old upstream PR 7998) ### 📊 Changes **4 files changed** (+1048 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `docs/README.md` (+1 -1) 📝 `docs/retail_boot_chain.md` (+50 -0) ➕ `tests/test_d3d12_device_calls.py` (+409 -0) ➕ `tools/d3d12_device_calls.py` (+588 -0) </details> ### 📄 Description 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). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:18:53 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#737
No description provided.