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

Open
github-bot wants to merge 1 commit from github-bot/gh-1503 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 02:27 UTC · original
IlyassRS3:fix/int3-cause-decode-and-trace → main · +238 −31 · 2 files · 1 commits · open

Claimed in the coordination issue as: INT3-CAUSE-DECODE-AND-TRACE-FIXES (#14)

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)
**@⁠IlyassRS3** on GitHub · 2026-11-25 02:27 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1503) `IlyassRS3:fix/int3-cause-decode-and-trace` → `main` · +238 −31 · 2 files · 1 commits · open Claimed in the coordination issue as: INT3-CAUSE-DECODE-AND-TRACE-FIXES (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ### 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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:54:28 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 02:28 UTC · original · reviewed

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.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 02:28 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1503#pullrequestreview-6050835785) · **reviewed** 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.
Author
Owner

@⁠ytsodacan on GitHub · 2026-11-25 03:36 UTC · original · edited 2026-11-25 03:44 UTC

[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.
**@⁠ytsodacan** on GitHub · 2026-11-25 03:36 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1503#issuecomment-7152070584) · edited 2026-11-25 03:44 UTC **[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.
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-25 07:34 UTC · original

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.

**@⁠whoalin1** on GitHub · 2026-11-25 07:34 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1503#issuecomment-7156019421) 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1503/head:github-bot/gh-1503'
git switch 'github-bot/gh-1503'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1503'
git switch 'github-bot/gh-1503'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1503'
git switch 'github-bot/gh-1503'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1503'
git switch 'main'
git merge --squash 'github-bot/gh-1503'
git switch 'main'
git merge --ff-only 'github-bot/gh-1503'
git switch 'main'
git merge 'github-bot/gh-1503'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.