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

Manually merged
github merged 1 commit from gh-pr/181/head into gh-pr/181/base 2026-11-26 21:32:35 +00:00
Owner

@⁠raulmoracode on GitHub · 2026-11-21 18:04 UTC · original
raulmoracode:pe/mutation-harness → main · +183 −0 · 3 files · 1 commits · merged 2026-11-21 18:11 UTC

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.

**@⁠raulmoracode** on GitHub · 2026-11-21 18:04 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/181) `raulmoracode:pe/mutation-harness` → `main` · +183 −0 · 3 files · 1 commits · merged 2026-11-21 18:11 UTC ## 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._
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:32:33 +00:00
github manually merged commit bd788c017a into gh-pr/181/base 2026-11-26 21:32:35 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.