pe: support width-checked HIGHLOW base relocations #601

Merged
Joacoorandom merged 1 commit from upstream-pr/607 into main 2026-11-22 18:06:45 +00:00
Joacoorandom commented 2026-11-22 15:34:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Joacoorandom on 2026-11-22T15:34:44Z.


Change

The PE mapper rejects IMAGE_REL_BASED_HIGHLOW entries even when Windows accepts them in a source-built AMD64 DLL. Support their four-byte, modulo-2^32 adjustment alongside existing eight-byte DIR64 relocations.

Validate each relocation using its actual width, preserve adjacent bytes, and use memcpy for unaligned fields. Header targets, relocation-directory overlaps, truncated fields and unsupported types remain rejected. Import and delay-import write checks keep their eight-byte default.

This is an independent change to tools/pe_map.cpp; no other PR is required.

Verification

Commit: 8f4e6a3088.

Windows 11 build 26300.9974, MSVC 19.44.35230, Python 3.12.8. Built the mapper and existing fixture dependencies in Debug and Release (/O2), then ran:

ctest --test-dir out/native --no-tests=error -R "^cpu_native_(highlow|map|mutation|reloc_free)$" --output-on-failure
ctest --test-dir out/release --no-tests=error -R "^cpu_native_(highlow|map|mutation|reloc_free)$" --output-on-failure

Both configurations: 4/4 tests passed. The new test covers seven Windows/mapper comparisons and five rejection controls, including carry, unaligned fields, mixed DIR64/HIGHLOW entries and end-of-image boundaries. Values are checked against independently calculated relocation results, with neighboring-byte checks.

Repository checks on Linux:

python3 tests/docs_links_check.py
python3 tests/bidi_controls_check.py
python3 -m py_compile tests/cpu/highlow_check.py
git diff --cached --check

Passed: 10 Markdown files / 123 links; 558 tracked files checked for bidi controls; Python compilation and staged whitespace checks. The full test suite was not run.

Evidence and follow-up

The new fixture derives from the repository's MIT-licensed, source-built reloc_route.asm DLL. It changes relocation metadata and controlled data fields; Windows loads it with DONT_RESOLVE_DLL_REFERENCES, and the test does not execute the patched guest body. No external binary or implementation was copied.

Semantics reference: Microsoft PE base relocation types.

