patch manifests: hash-gated memory and data patches for source-translated builds #3037

Open
opened 2026-11-27 10:41:18 +00:00 by github-bot · 2 comments
Owner

@⁠JohnConnorNPC on GitHub · 2026-11-27 09:30 UTC · original

Refs discussion #3026. Target branch main (cpp-migration has been merged into it).

Goal

Add a declarative patch manifest so input-specific adjustments can be applied to a source-translated build without modifying the original binary or data on disk, and without putting any input content in the repository.

Scope of this issue (main only)

  1. Schema, loader and hash gate. A manifest is bound to one input by SHA-256 and refuses to apply to any other input (no partial apply). Every patch carries id, kind, why and remove_when. Fixture: a synthetic PE, with a negative control for a wrong input hash.
  2. Stage 2: memory patches (runtime). After image load, write replacement bytes at an RVA only if the original bytes match expect_sha256 (verified, never stored). Negative control: wrong bytes fail loudly.
  3. Stage 3: data patches (file layer). Serve a replacement file or byte range for a path, leaving the original untouched. Needs the file-API shim to be the single read path; the first step is checking what exists in src/.
  4. Reporting. Every run report records the active patch ids and the manifest hash.

Out of scope here

  • Stage 1 (hook, function replace/skip/return-constant/branch-force) as a separate PR. The base-branch question is settled: cpp-migration was merged into main (#3039), so everything here targets main. The manifest should be consumed by the existing translators rather than a parallel tool: the CPU converter (exe_aot) and, for GPU programs, the shader-cache translation override. One manifest and one planner, several consumers.
  • Input-specific manifests and replacement code: they stay local under game-files/patches/, which is gitignored.

Acceptance

  • One PR per stage; each has a test with a negative control, run on Linux (pure Python or synthetic fixtures) where possible.
  • The README/docs/experiments.md gain the manifest format and the reproduction command.
  • Public wording stays platform-neutral; no game files, dumps or hashes of them.

This issue was AI-assisted.

**@⁠JohnConnorNPC** on GitHub · 2026-11-27 09:30 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/3037) Refs discussion #3026. Target branch `main` (`cpp-migration` has been merged into it). ## Goal Add a declarative patch manifest so input-specific adjustments can be applied to a source-translated build without modifying the original binary or data on disk, and without putting any input content in the repository. ## Scope of this issue (main only) 1. **Schema, loader and hash gate.** A manifest is bound to one input by SHA-256 and refuses to apply to any other input (no partial apply). Every patch carries `id`, `kind`, `why` and `remove_when`. Fixture: a synthetic PE, with a negative control for a wrong input hash. 2. **Stage 2: `memory` patches (runtime).** After image load, write replacement bytes at an RVA only if the original bytes match `expect_sha256` (verified, never stored). Negative control: wrong bytes fail loudly. 3. **Stage 3: `data` patches (file layer).** Serve a replacement file or byte range for a path, leaving the original untouched. Needs the file-API shim to be the single read path; the first step is checking what exists in `src/`. 4. **Reporting.** Every run report records the active patch ids and the manifest hash. ## Out of scope here - Stage 1 (`hook`, function replace/skip/return-constant/branch-force) as a separate PR. The base-branch question is settled: `cpp-migration` was merged into `main` (#3039), so everything here targets `main`. The manifest should be consumed by the existing translators rather than a parallel tool: the CPU converter (`exe_aot`) and, for GPU programs, the shader-cache translation override. One manifest and one planner, several consumers. - Input-specific manifests and replacement code: they stay local under `game-files/patches/`, which is gitignored. ## Acceptance - One PR per stage; each has a test with a negative control, run on Linux (pure Python or synthetic fixtures) where possible. - The README/`docs/experiments.md` gain the manifest format and the reproduction command. - Public wording stays platform-neutral; no game files, dumps or hashes of them. This issue was AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 10:41:18 +00:00
Author
Owner

@⁠Not-Saii on GitHub · 2026-11-27 12:31 UTC · original

Claiming item 1 (schema, loader and hash gate). Items 2-4 stay open; I can follow with item 2 once this lands.

Environment: Windows 11 build 26300, Python 3.14 (CI: Python 3.12 on Linux). Pure Python, no GPU or game files needed.

