Skip to content

RT-5: int3_cause.py, the call whose result sends the retail executable to an int3, read statically - #8408

Closed
TreXito wants to merge 7 commits into
ProjectLeonida:mainfrom
TreXito:exe/int3-cause
Closed

TreXito wants to merge 7 commits into
ProjectLeonida:mainfrom
TreXito:exe/int3-cause

Conversation

@TreXito

@TreXito TreXito commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #8186 (comment)

What and why

Boot runs now report a title int3 as an address (LEONIDA_SKIP_ASSERTS, LEONIDA_SKIP_INT3, the fault log). Until now each one was disassembled by hand to find which call failed. tools/int3_cause.py <image> <address>... reads that from the file alone, with nothing run:

  1. The stop: int3, ud2 or int 29h. An address one past an int3 (Wine's breakpoint address) is taken as that int3.
  2. The doomed code: every instruction in the stop's function (.pdata bounds) from which every path reaches the stop without a return.
  3. The guards: each conditional jump with exactly one side doomed, plus rel32 jumps into it from other functions (cold chunks), confirmed by decoding their function from its start.
  4. The condition for the doomed side, from the flag-setting instruction before the guard (test, cmp, and, sub, bt, register or memory operand), for example eax < 0, al == 0, bit 5 of eax is set.
  5. The call whose result the tested register holds, followed back through register copies, lea r, [r2+disp] and added constants: an import (dll!Name), a vtable slot (with this noted when it came from a global), or a function of the image. A block after a return or jump is entered through the one jump that reaches it. When the register is one of the function's arguments, each direct call site is read for what it passes, as a tally. For a load, the pointer register is followed too. When the value comes from a global, or a field of an object a global points to, each mov [rip+x], r/imm to that global is read for what it stores.
  6. When the int3 ends a function that never returns, its direct call sites are read the same way, up to 3 functions away.

--any lets the address be any instruction, for example the xor eax, eax of a return 0 path or a fallback's first instruction. The tool then names the branches that decide whether it runs, without following callers.

--returns takes a function and lists, for each ret, every value that can reach it (a constant, a call's result, an argument, a global or a stack slot) together with the branches on that path. A setup function that returns a bool then reads as "0 when this call fails, 1 when that one succeeds", which is where a caller's int3 on the result comes from.

Call, jump and store sources come from two sorted indexes built once per image (about 3 s on the retail .text), so following callers and globals several levels deep costs a bisect per target, not a scan of the code. It reuses gdk_runtime_calls' decoder and .pdata bounds and import_call_sites.import_slots. Text by default, --json for the same structure. Exit 0 when every address is a stop it could read, 1 when one isn't, 2 for an unreadable image. Standard library only. docs/boot.md points to it from the LEONIDA_SKIP_INT3 entry.

Not seen: stops reached through a jump table or a function pointer, values passed through the stack, flags set by forms outside step 4 (the tool says so and names the instruction).

Tested

  • python -I tests/test_int3_cause.py: 15 tests OK, on a PE built byte by byte (test_import_call_sites.build_image plus a .pdata directory). They cover an import result tested far from the stop, a vtable slot result copied to another register, a cold chunk reached by jne from another function, a never-returning handler read at its caller, a check that ends in a handler for some values of its argument (read at the check's call sites), a field of a returned object, a global tested for null (read at its two stores), --any on a success path and on a function's first instruction, constants of every width, --returns on a function that returns 1 only when an import's result is not negative, the Wine +1 address, a virtual address, condition text for cmp/test/and/bt, text output and the exit codes. One more checks that the call, jump and store indexes find, for every target in the image, what a scan of every code byte finds, in the same order.
  • test_import_call_sites and test_gdk_runtime_calls still OK.
  • On the retail executable, read statically on the rig (never run): the current analyzer attributes all 16 int3 stops in one device setup function to a call: device slots 48 (4), 9 (4), 73 (2) and 79, xmem.dll!XMemVirtualAlloc, and one in-image check (4). The device-lost handler was reported as never returning and was read at its one call site, the title's shared result check. There, the guard tests a value derived from argument 1, and the tool tallied what the check's 51 call sites pass: device slots 8, 41, 48, 133, 14, 32 and others, XGCreateTextureComputer, D3D12XboxCreateDevice and D3D12SerializeVersionedRootSignature. After a one-time index build of about 3 s, well under a second per address.
  • --returns on the same device setup function (the D3D12XboxCreateDevice caller, 1 ret): it returns a constant 0 when RegisterClassExA returns 0, when CreateWindowExA returns 0, when device slot 8 or slot 41 returns a negative value (slot 41 at four sites), and on several in-image checks. It returns 1 only when slot 41 succeeds. About 0.2 s.
  • Robustness and speed on the retail executable, over every 300th function (998 functions, counts only): --returns on each and --any on its first and middle instruction finish with no errors. --returns finished on all 998, over the paths its bounded static analysis recovers. The slowest --any takes 2.1 s; before the indexes it took up to 22 s, and one run stalled for over half an hour. On the same functions, the output with the indexes is identical to the output without them: 300 --returns/--any reports and all 20 int3 stops, 337 s of scanning before against 0.1 s after.
  • Coverage on the retail executable, over every 5th function (59,852 functions, 1,630 int3 stops; counts only):
    • The guard tests a call's result directly: 498 stops.
    • It tests an argument: 39, and those are read at the callers.
    • It tests a global, or a field of an object a global points to: most of the remaining 1,061.
    • A sample of 40 of the global cases: the tool found the global's stores for all 40, and 37 of them store a named call's result.
    • Only 3 stops have flags set by a form the tool does not read. No addresses, bytes or output from the executable are in this PR.

AI-assisted: yes

Checklist

  • 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. (No translator change.)

🤖 Generated with Claude Code

…3, statically

tools/int3_cause.py <image> <address>... finds every branch that reaches the
int3 (also from other functions), reads its condition and follows the tested
register back to the import, vtable slot or function whose result it holds.
An int3 that ends a never-returning function is read at its call sites.
Synthetic PE tests; docs/boot.md points to it from LEONIDA_SKIP_INT3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@morodirule

Copy link
Copy Markdown

Tested 8a314ee on Arch Linux, Python 3.14.10, CPU only: pass — first Linux check. new test_int3_cause 8/8 + import_call_sites 8/8 + gdk_runtime_calls 23/23 OK. Negative control: tool absent at base → import error (test is load-bearing on the new tool). No game files. AI-assisted.

…lock entry by its one jump

When the register a guard tests is one of the function's arguments (nothing
wrote it since the start, through copies, lea r,[r2+disp] and added
constants), each direct call site is read for what it passes, as a tally.
A block after a return or jump is entered through the one jump reaching it.
explain() now caps links after filtering them, so the not-followed count
is right.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ScarionWorkspace

Copy link
Copy Markdown
Contributor

Tested 8630afd1e on Windows 11 Home (26200), Python 3.12, own 1.0.2.1 game_scarlett_master.exe (SHA-256 matches e95020b2…), static read only, nothing run: pass. First check against the retail executable, as far as I can see.

  • python -I tests/test_int3_cause.py: 9 tests OK.
  • Retail exe, 300 addresses from my own rough scan (a 0xCC inside a .pdata function right after a short jcc, random sample). No boot trace, so these are arbitrary guarded stops, not boot stops:
    • 245 are not instruction starts (my scan's false positives). Each is reported as "decoding from the function start does not land on it", and the run exits 1, as documented.
    • 55 are real int3 stops: 31 with one guard, 23 with two, 1 with three. Every guard gets a condition (82 of 82).
    • 10 of the 55 name a call through the tested register: 8 image functions, 2 imports, 1 vtable slot (with this from a global). The rest trace the value to a memory load (mostly [rcx] / [rcx+0x20], i.e. argument checks), a computation or a constant, and 5 say "not found" with the reason.
    • Against the previous head 8a314eed5 on the same 300 addresses: 12 results differ, 3 of them gain the new arguments section (the tested argument followed to the check's call sites).
  • No crash or traceback; 300 addresses in about 100 s.

No addresses or output from the executable here. AI-assisted (Claude Code).

TreXito and others added 3 commits November 23, 2026 18:49
…stores

A load's pointer register is traced too (two levels). When the guard's value
comes from a global, or a field of an object a global points to, each
mov [rip+x], r / mov [rip+x], imm storing to that global is read for what it
stores (a call's result, a constant). Most title asserts test such a global
rather than a call's result directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…constants keep their value

With --any the address may be any instruction: the guards are the branches
that decide whether it runs, and callers are not followed. A traced constant
now carries its value (mov r, imm in every width, xor r, r, mov r/m, imm).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
For each ret, list every value that can reach it (constant, call
result, argument, global, stack slot) together with the branches that
set it, so a bool-returning setup function reads as "0 when X fails,
1 when Y succeeds". Path walking is shared with trace() through step().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@memorypressure

Copy link
Copy Markdown

Tested b689ee5 (noting 8a314ee was superseded mid-verification) merged onto main 867d922 (tree bdf9ee275): tests/test_int3_cause.py Ran 14 OK, test_import_call_sites (helper source) Ran 8 OK, test_missing_input_exit_codes Ran 2 OK; missing image = one line + exit 2. On clean main the test file can't import (tool absent) — vacuity N/A by construction. Tests are synthetic-image only; the constants test uses a stub flow harness rather than patching the tool, which is the right call. Two nits: the missing-file line is "int3_cause.py: [Errno 2] ..." rather than the ERROR:-prefixed one-liner the BUILD-1046 family uses (the tool isn't in that suite's list yet — aligning would be cheap); CI so far is change-scope + no-game-data only. Overlap: docs/boot.md with #4227, mechanical. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@Atomic258

Copy link
Copy Markdown
Contributor

Tested b689ee5a on Windows Server 2022, CPython 3.13.12: pass

  • python -I tests/test_int3_cause.py -> OK

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

@SirKingg

Copy link
Copy Markdown
Contributor

Independent Windows / Python 3.14 check of b689ee5aa: all 14 synthetic test_int3_cause.py tests passed.

On an offline Sandbox boot with #8379, #6582 and #8461, the analyzer identified the first guest breakpoint as a negative HRESULT guard on the public GameInput.dll!#1 import. A controlled comparison with SDL3 enabled in both builds corroborated the diagnosis: without #7216 the run stopped at that breakpoint; with #7216, 2/2 runs passed it, created the D3D12 device and reached slot 26. Applied to a later breakpoint after #6964, the analyzer identified a negative HRESULT guard on device slot 48; the independently documented #8258 queue-flags change passed that stop in 2/2 runs. On the next breakpoint it identified slot 73; the runtime trace recorded a failed command-list creation.

Only outcomes and public API/slot names are shared; analysis output and traces stay local. AI-assisted.

rel32_sources and global_writers scanned every code byte on each call,
and explain calls them at every level it follows (up to six scans per
level). On a 100 MB .text that is about 2 s a scan, so a stop with many
incoming jumps took minutes. Build two sorted indexes on first use
(target, rva, kind packed in one integer) and bisect them instead.
Results are the same matches in the same address order; a new test
checks every target against a full scan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pr-sorter

Copy link
Copy Markdown

Tested 745062c on Linux (CachyOS, Python 3.14): pass

  • python3 -I tests/test_int3_cause.py: 15 tests OK. Also OK: test_import_call_sites (8), test_gdk_runtime_calls (23), test_missing_input_exit_codes (2).
  • Control for the new commit: this head's test file against the previous head b689ee5aa gives 1 error, test_the_indexes_find_what_a_full_scan_finds, because the index methods don't exist there. The other 14 pass.
  • tests/test_docs_links.py fails on a docs/dev-tools.md link, the same way without this commit. It's not from this PR's docs/boot.md change.

Review of 745062c3e (the sorted indexes): the packing is sound. _shift leaves room for any RVA plus the 2 kind bits, and entries stay under 64 bits for any image below 2 GiB. rel32_from keeps the old at + 4 > len(data) bound. rel32_sources re-sorts by (rva, kind, target), so callers see matches in the same address order as the old per-call scan. global_writers keeps the prefix back-off and the lands_on check. No defects found. I had no game data, so I didn't check the speedup or the output on a real executable.

AI-assisted (Claude Code), run by a person; tests run in a sandbox without network.

@BatSmacker84

Copy link
Copy Markdown

Checked 745062c3e (merges cleanly onto main 5d74c2723) against the retail executable on Windows 11 26200. Static reads and CPU tests only.

Pass

  • 16 setup stops, the stated categories, and a single return instruction. Return analysis recovers 0 and 1 with the named import/slot guards, including slot 41 for return 1.
  • Three CPU suites 46/46; the docs-link failures also occur on main.

Needs changes

  • The stop tally in the text is stale: the current analyzer attributes all 16 stops, two of them to slot 73. Suggested: "The current analyzer attributes 16 of 16 setup stops, including two to slot 73."
  • Describe coverage as "paths recovered by the bounded static analysis", not all paths.
  • Not checked: the 51-caller tally, sampled coverage and the before/after timings.

AI-assisted: Codex GPT-6.2 Sol ran the checks, Claude Opus 5.5 reviewed the report. The retail executable (SHA-256 e95020b2…8993) and package PE images were read in place; static reads and CPU tests only, and only names, counts and constants the PR uses are given.

…arch recovers

The search stops at a step and source limit, so "every path" overstated what it reads (review on ItsNotRexed#8408).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@BatSmacker84

Copy link
Copy Markdown

Thanks. At 32d6a2304 both of my notes are addressed: the description gives the current tally (all 16 stops attributed, two to device slot 73), and the module docstring, trace_paths and returns describe the paths the bounded search recovers instead of every path. The new commit changes only that wording, so my earlier static results at 745062c3e carry over. Still not checked by me: the 51-caller tally, sampled coverage and timings.

AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants