tooling: report unreadable images in xmem_attribute_scan without a traceback #657

Merged
louisdibiasi merged 1 commit from upstream-pr/663 into main 2026-11-22 18:46:33 +00:00
louisdibiasi commented 2026-11-22 18:29:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by louisdibiasi on 2026-11-22T18:29:43Z.


Change

tools/xmem_attribute_scan.py reads the image with pefile and rejects non-x64 images, but main() did not catch the resulting errors. A non-PE file, an empty file, a missing file and an x86 image each ended in a traceback with exit status 1. Status 1 is also what --fail-on-null and --fail-on-unresolved return when a gate trips, so an unreadable input looked like a gate result. This reports OSError, ValueError and PEFormatError as <image>: <message> and exits with status 2, leaving 1 for the gates.

Independent problem, no linked issue.

Verification

Commit under test: 74da052 on 719552e, Windows 11, Python 3.12.10, pefile 2024.8.26.

python -B tools/xmem_attribute_scan.py <image> --fail-on-null, base vs this branch:

Image Base This branch
176 bytes of text pefile.PEFormatError: 'DOS Header magic not found.' traceback, exit 1 <path>: 'DOS Header magic not found.', exit 2
empty file PEFormatError: 'The file is empty', exit 1 one-line message, exit 2
missing path FileNotFoundError, exit 1 one-line message, exit 2
C:\Windows\SysWOW64\kernel32.dll (x86, --fail-on-unresolved) ValueError: Expected an x64 image, exit 1 ...kernel32.dll: Expected an x64 image, exit 2

New check_unreadable_image_is_not_a_gate_result in tests/xmem_attribute_scan_check.py runs the first three inputs with both gate flags and requires exit 2, the file name in stderr and no traceback; it runs in the no-argument CI invocation. The x86 row is a manual check; I have no portable x86 fixture.

  • Base: python -B tests/xmem_attribute_scan_check.py fails (traceback from the non-PE case).
  • This branch: decoding: 13 cases passed, exit 0.
  • With the source-built fixtures from my dev build, python -B tests/xmem_attribute_scan_check.py cpu_xmem_attributes.dll cpu_xmem_delay.dll still reports fixture: 23 sites, summary and exit codes passed and delay-load fixture: 1 site and exit codes passed, so the gate statuses (0, 1, 1) are unchanged.

Evidence and follow-up

Synthetic bytes only. I chose status 2 rather than the usual 1 for tool errors so it does not collide with the documented gates; happy to change it.

Checklist

  • One reviewable behavior.
  • Exact commands and results above.
  • Negative control: the new check fails on base.
  • No README/docs change needed.
  • No game files, dumps, links or secrets.

AI-assisted: I used Claude to find the bug and draft the change. I ran the reproductions and tests above myself.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6546091714 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/663). Originally posted by [louisdibiasi](https://github.com/louisdibiasi) on 2026-11-22T18:29:43Z. --- ## Change `tools/xmem_attribute_scan.py` reads the image with pefile and rejects non-x64 images, but `main()` did not catch the resulting errors. A non-PE file, an empty file, a missing file and an x86 image each ended in a traceback with exit status 1. Status 1 is also what `--fail-on-null` and `--fail-on-unresolved` return when a gate trips, so an unreadable input looked like a gate result. This reports `OSError`, `ValueError` and `PEFormatError` as `<image>: <message>` and exits with status 2, leaving 1 for the gates. Independent problem, no linked issue. ## Verification Commit under test: 74da052 on 719552e, Windows 11, Python 3.12.10, pefile 2024.8.26. `python -B tools/xmem_attribute_scan.py <image> --fail-on-null`, base vs this branch: | Image | Base | This branch | |---|---|---| | 176 bytes of text | `pefile.PEFormatError: 'DOS Header magic not found.'` traceback, exit 1 | `<path>: 'DOS Header magic not found.'`, exit 2 | | empty file | `PEFormatError: 'The file is empty'`, exit 1 | one-line message, exit 2 | | missing path | `FileNotFoundError`, exit 1 | one-line message, exit 2 | | `C:\Windows\SysWOW64\kernel32.dll` (x86, `--fail-on-unresolved`) | `ValueError: Expected an x64 image`, exit 1 | `...kernel32.dll: Expected an x64 image`, exit 2 | New `check_unreadable_image_is_not_a_gate_result` in `tests/xmem_attribute_scan_check.py` runs the first three inputs with both gate flags and requires exit 2, the file name in stderr and no traceback; it runs in the no-argument CI invocation. The x86 row is a manual check; I have no portable x86 fixture. - Base: `python -B tests/xmem_attribute_scan_check.py` fails (traceback from the non-PE case). - This branch: `decoding: 13 cases passed`, exit 0. - With the source-built fixtures from my dev build, `python -B tests/xmem_attribute_scan_check.py cpu_xmem_attributes.dll cpu_xmem_delay.dll` still reports `fixture: 23 sites, summary and exit codes passed` and `delay-load fixture: 1 site and exit codes passed`, so the gate statuses (0, 1, 1) are unchanged. ## Evidence and follow-up Synthetic bytes only. I chose status 2 rather than the usual 1 for tool errors so it does not collide with the documented gates; happy to change it. ## Checklist - [x] One reviewable behavior. - [x] Exact commands and results above. - [x] Negative control: the new check fails on base. - [x] No README/docs change needed. - [x] No game files, dumps, links or secrets. AI-assisted: I used Claude to find the bug and draft the change. I ran the reproductions and tests above myself.
upstream-sync closed this pull request 2026-11-24 06:44:13 +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!657
No description provided.