int3_cause: fix load widths, high-byte regs, global writers, returns dedup, and int 29h flow (INT3-CAUSE-DECODE-AND-TRACE-FIXES) #1503

Merged
IlyassRS3 merged 1 commit from upstream-pr/1503 into main 2026-11-28 14:42:37 +00:00
IlyassRS3 commented 2026-11-25 02:27:55 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T02:27:55Z.


Claimed in the coordination issue as: INT3-CAUSE-DECODE-AND-TRACE-FIXES (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7150689690)

What and why

Fixes seven decoding, register-tracing, and global-writer bugs in tools/int3_cause.py:

  1. True memory width on LOAD_OPS (load_bits in step): step() previously passed 64 if insn.wide else 32 to memory_name(), reporting byte (0x8A, 0x1B6, 0x1BE), word (0x1B7, 0x1BF, 66 8B), and movsxd (0x63, always a 32-bit dword load) as dword/qword.
  2. 8-bit high-byte registers (ah/ch/dh/bh) without REX: adds insn_writes() and uses gpr(..., 8, insn.rex) in step() (0x88, 0x8A, 0x1B6, 0x1BE), global_writers() (0x88), and call_name() so encodings 4..7 without a REX prefix map to rax..rbx rather than rsp..rdi (while preserving spl..dil when a REX prefix is present).
  3. stores_to() and global_writers() validation + 16-bit immediate stores:
    • stores_to() now indexes 66 C7 05 <disp32> <imm16> (mov word [rip+x], imm16) in addition to 32-bit C7 05, and checks full immediate bounds within the section.
    • global_writers() now verifies that the decoded instruction at at - back is actually a RIP-relative store targeting target (op in (0x88, 0x89, 0xC6, 0xC7), base == RIP, insn.target == target, and /0 for C6/C7) instead of accepting unrelated instructions whose payload bytes match 89 05 <disp32>, and deduplicates RVAs.
  4. trace_paths() and returns() distinct argument deduplication: includes r.get("argument") in _source_key() so a function returning e.g. rcx (arg 1) on one path and rdx (arg 2) on another no longer collapses both to (None, "argument") and silently drops the second argument.
  5. falls_into() matches doomed_code() on int 29h (0xCD): treats 0xCD (__fastfail) as non-falling-through in falls_into() so trace() / trace_paths() follow the jump entering a block after int 29h instead of falling back across it.
  6. flags_setter() and read_test() gaps: skips flag-neutral push imm (0x68/0x6A), push r/m (0xFF /6), xchg eax, r (0x91..0x97), mov moffs (0xA0..0xA3), and bswap (0x1C8..0x1CF) in flags_setter(); accepts 0xF6/0xF7 /1 (matching gdk_runtime_calls.decode) and reads unsigned raw[-1] for bt r/m, imm8 (0x1BA /4) in read_test().
  7. Uppercase 0X addresses and large-image index packing: accepts 0X in parse_address() and avoids array("Q") overflow when 2 * _shift - 2 > 64 (size_of_image >= 2^31).

Tested

  • python3 -I tests/test_int3_cause.py: 22/22 OK (7 new regression tests in Int3CauseEdgeFixesTest).
  • Mutation check against unpatched main (3ff2a2adc): all 7/7 new tests in Int3CauseEdgeFixesTest fail (failures=11, errors=3).
  • python3 -I tests/test_gdk_runtime_calls.py: 23/23 OK.
  • python3 -I tests/test_text_write_line_endings.py: 3/3 OK.
  • python3 -I scripts/check_no_game_data.py tools/int3_cause.py tests/test_int3_cause.py: clean.
  • python3 -m compileall -q tools/int3_cause.py tests/test_int3_cause.py: clean.

