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

Open
opened 2026-11-26 20:21:34 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1503
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/int3-cause-decode-and-trace


📝 Commits (1)

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

📊 Changes

2 files changed (+238 additions, -31 deletions)

View changed files

📝 tests/test_int3_cause.py (+150 -0)
📝 tools/int3_cause.py (+88 -31)

📄 Description

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)

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

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1503 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/int3-cause-decode-and-trace` --- ### 📝 Commits (1) - [`0148a63`](https://github.com/ubiquitarianism/leonida/commit/0148a635c103a08131f64c2bdd5669156294bbb1) int3_cause: fix load widths, high-byte regs, global writers, returns dedup, and int 29h flow (INT3-CAUSE-DECODE-AND-TRACE-FIXES) ### 📊 Changes **2 files changed** (+238 additions, -31 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_int3_cause.py` (+150 -0) 📝 `tools/int3_cause.py` (+88 -31) </details> ### 📄 Description 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1531
No description provided.