From fffde0c8a5c7bf0081b4c5b3afacc56ced302433 Mon Sep 17 00:00:00 2001 From: Koro4e <96347170+Koro4e@users.noreply.github.com> Date: Sun, 22 Nov 2026 19:33:20 +0100 Subject: docs: drop the superseded inline-dispatch observation row The later review pass added the 0x1d047 call with 0x8020 to the same 0x149ba row; keep that one and remove the older short copy. --- docs/d3d12_command_objects.md | 1 - 1 file changed, 1 deletion(-) (limited to 'docs/d3d12_command_objects.md') diff --git a/docs/d3d12_command_objects.md b/docs/d3d12_command_objects.md index 56e1fd5cd..4b3a79804 100644 --- a/docs/d3d12_command_objects.md +++ b/docs/d3d12_command_objects.md @@ -303,7 +303,6 @@ of an inline write of the same values. | `0x1a3b0` | `+0x168` | 45 → 41 `SetComputeRootUnorderedAccessView` | `(0, VA)` (inline: header + a 64-bit value) | **Measured** shape | | `0x20ed6` | `+0x4a0` | 148 → none | `(list, count * 40, 16)` returns a pointer; on null the DLL prints `D3D12 XDXR Error: Failed to allocate upload buffer` and throws `E_FAIL` | **Measured**: an upload allocator `(size, alignment)` | | `0x20f99` | `+0x158` | 43 → 39 `SetComputeRootShaderResourceView` | `(0, p)`, `p` the pointer slot 148 returned at `0x20ed6`, unchanged | **Measured**: the CPU pointer is used as the GPU address | -| `0x149ba` | `+0x280` | 80 → none | `(x, 1, 1, 0x8020)`: `EDX=EDI`, `R8D=R9D=1`, fifth argument `0x8020` (inline: the five-dword packet `0x4003cc00, x, 1, 1, W` of section 3.5a; the calls at `0x1525d` and `0x153b4` pass `0x20`) | Inferred: a `Dispatch` with one extra word | | `0x149ba` | `+0x280` | 80 → none | `(x, 1, 1, 0x8020)`: `EDX=EDI`, `R8D=R9D=1`, fifth argument `0x8020` (inline: the five-dword packet `0x4003cc00, x, 1, 1, W` of section 3.5a; the calls at `0x1525d` and `0x153b4` pass `0x20`, the one at `0x1d047` `0x8020`) | Inferred: a `Dispatch` with one extra word | | `0xd6de` | `+0x238` | 71 → none | `(&label, counter, 0 or 0x1000, 0)`: the counter at `[rbx+0x9c]` is incremented first; `0x1000` on the last item of a batch | Inferred: a GPU write of a 32-bit value to memory | | `0xd679` | `+0x248` | 73 → none | `(&label, 3, reference, 0xffffffff, 0)` | Inferred: a GPU wait until the masked value compares (function 3) with the reference | -- cgit v1.2.3 From 98de7444991993df83c2f3c53eba9432b12a3eae Mon Sep 17 00:00:00 2001 From: AREA52 Agent Date: Sun, 22 Nov 2026 20:04:57 +0100 Subject: d3d12_command_objects: document the geometry-descriptor validation and the batched-build slot map corrections (D3D-293) Extends section 7 with the CPU-side geometry descriptor validation that gates BuildRaytracingAccelerationStructureBatched2X before the first list-vtable call (the step the D3D-293 dynamic logging proxy stopped at), integrates the static iced-x86 cross-check results: undocumented slot 90 (+0x2d0) as the worker's first list call, the +0xd0 barrier being bss-gated (never fired in the shipping DLL), the +0x490 global UAV barrier group, and slot 148 (count * 40) upload allocation. Fixes D3D-293. --- docs/d3d12_command_objects.md | 94 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 86 insertions(+), 8 deletions(-) (limited to 'docs/d3d12_command_objects.md') diff --git a/docs/d3d12_command_objects.md b/docs/d3d12_command_objects.md index 56e1fd5cd..c39bee547 100644 --- a/docs/d3d12_command_objects.md +++ b/docs/d3d12_command_objects.md @@ -260,7 +260,7 @@ paragraph). Every call below except the two barriers is the fallback branch of a | RVA | Vtable offset | Console slot → PC method | Observed arguments | Confidence | |---:|---:|---|---|---| -| `0x2171e` | `+0xd0` | 26 → 26 `ResourceBarrier` | `NumBarriers=1`, `&{Type=2 (UAV), Flags=0, pResource=null}` | **Measured**: the shape is a global UAV barrier; slot 26 is the SDK `ResourceBarrier` | +| `0x2171e` | `+0xd0` | 26 → 26 `ResourceBarrier` | `NumBarriers=1`, `&{Type=2 (UAV), Flags=0, pResource=null}` | **Measured**: the shape is a global UAV barrier; slot 26 is the SDK `ResourceBarrier`; the site is gated (section 3.3b), so the call never fires in the shipping DLL | | `0x1d9cb` | `+0x70` | 14 → 14 `Dispatch` | `(1, 1, 1)` | **Measured**: exact `Dispatch` shape | | `0x1d85e` | `+0xc8` | 25 → 25 `SetPipelineState` | `RCX=list`, `RDX=[rdi+8]`: loaded at `0x1d7fa` and not changed before the call; the inline branch (`0x1d822`–`0x1d850`) copies 28 bytes from that object's `+0x10` | **Measured**: RDX is the pipeline the inline branch reads | | `0x1d7f4` | `+0x108` | 33 → 29 `SetComputeRootSignature` | one argument, `RDX=[rcx]`: the pointer stored next to the pipeline (`[rdi]`; the pipeline is `[rdi+8]`) | **Measured** shape; agrees with slot 33 in section 3.5a | @@ -324,6 +324,71 @@ That byte is one of seven bools at `0xd7738`–`0xd773e` in zero-initialised `.b the shipping DLL the label path is unreachable unless something writes that byte through a computed pointer, and the barrier path is the one that runs. +### 3.3b The batched build validates the geometry descriptors on the CPU first + +A logging-proxy harness (section 7, item 1) never reached the first list-vtable call: both runs of the +batched export faulted at RVA `0x142d3`, before the object received in the command-list parameter was +touched once. The reason is a CPU-side validation of the build items that the section 7 descriptor +guidance did not cover. The batched entry (`0x216a0`) reaches it through `0xe6a0` (call at `0x216dc`), +the packet processor `0xcc00` (call at `0xe781`) and a per-record validator at `0x14270` (call at +`0xce18`; a second call site exists at `0x11c25`). The processor walks the batched descriptor's 80-byte +build items (item `i` at descriptor `+ i*0x50`) and routes each by the dword at its `+0x08` — the +pointer's `+0x00` at the validator: kind 1 reaches the validator, kind 0 goes through `0xc820`/`0xc780` +instead, other values take an error path (`0xd52f`). The validator reads, from the pointer it receives +(all **measured** in the static disassembly): + +| Offset | Field | Check | +|---:|---|---| +| `+0x08` | descriptor count | loop bound | +| `+0x0c` | elements layout (`D3D12_ELEMENTS_LAYOUT`) | 0 = inline array of 0x38-byte records, 1 = array of pointers to records; other values print `D3D12 XDXR Error: Unexpected value for D3D12_ELEMENTS_LAYOUT` and throw `E_INVALIDARG` | +| `+0x10` | descriptor base | mode 0: record `i` at `base + i*0x38`; mode 1: record `i` at `[base + i*8]` | +| record `+0x00` | geometry type (`D3D12_RAYTRACING_GEOMETRY_TYPE`) | 0 = triangles, 1 = AABBs; others print `D3D12 XDXR Error: Unrecognized D3D12_RAYTRACING_GEOMETRY_TYPE` and throw `E_INVALIDARG` | +| record `+0x08` | AABB count (type 1) | accumulated | +| record `+0x10` | index format (type 0) | at most `0x39` and in the bitset `0x0220040000000000` — `DXGI_FORMAT_R32_UINT` (42), `DXGI_FORMAT_R16_TYPELESS` (53), `DXGI_FORMAT_R16_UINT` (57); others print `D3D12 XDXR Error: Unsupported index buffer format provided` and throw `E_NOTIMPL` | +| record `+0x18` | index count (type 0, format ≠ 0) | exact multiple of 3; otherwise prints `D3D12 XDXR Error: Triangle index count must be a multiple of 3 when an index buffer is provided` and throws `E_INVALIDARG` | +| record `+0x1c` | vertex count (type 0, format = 0) | checked instead of the index count, also an exact multiple of 3; otherwise prints `D3D12 XDXR Error: Triangle vertex count must be a multiple of 3 when no index buffer is provided` and throws `E_INVALIDARG` | + +The fault that stopped the dynamic runs is the base dereference itself: at `0x142d3` (`mov ecx,[rdx]`, +`rdx = base + i*0x38` in the inline mode) the record's type word is read with a CPU load, so a descriptor +whose base is a GPU address that is not CPU-readable faults there. For a replacement runtime this is a +measured host-side contract: the geometry descriptors must be backed by CPU-readable memory, not only by +the GPU arena. The validator returns the summed primitive count (the triangle counts ÷ 3 plus the AABB +counts), which the packet processor stores (`0xce1d`). It reads nothing past record `+0x1f`; what the +`+0x20..+0x37` tail of a record is used for is open — the dynamic runs stopped at the first record read. + +The same static pass settles what the first list calls would have been, and finds that three of the sites +section 3.3 and 3.3a list or miss are gated by the zero-initialised bytes of section 3.3a, so in the +shipping DLL they never run: + +- The `+0xd0` `ResourceBarrier` at `0x2171e` (section 3.3) needs a non-zero item count (`0x216e1`) and the + byte at `0xd773c` (`0x216e9`). Its shape stays as measured; in the shipping DLL the call never fires. +- Slot 90 (`+0x2d0`, call at `0xe836`) is new — it is not in the section 3.3a tail list. Its shape is + `(list, p, 0, last)`: `RDX = [item+0x28] + [item+0x54]*4`, where `item` is one 160-byte element of the + processor's output array, selected through the dword array beside it, `R9 = 1` on the last iteration, + and the element's dword at `+0x9c` is cleared first. The loop is behind the same `0xd773c` byte + (`0xe7d0`) and the count check, so it does not run in the shipping DLL either. +- The direct slot-146 barrier at `0xea99` is behind the adjacent byte `0xd773b` (`0xea41`, after the + per-item callback reports true); the wrapper calls at `0xebbb`, `0xec79`, `0xed37` and `0xee17` are not + gated by these bytes, and each ends in the measured slot-146 global UAV barrier (section 3.3a). + +The path also reads one byte past the seven bools of section 3.3a: `0xd773f` at `0xce3f` and `0x11c35`. +A linear sweep of `.text` finds no writes to `0xd7738`–`0xd773f` (only `cmp`/`movzx` reads; the two `lea` +sites take the address of `0xd7740`, one past the last byte), so the read-only range is eight bytes. + +With the gated sites removed, the shipping-DLL order for one item is (measured with a postbuild-info +type of 2, which routes to the `0x1d7c0` worker): the validation above → slot 146 four times through +the `0xd580` wrapper → the upload function `0x20ea0` (called at `0xee85`; a second site at `0xf0f9`): +slot 148 for `count * 40` bytes at alignment 16 (`0x20ed6`; the size is +`lea edx,[rsi+rsi*4]; shl edx,3`), root signature (33), pipeline (25, or its inline write), the +slot-148 pointer as root SRV (43, or inline), the count as a 32-bit root constant (37), and +`Dispatch((count+31)/32, 1, 1)` (`0x21054`, or its inline four-word packet) — then the per-entry +worker `0x1d7c0` (called at `0x217d0`) whose sequence section 3.3 lists, ending in the slot-146 +barrier at `0x1da02`. Postbuild-info types 0 and 3 route to the mirrored worker `0x1d540` (called at +`0x217e2`). Slot 148 is therefore asked before the per-entry dispatch, and the first dispatch on the +path is the upload function's own — the two refinements to section 7's prediction. The `+0x490` barrier +arguments (one global UAV group `{0x80, 0x80, 0x10, 0x10}`) and slot 148's `count * 40`/16 are confirmed +by both passes (D3D-293's static disassembly and this section's independent iced-x86 re-check). + ### 3.4 The object is wider than the public vtable The inner function at `0x1d7c0` receives the command-list pointer in RDX, copies it to RBX @@ -692,16 +757,22 @@ return has been measured. The executable is absent, so the next step should use the one shipped client that exists rather than invent slots. -1. **Confirm sections 3.3 and 3.3a with a logging proxy.** Create a test-only command +1. **Confirm sections 3.3, 3.3a and 3.3b with a logging proxy.** Create a test-only command list whose public GCL6/GCL8 vtable logs `(slot, raw arguments)` and whose tail is a page of logged unknown slots. Pass it to `XboxBvhBuilder::BuildRaytracingAccelerationStructureBatched2X` with a minimal non-empty - descriptor. The `+0xd0` barrier and `+0x70` dispatch should be observed first; the `+0x490` - call should arrive with one global UAV barrier group (section 3.3), and slot 148 should be - asked for `count * 40` bytes. Keep the cursor at its limit so every call reaches the vtable. If the - builder validates its inputs before reaching the dispatch, use a descriptor shaped like the - one its own `GetRaytracingAccelerationStructurePrebuildInfo` accepts (prior art measured a - 3,000-vertex triangle geometry; the prebuild answer is 204,800 bytes / 128,704 scratch). + descriptor. The proxy ran twice; both runs stopped one step short, at the CPU-side geometry + validation of section 3.3b (fault at `0x142d3`), before the first list call. The static pass + settled what the first calls will be: not the `+0xd0` barrier — it is gated and never fires + in the shipping DLL — but the wrapper's slot-146 barriers, then the upload function's slot + 148 for `count * 40` bytes and its own `Dispatch((count+31)/32, 1, 1)`, and only then the + per-entry `Dispatch(1,1,1)` of section 3.3; the other new slot, 90, is gated too + (section 3.3b). Keep the cursor at its limit so every call reaches the vtable, and back the + geometry descriptors with CPU-readable memory holding valid 0x38-byte records per section 3.3b + (type 0, index format 0, vertex count a multiple of 3 — prior art measured a 3,000-vertex + triangle geometry; the prebuild answer is 204,800 bytes / 128,704 scratch). A descriptor shaped + like the one `GetRaytracingAccelerationStructurePrebuildInfo` accepts is not enough by itself, + because the validation reads the records with CPU loads. 2. **GCL8 is now implemented** in PR #164 (public slot 81, recorded/reset, CTest 9/9); the builder's `+0x490` is `Barrier` (section 3.3), and its slot 148 needs an upload allocator (section 3.3a). 3. **When the executable appears, trace the four creation calls first.** Per-slot counters on @@ -749,6 +820,13 @@ the SDK; the console GUIDs are attributed to SCARAB in `call [reg+disp]` sites in the rest of `.text` whose object register holds the list pointer, each read with the argument registers set before it and the inline write it falls back from; the barrier constant is the 16 bytes at RVA `0xcdf60` (file offset from the section table). +- Section 3.3b and the gated sites: a second, independent disassembly pass (iced-x86, run for the + D3D-293 measurement) of the batched entry, the validation chain (`0xe6a0`, `0xcc00`, `0x14270`), + the upload function `0x20ea0` and the wrapper call sites; the dynamic side is D3D-293's + logging-proxy harness, whose two runs faulted at `0x142d3` before the first list call. The + quoted validation messages are the DLL's own wide strings at the `.rdata` addresses the throw + paths load. The gate-byte sentence is a linear sweep of `.text` collecting memory operands + targeting `0xd7738`–`0xd773f`. - Public slots: parse the `MIDL_INTERFACE`/`virtual` declarations in `d3d12.h`; the counts in section 2 include the seven `IUnknown`+`ID3D12Object` slots. Cross-check selected values with `python tools/d3d12_xs_surface.py --check --sdk` (116 slots, 83 standard GUIDs) and -- cgit v1.2.3 From 56839d2dd9a7de444b267216b49cc25938ef6659 Mon Sep 17 00:00:00 2001 From: NiiRoZz Date: Sun, 22 Nov 2026 20:13:37 +0100 Subject: D3D-350: device slots 8, 9, 12 and 36 cannot be measured from the package The package ships no D3D12 runtime (d3d12_xs.dll is part of the console OS), and the device clients it does ship never create a queue, allocator, command list or fence: neither XboxBvhBuilder.dll nor amd_fidelityfx_upscaler_xbox.dll contains those IIDs or imports GUID data from d3d12_xs.dll, and none of their indirect calls at 0x40/0x48/0x60/0x120 is made on the device. The callers are in the game executable, so the slots stay Open. tools/d3d12_iid_scan.py reports which ID3D12 IIDs (from the SDK's d3d12.h) an image contains and what it imports from d3d12_xs.dll, warning on imports that could be IID data. It prints names and counts only. docs/d3d12_command_objects.md section 2.1 records the result with counts and how each column was measured. tests/test_d3d12_iid_scan.py covers the tool on a hand-written header and hand-built PE images (no game files). Co-Authored-By: Claude Opus 5.5 --- docs/d3d12_command_objects.md | 27 +++++++ tests/test_d3d12_iid_scan.py | 154 +++++++++++++++++++++++++++++++++++++ tools/d3d12_iid_scan.py | 171 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 352 insertions(+) create mode 100644 tests/test_d3d12_iid_scan.py create mode 100644 tools/d3d12_iid_scan.py (limited to 'docs/d3d12_command_objects.md') diff --git a/docs/d3d12_command_objects.md b/docs/d3d12_command_objects.md index 56e1fd5cd..4331d5ddb 100644 --- a/docs/d3d12_command_objects.md +++ b/docs/d3d12_command_objects.md @@ -112,6 +112,33 @@ texture-creation method at 76 where the PC interface has `CreateStateObject`/som by that work.** They are the four calls a game must make before it can have a queue, allocator, list or fence, so they are the first thing a trace must confirm. +**They cannot be measured from the package either (D3D-350).** The package ships no D3D12 runtime: +the 16 DLLs in [`game/xbox-1.0.2.1.json`](../game/xbox-1.0.2.1.json) do not include +`d3d12_xs.dll`, which is part of the console OS, and the device clients that are shipped never call +these four slots. Measured on 1.0.2.1 (counts only): + +| Image | `ID3D12*` IIDs it contains | Imports from `d3d12_xs.dll` | Calls at `0x40`/`0x48`/`0x60`/`0x120` on the device | +|---|---|---|---| +| `XboxBvhBuilder.dll` | `PipelineState`, `RootSignature` | `D3D12SerializeVersionedRootSignature` | none: no indirect call at any of the four offsets | +| `amd_fidelityfx_upscaler_xbox.dll` | `CommandSignature`, `DescriptorHeap`, `Device`, `Heap`, `PipelineState`, `Resource`, `RootSignature`, `RootSignatureDeserializer` | `D3D12CreateRootSignatureDeserializer` | none: the 3 calls at `0x40` are `ID3D12Resource::Map` on a resource it has just created, the 29 at `0x48` are `Close`/`Unmap`-shaped calls with no `(type, &IID, &out)` arguments, the 4 at `0x60` are a function-pointer field in a plain struct (no vtable load), and there are none at `0x120` | +| `amd_fidelityfx_loader_xbox.dll`, `Bink2Scarlett.dll` | none | none | — | + +Neither image contains the IID of `ID3D12CommandQueue`, `ID3D12CommandAllocator`, +`ID3D12CommandList`, `ID3D12GraphicsCommandList`, `ID3D12Fence` or `ID3D12Fence1`, and neither +can take one from `d3d12_xs.dll`: each imports one function there and no GUID data (ordinals +23–115). A creator called through `IID_PPV_ARGS` needs that IID, so these clients do not create +queues, allocators, lists or fences; they record into lists the game gives them. The interfaces +that *are* present are the positive control: they are what each client is known to create +(compute PSOs through slot 62, root signatures, descriptor heaps, and resources through slots 27 +and 76). The IID column is reproduced by `python -I tools/d3d12_iid_scan.py /*.dll` +(`tests/test_d3d12_iid_scan.py`); the call-site column comes from `dumpbin /disasm` listings, +following each `0x40`/`0x48`/`0x60`/`0x120` call back to its receiver. + +So the four slots' callers are in the game executable, which the package does not contain (the +same blocker as RT-5). Confidence for slots 8, 9, 12 and 36 stays **Open**: the table in §2.1 is +still the SDK baseline. Once the executable is available, `tools/d3d12_iid_scan.py` run on it +shows whether it carries these IIDs, and its call sites through them give the slots. + ### 2.2 Queue, allocator and fence `ID3D12CommandQueue` is declared at `d3d12.h:8701`. It has 19 slots (0–18); its own methods start diff --git a/tests/test_d3d12_iid_scan.py b/tests/test_d3d12_iid_scan.py new file mode 100644 index 000000000..269257c1b --- /dev/null +++ b/tests/test_d3d12_iid_scan.py @@ -0,0 +1,154 @@ +"""tools/d3d12_iid_scan.py on a hand-written header and hand-built PE images (no game files, no SDK needed).""" +import json +import os +import struct +import subprocess +import sys +import tempfile +import unittest +import uuid + +ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +sys.path.insert(0, os.path.join(ROOT, "tools")) + +import d3d12_iid_scan as scan # noqa: E402 + +QUEUE = uuid.UUID("0ec870a6-5d7e-4c22-8cfc-5baae07616ed") +RESOURCE = uuid.UUID("696442be-a72e-4059-bc79-5b5c98040fad") + +HEADER = f""" + MIDL_INTERFACE("{QUEUE}") + ID3D12CommandQueue : public ID3D12Pageable + {{ }}; + MIDL_INTERFACE("{RESOURCE}") + ID3D12Resource : public ID3D12Pageable + {{ }}; + MIDL_INTERFACE("00000000-0000-0000-c000-000000000046") + IUnknown + {{ }}; +""" + + +def pe32plus(imports, payload=b""): + """A minimal PE32+ image: one section holding `payload` and an import directory. + + imports: {dll_name: [function name or ordinal int, ...]}. + """ + sect_rva, sect_raw = 0x1000, 0x200 + body = bytearray(payload) + + def put(blob, align=8): + while len(body) % align: + body.append(0) + at = len(body) + body.extend(blob) + return sect_rva + at + + descriptors = [] + for dll, funcs in imports.items(): + thunks = [] + for f in funcs: + if isinstance(f, int): + thunks.append((1 << 63) | f) + else: + thunks.append(put(struct.pack(" [ ...] [--header PATH/d3d12.h] [--json OUT] + +Without --header it takes d3d12.h from the newest Windows SDK under "Windows Kits\10\Include". +It also lists what each image imports from d3d12_xs.dll and warns when one of those imports could be IID data (an +IID_* name, or an ordinal in the GUID range 23-115), because an IID taken from there would not show up here. +""" +from __future__ import annotations + +import argparse +import glob +import json +import os +import re +import struct +import sys +import uuid + +MIDL = re.compile(r'MIDL_INTERFACE\("([0-9a-fA-F-]{36})"\)\s*\n\s*(ID3D12\w+)') + +# The creators whose result interfaces docs/d3d12_command_objects.md section 2.1 asks about. +FOCUS = ("ID3D12CommandQueue", "ID3D12CommandAllocator", "ID3D12CommandList", "ID3D12GraphicsCommandList", + "ID3D12Fence", "ID3D12Fence1") + + +def default_header() -> str | None: + root = os.path.join(os.environ.get("ProgramFiles(x86)", r"C:\Program Files (x86)"), + "Windows Kits", "10", "Include") + found = glob.glob(os.path.join(root, "*", "um", "d3d12.h")) + + def version(path: str) -> tuple[int, ...]: + name = os.path.basename(os.path.dirname(os.path.dirname(path))) + return tuple(int(p) for p in name.split(".") if p.isdigit()) + + return max(found, key=version) if found else None + + +def read_iids(header: str) -> dict[str, uuid.UUID]: + with open(header, encoding="utf-8", errors="replace") as f: + text = f.read() + return {name: uuid.UUID(guid) for guid, name in MIDL.findall(text)} + + +def d3d12_xs_imports(data: bytes) -> list[str] | None: + """What the PE image imports from d3d12_xs.dll: names, or "#N" for an import by ordinal (ordinals 23-115 are + GUID data, docs/d3d12_xs_surface.md section 2). None when the image does not import d3d12_xs.dll at all.""" + try: + if data[:2] != b"MZ": + return None + pe = struct.unpack_from(" int | None: + for i in range(sections): + s = table + 40 * i + vsize, va, rsize, raw = struct.unpack_from(" bytes: + return data[at:data.index(b"\0", at)] + + pos = offset(imp_rva) if imp_rva else None + while pos is not None and pos + 20 <= len(data): + lookup_rva, _, _, name_rva, iat_rva = struct.unpack_from(" list[str]: + """The d3d12_xs.dll imports that could be IID data: IID_* names and ordinals in the GUID range 23-115.""" + out = [] + for n in names or []: + if n.startswith("IID_") or (n.startswith("#") and n[1:].isdigit() and 23 <= int(n[1:]) <= 115): + out.append(n) + return out + + +def scan(path: str, iids: dict[str, uuid.UUID]) -> dict: + with open(path, "rb") as f: + data = f.read() + found = sorted(name for name, guid in iids.items() if guid.bytes_le in data) + imports = d3d12_xs_imports(data) + return { + "image": os.path.basename(path), + "found": found, + "focus": {name: name in found for name in FOCUS if name in iids}, + "d3d12_xs_imports": imports, + "possible_iid_imports": possible_iid_imports(imports), + } + + +def main(argv: list[str] | None = None) -> int: + ap = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) + ap.add_argument("images", nargs="+") + ap.add_argument("--header", help="d3d12.h to read the IIDs from (default: newest Windows SDK)") + ap.add_argument("--json", help="also write the result here") + args = ap.parse_args(argv) + header = args.header or default_header() + if not header or not os.path.isfile(header): + print("ERROR: d3d12.h not found; pass --header", file=sys.stderr) + return 2 + iids = read_iids(header) + if not iids: + print(f"ERROR: no ID3D12 MIDL_INTERFACE declarations in {header}", file=sys.stderr) + return 2 + print(f"{len(iids)} ID3D12 IIDs from {header}") + results = [] + for path in args.images: + r = scan(path, iids) + results.append(r) + absent = [n for n, present in r["focus"].items() if not present] + print(f"== {r['image']}: {len(r['found'])} found") + print(" found: " + (", ".join(r["found"]) or "none")) + print(" absent from the queue/allocator/list/fence set: " + (", ".join(absent) or "none")) + if r["d3d12_xs_imports"] is not None: + print(" imports from d3d12_xs.dll: " + (", ".join(r["d3d12_xs_imports"]) or "none")) + if r["possible_iid_imports"]: + print(" WARNING: these d3d12_xs.dll imports may be IID data, so an absent IID proves nothing for " + "this image: " + ", ".join(r["possible_iid_imports"])) + if args.json: + with open(args.json, "w", encoding="utf-8", newline="\n") as f: + json.dump({"header": os.path.basename(header), "iids": len(iids), "images": results}, f, indent=2) + f.write("\n") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) -- cgit v1.2.3 From ca438076bc73ac960e2743d7b0e092a457052fca Mon Sep 17 00:00:00 2001 From: CLHelper <359823989+CLHelper@users.noreply.github.com> Date: Sun, 22 Nov 2026 19:37:45 +0000 Subject: feat(tools): inline_scan finds inline command-list writes and whether each checks the cursor limit The package's DLLs check before every inline write (BVH builder 196/196, FSR 9/9), so a layer that keeps the cursor at the limit sees every command. Whether the game's executable does the same was open until it is available; inline_scan answers it in one pass over a dumpbin listing. Baseline in d3d12_command_objects.md, day-one step in design.md. --- docs/d3d12_command_objects.md | 21 ++++ docs/design.md | 6 ++ tests/test_inline_scan.py | 154 +++++++++++++++++++++++++++++ tools/inline_scan.py | 223 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 404 insertions(+) create mode 100644 tests/test_inline_scan.py create mode 100644 tools/inline_scan.py (limited to 'docs/d3d12_command_objects.md') diff --git a/docs/d3d12_command_objects.md b/docs/d3d12_command_objects.md index 56e1fd5cd..b72bf3696 100644 --- a/docs/d3d12_command_objects.md +++ b/docs/d3d12_command_objects.md @@ -453,6 +453,27 @@ them, and it is the simplest contract for a layer that does not want to decode t executable makes the same check before writing is unknown until it is available; it is compiled against the same console headers. +**Every inline write in the package's DLLs checks first.** `tools/inline_scan.py` finds each cursor store-back +(`mov [list+18h],reg` after stores through the cursor) and looks for the compare in front of it. On the 1.0.2.1 +DLLs (dumpbin 14.44 listings): + +| Image | Inline writes | Checked | Not checked | Limit compared | Fallback slot (sites) | +|---|---:|---:|---:|---|---| +| `XboxBvhBuilder.dll` | 196 | 196 | 0 | `+0x30` ×165, `+0x28` ×30, a register loaded in another block ×1 | 45 ×71, 37 ×35, 25 ×34, 14 ×24, 39 ×16, 43 ×9, 80 ×4; 3 reach theirs through a shared jump the tool does not follow | +| `amd_fidelityfx_upscaler_xbox.dll` | 9 | 9 | 0 | `+0x30` ×8, `+0x28` ×1 | 35 ×6, 25, 41, 14 | + +**Measured.** The packet headers it reads back are the two dispatch forms above: `0x4002c400` (26 four-word +dispatches in the builder, one in FSR) and `0x4003cc00` (the builder's four five-word ones). The other 14 DLLs have +no inline write, except one checked site in `libHttpClient.GDK.dll`, which imports nothing from D3D12: read a +result as an upper bound of about one site per image. Removing the compare and branch in front of the builder's +`0x14972` write turns exactly that site into "not checked", so a missing check is visible. + +On the executable, `python -I tools/inline_scan.py --sites` answers the question in one pass (see the day-one +list in `docs/design.md`): no unchecked site means a cursor-at-limit layer sees every command the game records; each +unchecked site is listed by RVA and is a write that layer never sees. Its fallback-slot line is the set of console +list methods the game reaches through the vtable. Limit offsets other than `+0x28`/`+0x30` would be command kinds +the DLLs never write (draws, input-assembler and output-merger state); read a few of those sites by hand. + **The five-word dispatch.** The BVH builder also writes `0x4003cc00, x, 1, 1, W`: - **Sites:** `0x14972`, `0x15215`, `0x1536a` and `0x1d002`, each checked against the dispatch limit `+0x28`. The diff --git a/docs/design.md b/docs/design.md index 6ee0e6f4e..c8312491a 100644 --- a/docs/design.md +++ b/docs/design.md @@ -29,6 +29,7 @@ tools/ Python analysis tools (no game data inside) pe_inspect.py PE headers, sections, entropy, imports sorted by where they resolve, .pdata, TLS rpf_probe.py RPF header survey of a game folder manifest.py SHA-256 manifest of a game folder, plus a --verify mode + inline_scan.py inline command-list writes in an image, and whether each checks the cursor limit first scripts/ first_look.ps1 run once the exe arrives: the full report set for it runtime/ C++ native loader (CMake + Ninja, MSVC) @@ -51,6 +52,11 @@ This writes `reports/exe/` (JSON plus a readable summary). Check it in this orde 2. **Import table.** Each DLL is marked `bundled` (in the game folder), `system` (present on this Windows), or `shim` (needs a reimplementation). The `shim` list is the real to-do list. 3. **.pdata function count.** This gives function boundaries for patching and later analysis. +4. **Inline command-list writes.** `python -I tools/inline_scan.py \game_scarlett_master.exe --sites` (a few + minutes; it streams `dumpbin /disasm`). "UNCHECKED 0" means every inline write checks the cursor limit, so a + layer that keeps the cursor at the limit receives every command through the vtable; any unchecked site is a + write that layer never sees. The package's DLLs check at every site + ([d3d12_command_objects.md](d3d12_command_objects.md), "Every inline write in the package's DLLs checks first"). Then `runtime\build\gta6rt.exe --dry-run ` maps the image and binds every import to the shim table without running any game code. It reports what it couldn't bind. diff --git a/tests/test_inline_scan.py b/tests/test_inline_scan.py new file mode 100644 index 000000000..67b93feb5 --- /dev/null +++ b/tests/test_inline_scan.py @@ -0,0 +1,154 @@ +"""Unit tests for tools/inline_scan.py on hand-written dumpbin-style listings. + +The listings are synthetic: the instruction shapes of a checked and an unchecked inline command-list write, written +here line by line, so the test needs no game files, no dumpbin and no third-party packages. + + python -I tests/test_inline_scan.py +""" +import os +import sys +import unittest + +ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +TOOLS_DIR = os.path.join(ROOT, "tools") +if TOOLS_DIR not in sys.path: + sys.path.insert(0, TOOLS_DIR) + +import inline_scan # noqa: E402 + + +def listing(*rows): + """Rows are 'mnemonic operands'; '@ADDR mnemonic operands' pins an address (a branch target).""" + out = [] + for i, row in enumerate(rows): + mnem, _, ops = row.partition(" ") + addr = 0x140001000 + 4 * i + if mnem.startswith("@"): + addr = int(mnem[1:], 16) + mnem, _, ops = ops.partition(" ") + out.append(f" {addr:016X}: {mnem:<11} {ops}\n") + return out + + +def sites(rows): + return list(inline_scan.scan(listing(*rows))) + + +# A four-word dispatch with its limit check and the vtable fallback (slot 14 at +0x70) when the buffer is full. +GUARDED = ( + "mov rax,qword ptr [rbx+18h]", + "cmp rax,qword ptr [rbx+28h]", + "jae 0000000140002000", + "mov dword ptr [rax],4002C400h", + "mov dword ptr [rax+4],ecx", + "add rax,10h", + "mov qword ptr [rbx+18h],rax", + "mov byte ptr [rbx+0000000000000140h],0", + "jmp 0000000140003000", + "@0000000140002000 mov rax,qword ptr [rbx]", + "mov rcx,rbx", + "call qword ptr [rax+0000000000000070h]", +) +UNGUARDED = tuple(r for r in GUARDED if not r.startswith(("cmp", "jae"))) + + +class InlineScanTests(unittest.TestCase): + def test_guarded_dispatch_is_checked_with_limit_header_and_fallback_slot(self): + (site,) = sites(GUARDED) + self.assertTrue(site["checked"]) + self.assertTrue(site["list"]) + self.assertEqual(site["limit"], 0x28) + self.assertEqual(site["size"], 0x10) + self.assertEqual(site["header"], 0x4002C400) + self.assertEqual(site["fallback_slot"], 14) + + def test_the_same_write_without_its_compare_is_unchecked(self): + # The only list field (+140h) is written after the store-back. + (site,) = sites(UNGUARDED) + self.assertTrue(site["list"]) + self.assertFalse(site["checked"]) + + def test_unchecked_with_the_root_header_table_read_before_the_write(self): + rows = list(UNGUARDED) + rows.insert(1, "mov edx,dword ptr [rbx+rdx*4+0000000000000344h]") + (site,) = sites(rows) + self.assertTrue(site["list"]) + self.assertFalse(site["checked"]) + + def test_limit_held_in_a_register_and_cursor_advanced_with_lea(self): + rows = ( + "mov rcx,qword ptr [rbx+18h]", + "mov rdx,qword ptr [rbx+30h]", + "cmp rcx,rdx", + "jae 0000000140002000", + "mov eax,dword ptr [rbx+0000000000000344h]", + "mov dword ptr [rcx],eax", + "lea rax,[rcx+0Ch]", + "mov qword ptr [rcx+4],r8", + "mov qword ptr [rbx+18h],rax", + ) + (site,) = sites(rows) + self.assertTrue(site["checked"]) + self.assertEqual(site["limit"], 0x30) + self.assertEqual(site["size"], 0xC) + + def test_limit_register_loaded_in_another_block_still_counts_as_checked(self): + rows = ( + "cmp rcx,rdx", + "jae 0000000140002000", + "mov eax,dword ptr [rbx+0000000000000344h]", + "mov dword ptr [rcx],eax", + "lea rax,[rcx+0Ch]", + "mov qword ptr [rbx+18h],rax", + ) + (site,) = sites(rows) + self.assertTrue(site["checked"]) + self.assertEqual(site["limit"], inline_scan.REG_LIMIT) + + def test_list_copied_to_another_register_is_followed(self): + rows = ( + "mov rbx,rcx", + "mov rax,qword ptr [rcx+18h]", + "cmp rax,qword ptr [rcx+30h]", + "jae 0000000140002000", + "mov dword ptr [rax],edx", + "add rax,8", + "mov qword ptr [rbx+18h],rax", + ) + (site,) = sites(rows) + self.assertTrue(site["checked"]) + self.assertEqual(site["limit"], 0x30) + + def test_stack_frame_slot_is_not_a_list(self): + rows = ( + "mov qword ptr [rbp+0000000000000140h],rcx", + "lea rax,[0000000140090000h]", + "mov qword ptr [rax],rcx", + "mov qword ptr [rbp+18h],rax", + ) + self.assertTrue(all(not s["list"] for s in sites(rows))) + + def test_plain_structure_pointer_bump_is_not_a_list(self): + rows = ( + "mov rax,qword ptr [rdi+18h]", + "mov qword ptr [rax],rdx", + "add rax,8", + "mov qword ptr [rdi+18h],rax", + ) + (site,) = sites(rows) + self.assertFalse(site["list"]) + + def test_listing_with_byte_column_parses_the_same(self): + rows = [line.replace(": ", ": 48 8B 43 18 ", 1) for line in listing(*GUARDED)] + (site,) = list(inline_scan.scan(rows)) + self.assertTrue(site["checked"]) + self.assertEqual(site["fallback_slot"], 14) + + def test_summary_counts_checked_and_unchecked(self): + text = inline_scan.summarize(sites(GUARDED) + sites(UNGUARDED)) + self.assertIn("checked 1, UNCHECKED 1", text) + self.assertIn("+0x28 x1", text) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/inline_scan.py b/tools/inline_scan.py new file mode 100644 index 000000000..47d36ac44 --- /dev/null +++ b/tools/inline_scan.py @@ -0,0 +1,223 @@ +"""Find the inline command-list writes in an x64 image and say whether each one checks the cursor limit first. + +Usage: + python -I tools/inline_scan.py [--base 0x140000000] [--sites] + +Code compiled against the console headers writes some commands into the list's buffer itself +(docs/d3d12_command_objects.md, "The list object is wider than its vtable"): it compares the write cursor +`[list+18h]` with a limit (`[list+28h]` for a dispatch, `[list+30h]` for root arguments in the package's DLLs), +writes the packet through the cursor, advances it and stores it back; when the buffer is full it calls the vtable +method instead. A layer that keeps the cursor at the limit sees every command only if every such write checks +first. This tool finds each cursor store-back `mov [list+18h],reg` that follows stores through the cursor, looks +back to the previous store-back of the same list, and sorts the site into: + + checked a compare of the cursor against `[list+X]` (X != 18h), or against a register, followed by an + unsigned branch; the branch target's vtable call is reported as the fallback slot + UNCHECKED no compare, but the cursor was loaded from the list and the list's own fields are touched + (+140h..+143h, +344h, +544h): an inline write that a cursor-at-limit layer never sees + unrelated no compare and no list field: another structure with a pointer at +18h + +A PE is disassembled with MSVC `dumpbin /disasm:nobytes` (it comes with the build tools the runtime needs) and +streamed, so an image of any size works in one pass; a saved dumpbin listing (with or without the byte column) +works too, on any OS. Nothing is executed. The output is RVAs, counts and constants, no code bytes. +The matcher knows the instruction shapes MSVC emits for these writes (see tests/test_inline_scan.py); a shape it +does not know shows up as `unrelated`, so read a few of those by hand on a new image. +""" +import argparse +import collections +import re +import shutil +import subprocess +import sys +from pathlib import Path + +LOOKBACK = 64 # instructions searched backwards from a store-back +FALLBACK_WINDOW = 16 # instructions after the branch target to look for the vtable call +PENDING_WINDOW = 400 # instructions to wait for a forward branch target +TAIL_WINDOW = 6 # instructions after a store-back that may still show a list field +REG64 = r"r(?:[abcd]x|[sd]i|bp|sp|8|9|1[0-5])" +DUMPBIN_GLOB = "Program Files*/Microsoft Visual Studio/*/*/VC/Tools/MSVC/*/bin/Hostx64/x64/dumpbin.exe" + +LINE = re.compile(r"^\s+([0-9A-F]{8,16}): (?:(?:[0-9A-F]{2} )+\s+)?([a-z][a-z0-9]*)\s*(.*)$") +LOAD = re.compile(rf"^({REG64}),qword ptr \[({REG64})\+18h\]$") +STORE_BACK = re.compile(rf"^qword ptr \[({REG64})\+18h\],({REG64})$") +CMP = re.compile(rf"^(?:({REG64}),qword ptr \[({REG64})\+([0-9A-F]+)h?\]|qword ptr \[({REG64})\+([0-9A-F]+)h?\],({REG64}))$") +LEA = re.compile(rf"^({REG64}),\[({REG64})\+([0-9A-F]+)h?\]$") +ADD = re.compile(rf"^({REG64}),([0-9A-F]+)h?$") +STORE = re.compile(r"^(?:byte|word|dword|qword|xmmword|ymmword) ptr \[(\w+)(?:\+([0-9A-F]+)h?)?\],(.+)$") +IMM = re.compile(r"^([0-9A-F]+)h?$") +COPY = re.compile(rf"^({REG64}),({REG64})$") +LIMIT_LOAD = re.compile(rf"^({REG64}),qword ptr \[({REG64})\+([0-9A-F]+)h?\]$") +LIST_FIELDS = re.compile(r"\[(\w+)(?:\+\w+\*\d)?\+0*(?:140|141|143|344|544)h\]") # fields only a D3D12.X list has +VCALL = re.compile(rf"^qword ptr \[({REG64})\+([0-9A-F]+)h?\]$") +UNSIGNED_JCC = {"jae", "jb", "ja", "jbe"} +REG_LIMIT = -1 # limit compared through a register loaded outside the scanned span +JCC_TARGET = re.compile(r"^([0-9A-F]{8,16})$") + + +def read_lines(source: Path): + if source.suffix.lower() in (".exe", ".dll"): + dumpbin = shutil.which("dumpbin") or next(iter(sorted(Path("C:/").glob(DUMPBIN_GLOB))), None) + if not dumpbin: + sys.exit("dumpbin.exe not found: run from a VS developer shell or install the MSVC build tools") + proc = subprocess.Popen([str(dumpbin), "/nologo", "/disasm:nobytes", str(source)], + stdout=subprocess.PIPE, text=True, errors="replace") + yield from proc.stdout + if proc.wait(): + sys.exit(f"dumpbin failed with exit code {proc.returncode}") + return + with open(source, encoding="utf-8", errors="replace") as f: + yield from f + + +def instructions(lines): + for line in lines: + m = LINE.match(line) + if m: + yield int(m.group(1), 16), m.group(2), m.group(3).strip() + + +def classify(window, base, stored): + """Look back from a store-back of `stored` into [base+18h]. Return a site dict or None.""" + chain, size, load, bases, broken = {stored}, 0, None, {base}, False + touched = {stored} # every register the cursor passed through, for counting stores + span = [] + for addr, mnem, ops in reversed(window): + if mnem == "ret" or (mnem == "mov" and (sb := STORE_BACK.match(ops)) and sb.group(1) in bases): + break # the previous site of this list, or the previous function + span.append((addr, mnem, ops)) + if mnem == "mov" and (cp := COPY.match(ops)) and cp.group(1) in bases: + bases.add(cp.group(2)) # `mov rbx,rcx`: the list is in both + if load is None and not broken: + if mnem == "mov" and (lm := LOAD.match(ops)) and lm.group(1) in chain and lm.group(2) in bases: + load = addr + elif mnem == "lea" and (le := LEA.match(ops)) and le.group(1) in chain: + chain.discard(le.group(1)) # defined here; older values of it are not the cursor + chain.add(le.group(2)) + touched.add(le.group(2)) + size += int(le.group(3), 16) + elif mnem == "add" and (am := ADD.match(ops)) and am.group(1) in chain: + size += int(am.group(2), 16) + elif ops.split(",", 1)[0] in chain and mnem not in ("cmp", "test") and not mnem.startswith("j"): + broken = True # the stored value was computed from something other than the cursor + span.reverse() + stores, header, limit, target, evidence = 0, None, None, None, False + limit_regs = {} # register -> limit offset, for `mov rdx,[list+30h]` ... `cmp rcx,rdx` + for i, (addr, mnem, ops) in enumerate(span): + if mnem == "mov" and (lr := LIMIT_LOAD.match(ops)) and lr.group(2) in bases and int(lr.group(3), 16) != 0x18: + limit_regs[lr.group(1)] = int(lr.group(3), 16) + if mnem == "cmp" and (rr := COPY.match(ops)) and (rr.group(1) in touched or rr.group(1) in limit_regs): + nxt = span[i + 1] if i + 1 < len(span) else None + if nxt and nxt[1] in UNSIGNED_JCC: + # the limit came from [list+X] here, or in a block that jumps to this one (REG_LIMIT) + limit = limit_regs.get(rr.group(2), limit_regs.get(rr.group(1), REG_LIMIT)) + if jt := JCC_TARGET.match(nxt[2]): + target = int(jt.group(1), 16) + if mnem.startswith(("mov", "vmov")) and (st := STORE.match(ops)) and st.group(1) in touched: + stores += 1 + imm = IMM.match(st.group(3)) + if header is None and not st.group(2) and imm and mnem == "mov": + header = int(imm.group(1), 16) + if (lf := LIST_FIELDS.search(ops)) and lf.group(1) in bases: + evidence = True + if mnem == "cmp" and (cm := CMP.match(ops)): + reg_base, disp = (cm.group(2), cm.group(3)) if cm.group(1) else (cm.group(4), cm.group(5)) + if reg_base in bases and int(disp, 16) != 0x18: + limit = int(disp, 16) + nxt = span[i + 1] if i + 1 < len(span) else None + if nxt and nxt[1].startswith("j") and nxt[1] != "jmp" and (jt := JCC_TARGET.match(nxt[2])): + target = int(jt.group(1), 16) + if not stores or base == "rsp": + return None + checked = limit is not None + # A guard-free list write must load the cursor from the list nearby; without that it is some other structure. + is_list = checked or (evidence and load is not None and not broken) + return {"load": load, "base": base, "checked": checked, "list": is_list, "limit": limit, "size": size, + "stores": stores, "header": header, "target": target, "fallback_slot": None, + "bases": bases, "load_traced": load is not None and not broken} + + +def scan(lines): + """Yield one dict per cursor store-back site; fallback slots are filled in once the branch target is seen.""" + window = collections.deque(maxlen=LOOKBACK) + pending, watching, tail = [], [], [] + for idx, (addr, mnem, ops) in enumerate(instructions(lines)): + for item in tail[:]: # list fields written right after the store-back (e.g. clearing +140h) count too + site, left = item + tail.remove(item) + if (lf := LIST_FIELDS.search(ops)) and lf.group(1) in site["bases"] and site["load_traced"]: + site["list"] = True + elif left > 1: + tail.append((site, left - 1)) + for item in watching[:]: + site, left = item + watching.remove(item) + if mnem == "call" and (vm := VCALL.match(ops)): + site["fallback_slot"] = int(vm.group(2), 16) // 8 + elif left > 1: + watching.append((site, left - 1)) + for item in pending[:]: + site, opened = item + if addr == site["target"]: + watching.append((site, FALLBACK_WINDOW)) + pending.remove(item) + elif idx - opened > PENDING_WINDOW: + pending.remove(item) + if mnem == "mov" and (sb := STORE_BACK.match(ops)): + site = classify(window, sb.group(1), sb.group(2)) + if site: + site["store_back"] = addr + if site["target"] is not None: + pending.append((site, idx)) + if not site["list"]: + tail.append((site, TAIL_WINDOW)) + yield site + window.append((addr, mnem, ops)) + + +def limit_text(limit): + return "none" if limit is None else "reg" if limit == REG_LIMIT else f"+0x{limit:x}" + + +def summarize(sites): + checked = [s for s in sites if s["checked"]] + unchecked = [s for s in sites if not s["checked"] and s["list"]] + unrelated = [s for s in sites if not s["list"]] + plain = lambda v: "none" if v is None else str(v) + out = [f"list sites {len(checked) + len(unchecked)}: checked {len(checked)}, UNCHECKED {len(unchecked)} " + f"(plus {len(unrelated)} cursor-like stores with no list field nearby, likely other structures)"] + for title, key, group, fmt in (("limit offsets (checked)", "limit", checked, limit_text), + ("fallback vtable slots (checked)", "fallback_slot", checked, plain), + ("packet sizes, checked", "size", checked, plain), + ("packet sizes, unchecked", "size", unchecked, plain)): + hist = collections.Counter(s[key] for s in group) + out.append(f"{title}: " + ", ".join(f"{fmt(k)} x{n}" for k, n in hist.most_common(12))) + headers = collections.Counter(s["header"] for s in sites if s["header"] is not None) + out.append("header dwords: " + ", ".join(f"0x{h:08x} x{n}" for h, n in headers.most_common(12))) + return "\n".join(out) + + +def main() -> int: + p = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + p.add_argument("source", type=Path) + p.add_argument("--base", type=lambda s: int(s, 16), help="image base (default: inferred from the first site)") + p.add_argument("--sites", action="store_true", help="print every site") + args = p.parse_args() + if not args.source.is_file(): + print(f"{args.source} not found", file=sys.stderr) + return 2 + sites = list(scan(read_lines(args.source))) + base = args.base if args.base is not None else min((s["store_back"] for s in sites), default=0) & ~0xFFFFFFF + print(summarize(sites)) + if args.sites: + rva = lambda a: "?" if a is None else f"+0x{a - base:x}" + for s in sites: + state = f"checked {limit_text(s['limit'])}" if s["checked"] else "UNCHECKED" if s["list"] else "unrelated" + header = "-" if s["header"] is None else f"0x{s['header']:08x}" + print(f" load {rva(s['load'])} store {rva(s['store_back'])} [{s['base']}] {state} size {s['size']} " + f"stores {s['stores']} header {header} fallback {s['fallback_slot']}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) -- cgit v1.2.3 From 7cbb0d006faf8a9b54fa9e2e116e539a01bc5bbd Mon Sep 17 00:00:00 2001 From: mrp1no <137657338+mrp1no@users.noreply.github.com> Date: Sun, 22 Nov 2026 20:39:14 +0100 Subject: docs: the console allocator's slots past 8 can't be measured from the package D3D-360. Read statically on a 1.0.2.1 package whose 16 images all match game/xbox-1.0.2.1.json: none of them is d3d12_xs.dll, which owns the allocator's vtable. None contains IID_ID3D12CommandAllocator, and no export takes an allocator: the BVH builder's take a device or a command list, and the two FidelityFX DLLs export the five ffx* entry points. No shipped module creates, receives or calls an allocator, so only the game executable could show a call past slot 8, and the proxy keeps logging and refusing those. Co-Authored-By: Claude Opus 5.5 --- docs/d3d12_command_objects.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'docs/d3d12_command_objects.md') diff --git a/docs/d3d12_command_objects.md b/docs/d3d12_command_objects.md index 56e1fd5cd..c8b3911be 100644 --- a/docs/d3d12_command_objects.md +++ b/docs/d3d12_command_objects.md @@ -615,7 +615,12 @@ Command allocators get the same kind of proxy: device slot 9 (`CreateCommandAllo - **What is forwarded.** The public chain, 9 slots: the base chain and `Reset` at 8. A slot past it, up to the end of a 64-slot table, is logged and refused, and a read past the table faults in its own guard region. - The console allocator's extra methods are not measured. + The console allocator's extra methods cannot be measured from the package (D3D-360). The 16 images in + `game/xbox-1.0.2.1.json` don't include `d3d12_xs.dll`, which owns the allocator's vtable. None of them contains + `IID_ID3D12CommandAllocator`, and no export takes an allocator: the BVH builder's take an `ID3D12Device11` or + an `ID3D12GraphicsCommandList4`/`6`/`8`, and the FSR loader and upscaler export only the five `ffx*` entry points. + So no shipped module creates, receives or calls an allocator (§3.5). Only the game executable, which the package + doesn't contain, could show a call past slot 8. Until it does, a slot past 8 stays logged and refused. - **Where a list takes it.** A list takes an allocator from the title in `CreateCommandList` and `Reset`, so the proxy is safe only where the list side resolves it. Slot 9 therefore wraps an allocator only when it answers `kLeonidaCommandAllocatorTag` (`d3d12_xs_device.h`). That is the Vulkan layer's own allocator, whose -- cgit v1.2.3 From 781b0763a0f7a8a4f1be1310435c59f0267ecbee Mon Sep 17 00:00:00 2001 From: mrp1no <137657338+mrp1no@users.noreply.github.com> Date: Sun, 22 Nov 2026 21:05:23 +0100 Subject: docs: the allocator note says how the exports were read, and points to §3.5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From the review on #3192: the FSR DLLs' exports are named and the tool that listed them (dumpbin /exports) is given, so the measurement can be repeated, and what §3.5 already says is a pointer instead of a repeat. Co-Authored-By: Claude Opus 5.5 --- docs/d3d12_command_objects.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'docs/d3d12_command_objects.md') diff --git a/docs/d3d12_command_objects.md b/docs/d3d12_command_objects.md index c8b3911be..6a6a27ea2 100644 --- a/docs/d3d12_command_objects.md +++ b/docs/d3d12_command_objects.md @@ -615,12 +615,12 @@ Command allocators get the same kind of proxy: device slot 9 (`CreateCommandAllo - **What is forwarded.** The public chain, 9 slots: the base chain and `Reset` at 8. A slot past it, up to the end of a 64-slot table, is logged and refused, and a read past the table faults in its own guard region. - The console allocator's extra methods cannot be measured from the package (D3D-360). The 16 images in - `game/xbox-1.0.2.1.json` don't include `d3d12_xs.dll`, which owns the allocator's vtable. None of them contains - `IID_ID3D12CommandAllocator`, and no export takes an allocator: the BVH builder's take an `ID3D12Device11` or - an `ID3D12GraphicsCommandList4`/`6`/`8`, and the FSR loader and upscaler export only the five `ffx*` entry points. - So no shipped module creates, receives or calls an allocator (§3.5). Only the game executable, which the package - doesn't contain, could show a call past slot 8. Until it does, a slot past 8 stays logged and refused. + The console allocator's extra methods cannot be measured from the package (D3D-360). No shipped module creates, + receives or calls an allocator (§3.5). The package has no `d3d12_xs.dll` either, and no export of the three + D3D12 clients takes an allocator. `dumpbin /exports` (MSVC 19.52) lists the BVH builder's 12 exports, which take + an `ID3D12Device11` or a command list (`docs/d3d12_xs_surface.md`), and the FSR loader's and upscaler's + `ffxConfigure`, `ffxCreateContext`, `ffxDestroyContext`, `ffxDispatch` and `ffxQuery`. A call past slot 8 could + only show up in the game executable, which the package doesn't contain, so such a slot stays logged and refused. - **Where a list takes it.** A list takes an allocator from the title in `CreateCommandList` and `Reset`, so the proxy is safe only where the list side resolves it. Slot 9 therefore wraps an allocator only when it answers `kLeonidaCommandAllocatorTag` (`d3d12_xs_device.h`). That is the Vulkan layer's own allocator, whose -- cgit v1.2.3