GPUs tested: n/a (CPU/PE static analysis tool only)

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. (n/a — no translator rule changed)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5483978878 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1503). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T02:27:55Z. --- Claimed in the coordination issue as: INT3-CAUSE-DECODE-AND-TRACE-FIXES (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7150689690) ### What and why Fixes seven decoding, register-tracing, and global-writer bugs in `tools/int3_cause.py`: 1. **True memory width on `LOAD_OPS` (`load_bits` in `step`)**: `step()` previously passed `64 if insn.wide else 32` to `memory_name()`, reporting `byte` (`0x8A`, `0x1B6`, `0x1BE`), `word` (`0x1B7`, `0x1BF`, `66 8B`), and `movsxd` (`0x63`, always a 32-bit `dword` load) as `dword`/`qword`. 2. **8-bit high-byte registers (`ah`/`ch`/`dh`/`bh`) without REX**: adds `insn_writes()` and uses `gpr(..., 8, insn.rex)` in `step()` (`0x88`, `0x8A`, `0x1B6`, `0x1BE`), `global_writers()` (`0x88`), and `call_name()` so encodings `4..7` without a REX prefix map to `rax..rbx` rather than `rsp..rdi` (while preserving `spl..dil` when a REX prefix is present). 3. **`stores_to()` and `global_writers()` validation + 16-bit immediate stores**: - `stores_to()` now indexes `66 C7 05 <disp32> <imm16>` (`mov word [rip+x], imm16`) in addition to 32-bit `C7 05`, and checks full immediate bounds within the section. - `global_writers()` now verifies that the decoded instruction at `at - back` is actually a RIP-relative store targeting `target` (`op in (0x88, 0x89, 0xC6, 0xC7)`, `base == RIP`, `insn.target == target`, and `/0` for `C6`/`C7`) instead of accepting unrelated instructions whose payload bytes match `89 05 <disp32>`, and deduplicates RVAs. 4. **`trace_paths()` and `returns()` distinct argument deduplication**: includes `r.get("argument")` in `_source_key()` so a function returning e.g. `rcx` (arg 1) on one path and `rdx` (arg 2) on another no longer collapses both to `(None, "argument")` and silently drops the second argument. 5. **`falls_into()` matches `doomed_code()` on `int 29h` (`0xCD`)**: treats `0xCD` (`__fastfail`) as non-falling-through in `falls_into()` so `trace()` / `trace_paths()` follow the jump entering a block after `int 29h` instead of falling back across it. 6. **`flags_setter()` and `read_test()` gaps**: skips flag-neutral `push imm` (`0x68`/`0x6A`), `push r/m` (`0xFF /6`), `xchg eax, r` (`0x91..0x97`), `mov moffs` (`0xA0..0xA3`), and `bswap` (`0x1C8..0x1CF`) in `flags_setter()`; accepts `0xF6`/`0xF7 /1` (matching `gdk_runtime_calls.decode`) and reads unsigned `raw[-1]` for `bt r/m, imm8` (`0x1BA /4`) in `read_test()`. 7. **Uppercase `0X` addresses and large-image index packing**: accepts `0X` in `parse_address()` and avoids `array("Q")` overflow when `2 * _shift - 2 > 64` (`size_of_image >= 2^31`). ### Tested - `python3 -I tests/test_int3_cause.py`: 22/22 OK (7 new regression tests in `Int3CauseEdgeFixesTest`). - Mutation check against unpatched `main` (`3ff2a2adc`): all 7/7 new tests in `Int3CauseEdgeFixesTest` fail (`failures=11, errors=3`). - `python3 -I tests/test_gdk_runtime_calls.py`: 23/23 OK. - `python3 -I tests/test_text_write_line_endings.py`: 3/3 OK. - `python3 -I scripts/check_no_game_data.py tools/int3_cause.py tests/test_int3_cause.py`: clean. - `python3 -m compileall -q tools/int3_cause.py tests/test_int3_cause.py`: clean. GPUs tested: n/a (CPU/PE static analysis tool only) 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. (n/a — no translator rule changed)
copilot-pull-request-reviewer[bot] commented 2026-11-25 02:28:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T02:28:12Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6050835785 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1503#pullrequestreview-6050835785). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T02:28:12Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
ytsodacan commented 2026-11-25 03:36:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ytsodacan on 2026-11-25T03:36:20Z.


[KEEP]

  • No CI checks have run on fix/int3-cause-decode-and-trace (gh pr checks reports none; mergeStateStatus is UNSTABLE), so the author-reported test results are unverified.
  • The PR bundles seven separate fixes in tools/int3_cause.py (load widths, high-byte registers, global writers, returns dedup, int 29h flow, flags setter, address/index packing), which conflicts with the "one topic" checklist item; splitting would make each easier to review and bisect.
  • The changes look plausible and come with 7 new regression tests in tests/test_int3_cause.py plus a mutation check against main; no overlapping open PR touches int3_cause.
  • Needs: CI run and green, and a maintainer call on whether to accept the bundle or request a split.
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7152070584 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1503#issuecomment-7152070584). Originally posted by [ytsodacan](https://github.com/ytsodacan) on 2026-11-25T03:36:20Z. --- **[KEEP]** - No CI checks have run on `fix/int3-cause-decode-and-trace` (`gh pr checks` reports none; mergeStateStatus is UNSTABLE), so the author-reported test results are unverified. - The PR bundles seven separate fixes in `tools/int3_cause.py` (load widths, high-byte registers, global writers, returns dedup, `int 29h` flow, flags setter, address/index packing), which conflicts with the "one topic" checklist item; splitting would make each easier to review and bisect. - The changes look plausible and come with 7 new regression tests in `tests/test_int3_cause.py` plus a mutation check against `main`; no overlapping open PR touches `int3_cause`. - Needs: CI run and green, and a maintainer call on whether to accept the bundle or request a split.
whoalin1 commented 2026-11-25 07:34:48 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by whoalin1 on 2026-11-25T07:34:48Z.


Independent verification (CPU/tools-only, native Windows, Python 3.11.9 — stdlib-only tools so representative): diff reviewed line-by-line, all claimed fixes present and covered by the new tests; neighboring suites green. Details in the verification batch log. AI-assisted verification.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7156019421 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1503#issuecomment-7156019421). Originally posted by [whoalin1](https://github.com/whoalin1) on 2026-11-25T07:34:48Z. --- Independent verification (CPU/tools-only, native Windows, Python 3.11.9 — stdlib-only tools so representative): diff reviewed line-by-line, all claimed fixes present and covered by the new tests; neighboring suites green. Details in the verification batch log. AI-assisted verification.
MoonEyes commented 2026-11-28 14:42:34 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T14:42:34Z.


Red/green: pytest tests/test_int3_cause.py fails on main (14 failed, 16 passed, 1 subtests passed) and passes on head 0148a635c1 merged with main (22 passed, 9 subtests passed).
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7240871959 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1503#issuecomment-7240871959). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T14:42:34Z. --- Red/green: `pytest tests/test_int3_cause.py` fails on main (14 failed, 16 passed, 1 subtests passed) and passes on head 0148a635c103 merged with main (22 passed, 9 subtests passed). Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure. 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!1503
No description provided.