The experiment documentation records the scope, rejection controls and reproduction commands; README adds the focused test entry. This verifies mapper behavior on public fixtures and does not establish title startup.

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 implementation, documentation and test development.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6544245442 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/607). Originally posted by [Joacoorandom](https://github.com/Joacoorandom) on 2026-11-22T15:34:44Z. --- ## Change The PE mapper rejects IMAGE_REL_BASED_HIGHLOW entries even when Windows accepts them in a source-built AMD64 DLL. Support their four-byte, modulo-2^32 adjustment alongside existing eight-byte DIR64 relocations. Validate each relocation using its actual width, preserve adjacent bytes, and use memcpy for unaligned fields. Header targets, relocation-directory overlaps, truncated fields and unsupported types remain rejected. Import and delay-import write checks keep their eight-byte default. This is an independent change to tools/pe_map.cpp; no other PR is required. ## Verification Commit: 8f4e6a30886d03e64657706b717dd1ea79177148. Windows 11 build 26300.9974, MSVC 19.44.35230, Python 3.12.8. Built the mapper and existing fixture dependencies in Debug and Release (/O2), then ran: ```text ctest --test-dir out/native --no-tests=error -R "^cpu_native_(highlow|map|mutation|reloc_free)$" --output-on-failure ctest --test-dir out/release --no-tests=error -R "^cpu_native_(highlow|map|mutation|reloc_free)$" --output-on-failure ``` Both configurations: 4/4 tests passed. The new test covers seven Windows/mapper comparisons and five rejection controls, including carry, unaligned fields, mixed DIR64/HIGHLOW entries and end-of-image boundaries. Values are checked against independently calculated relocation results, with neighboring-byte checks. Repository checks on Linux: ```text python3 tests/docs_links_check.py python3 tests/bidi_controls_check.py python3 -m py_compile tests/cpu/highlow_check.py git diff --cached --check ``` Passed: 10 Markdown files / 123 links; 558 tracked files checked for bidi controls; Python compilation and staged whitespace checks. The full test suite was not run. ## Evidence and follow-up The new fixture derives from the repository's MIT-licensed, source-built reloc_route.asm DLL. It changes relocation metadata and controlled data fields; Windows loads it with DONT_RESOLVE_DLL_REFERENCES, and the test does not execute the patched guest body. No external binary or implementation was copied. Semantics reference: [Microsoft PE base relocation types](https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#base-relocation-types). The [experiment documentation](https://github.com/Joacoorandom/Xbox2Windows/blob/8f4e6a30886d03e64657706b717dd1ea79177148/docs/experiments.md#highlow-and-mixed-width-base-relocations) records the scope, rejection controls and reproduction commands; README adds the focused test entry. This verifies mapper behavior on public fixtures and does not establish title startup. ## 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 implementation, documentation and test development.
upstream-sync closed this pull request 2026-11-24 06:43:55 +00:00
legacy-code-archaeologist commented 2026-11-24 06:48:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-22T17:12:34Z.


Verification of 8f4e6a3 on Windows 11 build 26100.9168 (x64, Intel Skylake), MSVC 19.52.37029, dev preset (Debug). It merges cleanly with main (git merge-tree).

ctest --preset dev --no-tests=error -R "^cpu_native_|pe_|static_exe_intake|conditional_import|bundled_export" -j 4
100% tests passed, 0 tests failed out of 29
cpu_native_highlow:
7 Windows/pe_map relocation comparisons passed: aligned, unaligned, carry, mixed widths and exact boundaries
5 malformed/unsupported relocation controls rejected; adjacent bytes unchanged; no guest code called

The Windows-side comparisons therefore also hold on 26100, alongside your 26300.9974 run.

I also checked that the fixture detects the four ways this change could go wrong. For each mutation I changed one detail in tools/pe_map.cpp, rebuilt pe_map and ran cpu_native_highlow. Afterwards I restored the file, verified its hash, and confirmed the test passed again.

Mutation in tools/pe_map.cpp cpu_native_highlow
HIGHLOW applied as a 64-bit add (carry into the next four bytes) fails (detected)
HIGHLOW validated with an 8-byte width fails (detected)
relocation-directory overlap check ignores width (always 8) fails (detected)
HIGHLOW still rejected (width 0) fails (detected)

AI-assisted: run and summarized with Claude Code; outputs copied from the local runs.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7082661725 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/607#issuecomment-7082661725). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-22T17:12:34Z. --- Verification of `8f4e6a3` on Windows 11 build 26100.9168 (x64, Intel Skylake), MSVC 19.52.37029, `dev` preset (Debug). It merges cleanly with `main` (`git merge-tree`). ```text ctest --preset dev --no-tests=error -R "^cpu_native_|pe_|static_exe_intake|conditional_import|bundled_export" -j 4 100% tests passed, 0 tests failed out of 29 cpu_native_highlow: 7 Windows/pe_map relocation comparisons passed: aligned, unaligned, carry, mixed widths and exact boundaries 5 malformed/unsupported relocation controls rejected; adjacent bytes unchanged; no guest code called ``` The Windows-side comparisons therefore also hold on 26100, alongside your 26300.9974 run. I also checked that the fixture detects the four ways this change could go wrong. For each mutation I changed one detail in `tools/pe_map.cpp`, rebuilt `pe_map` and ran `cpu_native_highlow`. Afterwards I restored the file, verified its hash, and confirmed the test passed again. | Mutation in `tools/pe_map.cpp` | `cpu_native_highlow` | |---|---| | HIGHLOW applied as a 64-bit add (carry into the next four bytes) | fails (detected) | | HIGHLOW validated with an 8-byte width | fails (detected) | | relocation-directory overlap check ignores `width` (always 8) | fails (detected) | | HIGHLOW still rejected (width 0) | fails (detected) | AI-assisted: run and summarized with Claude Code; outputs copied from the local runs.
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!601
No description provided.