tooling: keep the entry register when resolving xmem attribute callers #755

Merged
FZNull merged 1 commit from upstream-pr/761 into main 2026-11-23 01:40:46 +00:00
FZNull commented 2026-11-23 01:22:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by FZNull on 2026-11-23T01:22:22Z.


Problem

tools/xmem_attribute_scan.py reports where the attribute word in RDX comes from. When Scan.walk() follows a register copy such as mov rdx, r8 back to a function entry, Scan.block_start() returned an "argument" node without recording which register reached the entry, and Scan.finish() resolved the direct callers with the default RDX. A pass-through that receives the word in R8 therefore reported the caller's RDX instead of its R8.

Reproduction with the source-built fixture patched so call_clobber sets EDX = 0x05e50000 and R8D = 0xa8004000 and computed_word runs mov rdx, r8; jmp [__imp_XMemAlloc]:

{'source': 'argument', 'function': '0x10bf', 'exported': True, 'callers': [{'source': 'constant',
 'word': 98893824, 'word_hex': '0x5e50000',
 'desktop': 'heap: aligned allocation, 32-byte alignment', ...}], 'via': '0x10bf'}

Expected 0xa8004000; observed 0x5e50000.

Change

  • Scan.walk() passes the tracked register to Scan.block_start(), which records it on the "argument" node ("register": "R8").
  • truncate() marks an "argument" node "truncated": true when a 32-bit copy led to the entry (it already masked constants).
  • Scan.finish() resolves each caller with the recorded entry register instead of the default RDX, and applies the 32-bit truncation to the resolved caller word.
  • tests/cpu/xmem_attributes.asm gains two exports: caller_copy (caller sets EDX=0x5e50000, R8D=0xa8004000; callee mov rdx, r8) and caller_copy_low (caller sets R8=0x1a8004000; callee mov edx, r8d). tests/xmem_attribute_scan_check.py requires both to resolve 0xa8004000 from R8, checks the truncation flag, and the summary counts 25 sites.
  • docs/experiments.md records the entry-register rule and the two new forms.

Verification

Environment: Windows 11, Python 3.13.12 (out/pe-env: pefile 2024.8.26, iced-x86 1.21.0), MSVC 19.50.35726, Windows SDK 10.0.26100.0, CMake 4.5.1 + Ninja.

cmake --preset dev -B out/build/wt747 -DINTAKE_PYTHON=<repo>/out/pe-env/Scripts/python.exe
cmake --build out/build/wt747 --parallel 6
ctest --test-dir out/build/wt747 --no-tests=error -R 'xmem_attribute' -V

Results: configure exit 0; build [1355/1355] exit 0; 1/1 Test #122: xmem_attribute_scan ... Passed with decoding: 13 cases passed, fixture: 25 sites, summary and exit codes passed, delay-load fixture: 1 site and exit codes passed. ctest -R 'xmem' is 5/5.

With the fix the reproduction resolves:

{'source': 'argument', 'function': '0x10bf', 'register': 'R8', 'exported': True, 'callers':
 [{'source': 'constant', 'word': 2818588672, 'word_hex': '0xa8004000',
   'desktop': 'graphics: VirtualAlloc on an allocation-granularity boundary', ...}], 'via': '0x10bf'}

Negative controls, run with mutant copies of the scanner: resolving callers with the default RDX fails the check with 0x5e50000; dropping the 32-bit truncation fails it with 0x1a8004000 (memory type 13, null).

No game files, dumps or distribution links are used; the fixture is source-built MASM.

Fixes #747

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6550341909 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/761). Originally posted by [FZNull](https://github.com/FZNull) on 2026-11-23T01:22:22Z. --- ## Problem `tools/xmem_attribute_scan.py` reports where the attribute word in `RDX` comes from. When `Scan.walk()` follows a register copy such as `mov rdx, r8` back to a function entry, `Scan.block_start()` returned an `"argument"` node without recording which register reached the entry, and `Scan.finish()` resolved the direct callers with the default `RDX`. A pass-through that receives the word in `R8` therefore reported the caller's `RDX` instead of its `R8`. Reproduction with the source-built fixture patched so `call_clobber` sets `EDX = 0x05e50000` and `R8D = 0xa8004000` and `computed_word` runs `mov rdx, r8; jmp [__imp_XMemAlloc]`: ```text {'source': 'argument', 'function': '0x10bf', 'exported': True, 'callers': [{'source': 'constant', 'word': 98893824, 'word_hex': '0x5e50000', 'desktop': 'heap: aligned allocation, 32-byte alignment', ...}], 'via': '0x10bf'} ``` Expected `0xa8004000`; observed `0x5e50000`. ## Change - `Scan.walk()` passes the tracked register to `Scan.block_start()`, which records it on the `"argument"` node (`"register": "R8"`). - `truncate()` marks an `"argument"` node `"truncated": true` when a 32-bit copy led to the entry (it already masked constants). - `Scan.finish()` resolves each caller with the recorded entry register instead of the default `RDX`, and applies the 32-bit truncation to the resolved caller word. - `tests/cpu/xmem_attributes.asm` gains two exports: `caller_copy` (caller sets `EDX=0x5e50000`, `R8D=0xa8004000`; callee `mov rdx, r8`) and `caller_copy_low` (caller sets `R8=0x1a8004000`; callee `mov edx, r8d`). `tests/xmem_attribute_scan_check.py` requires both to resolve `0xa8004000` from `R8`, checks the truncation flag, and the summary counts 25 sites. - `docs/experiments.md` records the entry-register rule and the two new forms. ## Verification Environment: Windows 11, Python 3.13.12 (`out/pe-env`: pefile 2024.8.26, iced-x86 1.21.0), MSVC 19.50.35726, Windows SDK 10.0.26100.0, CMake 4.5.1 + Ninja. ```powershell cmake --preset dev -B out/build/wt747 -DINTAKE_PYTHON=<repo>/out/pe-env/Scripts/python.exe cmake --build out/build/wt747 --parallel 6 ctest --test-dir out/build/wt747 --no-tests=error -R 'xmem_attribute' -V ``` Results: configure exit 0; build `[1355/1355]` exit 0; `1/1 Test #122: xmem_attribute_scan ... Passed` with `decoding: 13 cases passed`, `fixture: 25 sites, summary and exit codes passed`, `delay-load fixture: 1 site and exit codes passed`. `ctest -R 'xmem'` is 5/5. With the fix the reproduction resolves: ```text {'source': 'argument', 'function': '0x10bf', 'register': 'R8', 'exported': True, 'callers': [{'source': 'constant', 'word': 2818588672, 'word_hex': '0xa8004000', 'desktop': 'graphics: VirtualAlloc on an allocation-granularity boundary', ...}], 'via': '0x10bf'} ``` Negative controls, run with mutant copies of the scanner: resolving callers with the default `RDX` fails the check with `0x5e50000`; dropping the 32-bit truncation fails it with `0x1a8004000` (memory type 13, null). No game files, dumps or distribution links are used; the fixture is source-built MASM. Fixes #747
upstream-sync closed this pull request 2026-11-24 06:44:40 +00:00
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
R0Y00/Xbox2Windows!755
No description provided.