pe: map mutated images in child processes and require named results #180

Merged
raulmoracode merged 1 commit from upstream-pr/181 into main 2026-11-21 18:11:50 +00:00
raulmoracode commented 2026-11-21 18:04:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by raulmoracode on 2026-11-21T18:04:57Z.


Change

Adds cpu_native_mutation, which maps mutated copies of the source-built PE fixtures in child processes and requires a named result.

tests/cpu/native_map_check.py patches specific fields by hand. This test instead applies a fixed list of single-field edits to the header, the first section header, the export, import and base-relocation directories, plus three truncations. Each case runs in its own process, so an access violation or a hang is reported by the parent as a failed case instead of ending the suite.

A case is accepted when the child exits normally and prints either MAP_OK or one of the named MapStatus values with a non-empty detail. The parent fails on a crash, a timeout, an unknown status, or a status that disagrees with the returned base. The control case applies no edit and must map.

Fixes #180

Verification

Commit 023f857 on Windows 10 22H2 build 19045.6466, VS Build Tools 2022 17.14, MSVC 14.44.35207, Windows SDK 10.0.26100, CMake 4.4.4, Python 3.12.10.

cmake --preset dev
cmake --build --preset dev
ctest --preset dev --no-tests=error -R '^cpu_native_mutation$' -V

Result:

73: 2 fixtures survived; outcomes: format=26, ok=16, relocation=4
1/1 Test #73: cpu_native_mutation ..............   Passed    5.66 sec

46 cases across cpu_register_probe and cpu_import_original: no crash, no timeout, and every rejection carried a detail string.

Negative control for the harness itself: with the mapper replaced by a three-line DLL whose pe_map_image dereferences null, the parent reports

AssertionError: cpu_register_probe.dll: control: child exited 0xc0000005

and exits non-zero. The harness therefore detects the failure mode it exists for.

Evidence and follow-up

The edits are computed with pefile from the built fixtures: DOS_HEADER, FILE_HEADER, OPTIONAL_HEADER, the first section header, and data directories 0, 1 and 5. No random input and no corpus.

This covers the map and release path. It does not call pe_map_export, so the export-lookup crash class in #163 is not exercised here; that becomes possible once #167 merges, and the child can then resolve an export before releasing.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6532508895 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/181). Originally posted by [raulmoracode](https://github.com/raulmoracode) on 2026-11-21T18:04:57Z. --- ## Change Adds `cpu_native_mutation`, which maps mutated copies of the source-built PE fixtures in child processes and requires a named result. `tests/cpu/native_map_check.py` patches specific fields by hand. This test instead applies a fixed list of single-field edits to the header, the first section header, the export, import and base-relocation directories, plus three truncations. Each case runs in its own process, so an access violation or a hang is reported by the parent as a failed case instead of ending the suite. A case is accepted when the child exits normally and prints either `MAP_OK` or one of the named `MapStatus` values with a non-empty detail. The parent fails on a crash, a timeout, an unknown status, or a status that disagrees with the returned base. The control case applies no edit and must map. Fixes #180 ## Verification Commit `023f857` on Windows 10 22H2 build 19045.6466, VS Build Tools 2022 17.14, MSVC 14.44.35207, Windows SDK 10.0.26100, CMake 4.4.4, Python 3.12.10. ```powershell cmake --preset dev cmake --build --preset dev ctest --preset dev --no-tests=error -R '^cpu_native_mutation$' -V ``` Result: ```text 73: 2 fixtures survived; outcomes: format=26, ok=16, relocation=4 1/1 Test #73: cpu_native_mutation .............. Passed 5.66 sec ``` 46 cases across `cpu_register_probe` and `cpu_import_original`: no crash, no timeout, and every rejection carried a detail string. Negative control for the harness itself: with the mapper replaced by a three-line DLL whose `pe_map_image` dereferences null, the parent reports ```text AssertionError: cpu_register_probe.dll: control: child exited 0xc0000005 ``` and exits non-zero. The harness therefore detects the failure mode it exists for. ## Evidence and follow-up The edits are computed with `pefile` from the built fixtures: `DOS_HEADER`, `FILE_HEADER`, `OPTIONAL_HEADER`, the first section header, and data directories 0, 1 and 5. No random input and no corpus. This covers the map and release path. It does not call `pe_map_export`, so the export-lookup crash class in #163 is not exercised here; that becomes possible once #167 merges, and the child can then resolve an export before releasing. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. _AI-assisted._
upstream-sync closed this pull request 2026-11-24 06:41:42 +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!180
No description provided.