Part I will test: tools/patch_manifest.py, a TOML manifest read with the standard library's tomllib. [target] input_sha256 plus [[patch]] entries, each with id, kind, why and remove_when. The whole manifest is validated and the input's SHA-256 compared before anything is returned, so nothing applies partially. Unknown or missing keys are refused at every level. Only kind = "memory" is defined (rva, expect_sha256, bytes), checked for shape only, with no applier. hook and data are refused as not supported until their stages define them. The loader returns manifest_sha256 and the patch ids for item 4.

Fixture: tests/patch_manifest_check.py with a synthetic PE32+ built at run time from build_pe32_plus in tests/call_evidence_check.py. Negative controls: a wrong-input hash through the CLI (exit 1), plus misspelled keys, unsupported kind, duplicate id, overlapping patches and malformed values. Registered in tests/checks/python-linux/ and tests/cmake/; note in docs/experiments/patch-manifests.md.

Shared interface: the manifest format. Stages 2-4 and the exe_aot and shader-cache consumers would build on it, so please flag any objection to TOML or to the strict-key rule now. PR will target main.

**@⁠Not-Saii** on GitHub · 2026-11-27 12:31 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/3037#issuecomment-7218338707) Claiming item 1 (schema, loader and hash gate). Items 2-4 stay open; I can follow with item 2 once this lands. Environment: Windows 11 build 26300, Python 3.14 (CI: Python 3.12 on Linux). Pure Python, no GPU or game files needed. Part I will test: `tools/patch_manifest.py`, a TOML manifest read with the standard library's `tomllib`. `[target] input_sha256` plus `[[patch]]` entries, each with `id`, `kind`, `why` and `remove_when`. The whole manifest is validated and the input's SHA-256 compared before anything is returned, so nothing applies partially. Unknown or missing keys are refused at every level. Only `kind = "memory"` is defined (`rva`, `expect_sha256`, `bytes`), checked for shape only, with no applier. `hook` and `data` are refused as not supported until their stages define them. The loader returns `manifest_sha256` and the patch ids for item 4. Fixture: `tests/patch_manifest_check.py` with a synthetic PE32+ built at run time from `build_pe32_plus` in `tests/call_evidence_check.py`. Negative controls: a wrong-input hash through the CLI (exit 1), plus misspelled keys, unsupported kind, duplicate id, overlapping patches and malformed values. Registered in `tests/checks/python-linux/` and `tests/cmake/`; note in `docs/experiments/patch-manifests.md`. Shared interface: the manifest format. Stages 2-4 and the `exe_aot` and shader-cache consumers would build on it, so please flag any objection to TOML or to the strict-key rule now. PR will target `main`.
Author
Owner

@⁠JohnConnorNPC on GitHub · 2026-11-27 14:06 UTC · original

@⁠Not-Saii Thanks for #3056. I had a schema, loader and hash gate built to nearly the same design (TOML, same keys, same SHA-256 gate) and had not posted it before yours merged, so I'm dropping mine and building on yours. I also have the next stages built and reviewed locally on my own loader copy and will rebase them onto yours: the memory applier in the debugger launcher (item 2), a consumer in the CPU converter (exe_aot --patches, translating a patched copy) and a per-key shader-cache override. So to avoid overlap I'm taking item 2 and will open it one PR at a time. First a small PR to tools/patch_manifest.py: a refusal for deeply nested input (the CLI currently ends in a RecursionError traceback), a kind = "shader" shape, and a gate on bytes the caller already read. Item 3 (data patches, the file layer) is not started; please take it if you'd like it.
This comment was AI-assisted.

**@⁠JohnConnorNPC** on GitHub · 2026-11-27 14:06 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/3037#issuecomment-7220351249) @⁠Not-Saii Thanks for #3056. I had a schema, loader and hash gate built to nearly the same design (TOML, same keys, same SHA-256 gate) and had not posted it before yours merged, so I'm dropping mine and building on yours. I also have the next stages built and reviewed locally on my own loader copy and will rebase them onto yours: the memory applier in the debugger launcher (item 2), a consumer in the CPU converter (`exe_aot --patches`, translating a patched copy) and a per-key shader-cache override. So to avoid overlap I'm taking item 2 and will open it one PR at a time. First a small PR to `tools/patch_manifest.py`: a refusal for deeply nested input (the CLI currently ends in a RecursionError traceback), a `kind = "shader"` shape, and a gate on bytes the caller already read. Item 3 (`data` patches, the file layer) is not started; please take it if you'd like it. This comment was AI-assisted.
This discussion has been locked. Commenting is limited to contributors.
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.

Dependencies

No dependencies set

Reference
github/R0Y00--Xbox2Windows#3037
No description provided.