tooling: apply memory patches in exe_aot (Refs #3037) #3877
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!3877
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3875"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Ammmae0x on GitHub · 2026-12-02 16:59 UTC · original
Ammmae0x:tooling/exe-aot-memory-patches→main· +518 −13 · 8 files · 1 commits · openRefs #3037 — Stage 2: memory patches in the CPU converter.
What landed (single commit, off
origin/main8121ca99, pushed to the fork, no force-push):tools/patch_manifest.py: newapply_memory(data, patches). Every patch is validated before anything is modified: kind must bememory, each span[rva, rva + len(bytes))must lie strictly inside a single PE section (PE headers, section gaps and virtual bytes beyondSizeOfRawData/Misc_VirtualSizerefused, mapped withpefile.PE(data=bytes(data), fast_load=True)), and the SHA-256 of the original bytes at that section file slice must equalexpect_sha256(refused naming the patchid). Returns patchedbytes; the input bytes are untouched.tools/cpu_stdio_exe_aot.py:translate(..., data=None)takes optional in-memory bytes, defaulting toPath(image).read_bytes(); existing callers unchanged.tools/exe_aot.py:--patches PATHandpatches=Noneonconvert(). Reads the input once,report["sha256"]is the original bytes; with--patchesit runsload_data+apply_memorybefore the header stage and lifts from the patched copy (read_header(working),translate(..., data=working)). AnyValueError/OSError/pefile.PEFormatErrorbecomesRefusal("patches", ...)(stale artifacts cleaned, exit 1,refused at patches: ...).report.jsonrecordsmanifest_sha256andpatch_idswhen--patchesis given.tests/exe_aot_patches_check.py+tests/cmake/exe_aot_patches.cmake+tests/checks/python-linux/exe_aot_patches.txt+docs/experiments/exe-aot-patches.md(and a two-line pointer update indocs/experiments/patch-manifests.md).Fixture: synthetic PE32+ whose entry is
mov eax, 1; retin.text(.pdata-registered, no imports). A one-byte patch at the immediate's RVA turns 1 into 42: conversion exits 0,report.jsonrecords the originalsha256,manifest_sha256andpatch_ids ["p001"], the input file on disk is byte-identical, and the lifted C++ contains0x2aull. Whereclis present the check also builds and runs the converted EXE, asserting exit code 42. Negative controls (wrongexpect_sha256, wronginput_sha256, second patch wrong = no partial apply, PE-header / out-of-section / cross-section / unbacked-slack RVAs, non-memoryshader patch, missing manifest) each exit 1 with stagepatchesand leave no_aot.cpp/_aot.exe. Mutation controls: removing theexpect_sha256gate or the section-bounds check makes the fixture accept a bad patch.Linux verification (Debian 13, Python 3.12, pefile 2024.8.26, targeted checks only; GitHub Actions runs the full suite on push):
tests/exe_aot_patches_check.py: 10 tests, all passedtests/patch_manifest_check.py: 9 tests, all passedtests/cpu_exe_aot_cli_check.py: 9 tests, all passedtests/cpu_stdio_exe_aot_check.py: 10 tests, all passedtests/form_coverage_check.py: passedtests/docs_links_check.py: passed (252 Markdown files, 960 links)tests/bidi_controls_check.py: passed (2989 files, no bidirectional controls)git diff --check origin/main...HEAD: clean;git merge-tree --write-tree origin/main HEAD: exits 0No
clon this Linux host, so the build-and-run leg of the positive case did not execute here; Windows verification is the arbiter.Windows Verification (
59f56aca)git merge-tree --write-tree upstream/main HEAD(bdf85910) andgit diff --check.dev(cmake --preset dev, builtcpu_crc_line,cpu_crc_castagnoli,cpu_exe_original,cpu_exe_io):ctest --preset dev --no-tests=error -R '^(exe_aot_patches|patch_manifest_controls|cpu_exe_aot|cpu_stdio_exe_aot)' --output-on-failurepassed5/5(18.23s), includingexe_aot_patches(10 tests,4.78s, withcl-compiled patched EXE exiting42).release(cmake --preset release, built same targets):ctest --preset release --no-tests=error -R '^(exe_aot_patches|patch_manifest_controls|cpu_exe_aot|cpu_stdio_exe_aot)' --output-on-failurepassed5/5(18.49s), includingexe_aot_patches(4.96s).py_compile,tests/docs_links_check.py(252 files, 960 links), andtests/bidi_controls_check.py(2991 files) passed.AI-assisted.
@R0Y00 on GitHub · 2026-12-02 19:35 UTC · original · requested changes
Independent Windows/MSVC Debug
ctest --preset dev --no-tests=error -V -j 1 -R '^(exe_aot_patches|patch_manifest_controls|cpu_exe_aot|cpu_stdio_exe_aot)'passed 5/5. One validation gap remains.apply_memorytreats a section-table match as sufficient proof that its raw file range is outside the headers. It also takes the first matching section without rejecting ambiguous ranges. Please verify the resolved file span independently of the RVA check, reject header-overlapping or ambiguous mappings, and add a source-built rejection control. This preserves the documented refusal for malformed inputs.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.