Runtime knob to write bytes into a loaded module (VICTORY_PATCH=<module>:<rva>:<bytes>) #917

Open
opened 2026-11-26 04:14:09 +00:00 by github-bot · 4 comments
Owner

@⁠fiestorra on GitHub · 2026-11-24 14:07 UTC · original

What I would like

One documented way to write bytes into a module after the loader has mapped and relocated it, before the thread-local storage copy and the section protection. Shape I have in mind:

VICTORY_PATCH=<module basename>:<rva hex>:<hex bytes>

repeatable, with each application echoed to the log (module, rva, old bytes, new bytes) so a run is reproducible from its own log and the patched addresses are visible to whoever reads the report.

Why it is useful for this project

Most of what I can measure about the title is questions about the title's own code, and today the only thing I can do with that code is read it. Examples, all from my local copy of the 1.0.2.1 package (SHA-256 e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993, offsets are RVAs in the title image):

  • +0x247af2d is a conditional int 3: sub of two stack values, add of a global, cmp rax, 1FFFFFh, jbe +1, int 3 — the title stops when a range reaches 2 MiB. Only stop of that kind in the whole image.
  • +0x19f4f58 is another conditional int 3, right after call +0x2478440h and test al,al / jne +1 — a bring-up routine whose byte result gates what follows.
  • The two device-table entries with no implementation, +0x1c8 and +0x218, are reached from 165 and 107 sites in .text (measurements here).

Each of those is a question I can only ask by changing a byte: skip the stop, force the branch, see what the title does next. Without a knob, the experiment needs a rewritten copy of a 120 MB file, and the run no longer matches the build id every report names.

What exists nearby today

  • VICTORY_WATCH=<rva> and VICTORY_CRASH_SAVE=<rva>:<len> read the guest image; nothing writes to it.
  • --unimplemented trap|zero changes how host methods answer, not the guest.
  • victory-loader does write into images while loading (prepare.rs, tls.rs), just never at an address someone asks for.
  • The environment variables in the README include nothing that writes into a loaded module.

Scope

Not a patch system. One knob, applied once, at a fixed point in the load order, logged with the bytes it replaced. If the preferred shape is a victory.toml section rather than an environment variable, I would take either — where it lands matters less than that it happens after relocations and before protection, and that the log says what changed.

I have not implemented anything for this; every measurement above is read-side. Happy to test whatever form maintainers prefer, on the same build id.

Written with an AI assistant.

**@⁠fiestorra** on GitHub · 2026-11-24 14:07 UTC · [original](https://github.com/Marvisak/VIctory/issues/917) ### What I would like One documented way to write bytes into a module **after** the loader has mapped and relocated it, before the thread-local storage copy and the section protection. Shape I have in mind: ``` VICTORY_PATCH=<module basename>:<rva hex>:<hex bytes> ``` repeatable, with each application echoed to the log (module, rva, old bytes, new bytes) so a run is reproducible from its own log and the patched addresses are visible to whoever reads the report. ### Why it is useful for this project Most of what I can measure about the title is questions about the title's own code, and today the only thing I can do with that code is read it. Examples, all from my local copy of the 1.0.2.1 package (SHA-256 `e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993`, offsets are RVAs in the title image): - `+0x247af2d` is a **conditional** `int 3`: `sub` of two stack values, `add` of a global, `cmp rax, 1FFFFFh`, `jbe +1`, `int 3` — the title stops when a range reaches 2 MiB. Only stop of that kind in the whole image. - `+0x19f4f58` is another conditional `int 3`, right after `call +0x2478440h` and `test al,al / jne +1` — a bring-up routine whose byte result gates what follows. - The two device-table entries with no implementation, `+0x1c8` and `+0x218`, are reached from 165 and 107 sites in `.text` ([measurements here](https://git.gtahub.st/github/Marvisak--VIctory/issues/417)). Each of those is a question I can only ask by changing a byte: skip the stop, force the branch, see what the title does next. Without a knob, the experiment needs a rewritten copy of a 120 MB file, and the run no longer matches the build id every report names. ### What exists nearby today - `VICTORY_WATCH=<rva>` and `VICTORY_CRASH_SAVE=<rva>:<len>` read the guest image; nothing writes to it. - `--unimplemented trap|zero` changes how *host* methods answer, not the guest. - `victory-loader` does write into images while loading (`prepare.rs`, `tls.rs`), just never at an address someone asks for. - The environment variables in the README include nothing that writes into a loaded module. ### Scope Not a patch system. One knob, applied once, at a fixed point in the load order, logged with the bytes it replaced. If the preferred shape is a `victory.toml` section rather than an environment variable, I would take either — where it lands matters less than that it happens after relocations and before protection, and that the log says what changed. I have not implemented anything for this; every measurement above is read-side. Happy to test whatever form maintainers prefer, on the same build id. Written with an AI assistant.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:14:09 +00:00
Author
Owner

@⁠pickles976 on GitHub · 2026-11-24 14:11 UTC · original

Strong +1 on this knob from the sibling runtime's side — it is the missing half of the shared crash-site map (Marvisak/VIctory#630): five deliberately-placed stops, verified byte-for-byte by three independent holders of the hash-pinned image, and none of them answer "what happens if the title is allowed past it" until someone can bypass one without rebuilding. Patch table for the map's sites (module game_scarlett_master.exe, RVA = the game+0x… number, image-base-relative), each with the reading it buys:

site (RVA) patch what it answers
+0x23cf683 11 bytes at the site → 90×11 (mov dword ptr [0], 4d8bd421h NOP'd; the function's own add rsp,48h; ret follows) the watchdog self-kill is the end of every stalled run. Continue-past tells you whether the title's threads resume productively (stall was transient → the watchdog is the false-positive problem) or immediately re-wait (the CPU-side completion really is lost). Highest-value single byte in the map.
+0x247af2d cc → 90 the 2 MiB range cap currently surfaces as a crash-handler record; NOP'd it proceeds silently into +0x5c8fa7x. If oversized ranges render fine, the cap is conservative vs console behavior and reports of that record are noise, not walls.
+0x193e00f cc → 90 the 8 GB cohort's fatal int3 after the failed call [rax+0x428]: the jns skip already handles success; NOP'ing the failure path continues with the HR negative in esi. Whatever check trips next names the first true dependency on that placed resource — exactly what the VRAM-spillover work needs. Expect cascades; the first subsequent trip is the finding.
+0x2215c35 c7 04 25 00 00 00 00 00 00 00 00 → 90×11 the null-checked callback stop; bypass tells you whether callers tolerate the missing callback. Lower priority — the guard path (je) already exists and is probably the tolerated route.
+0x19f4f58 cc → 90 bring-up gate (byte from routine +0x2478440); almost certainly cascades — listed for completeness, run it last.

Two cautions from our side of the fence: the knob must apply before the title's own integrity pass if one exists (map not exhaustive on that point — if a patch silently "does nothing", suspect the check ran first), and a continued-past watchdog run may corrupt save state, so treat the patched prefix as disposable. If the first experiments pay off, the same table belongs in our runtime's docs too — our contributors are hand-patching builds for exactly this (the thread's modified-build A/Bs), so I will cross-post the table there.

**@⁠pickles976** on GitHub · 2026-11-24 14:11 UTC · [original](https://github.com/Marvisak/VIctory/issues/917#issuecomment-7133974200) Strong +1 on this knob from the sibling runtime's side — it is the missing half of the shared crash-site map (Marvisak/VIctory#630): five deliberately-placed stops, verified byte-for-byte by three independent holders of the hash-pinned image, and **none of them answer "what happens if the title is allowed past it"** until someone can bypass one without rebuilding. Patch table for the map's sites (module `game_scarlett_master.exe`, RVA = the `game+0x…` number, image-base-relative), each with the reading it buys: | site (RVA) | patch | what it answers | |---|---|---| | `+0x23cf683` | 11 bytes at the site → `90`×11 (`mov dword ptr [0], 4d8bd421h` NOP'd; the function's own `add rsp,48h; ret` follows) | the watchdog self-kill is the **end of every stalled run**. Continue-past tells you whether the title's threads resume productively (stall was transient → the *watchdog* is the false-positive problem) or immediately re-wait (the CPU-side completion really is lost). Highest-value single byte in the map. | | `+0x247af2d` | `cc` → `90` | the 2 MiB range cap currently surfaces as a crash-handler *record*; NOP'd it proceeds silently into `+0x5c8fa7x`. If oversized ranges render fine, the cap is conservative vs console behavior and reports of that record are noise, not walls. | | `+0x193e00f` | `cc` → `90` | the 8 GB cohort's fatal `int3` after the failed `call [rax+0x428]`: the `jns` skip already handles *success*; NOP'ing the failure path continues with the HR negative in `esi`. Whatever check trips next names the **first true dependency on that placed resource** — exactly what the VRAM-spillover work needs. Expect cascades; the *first* subsequent trip is the finding. | | `+0x2215c35` | `c7 04 25 00 00 00 00 00 00 00 00` → `90`×11 | the null-checked callback stop; bypass tells you whether callers tolerate the missing callback. Lower priority — the guard path (`je`) already exists and is probably the tolerated route. | | `+0x19f4f58` | `cc` → `90` | bring-up gate (byte from routine `+0x2478440`); almost certainly cascades — listed for completeness, run it last. | Two cautions from our side of the fence: the knob must apply **before the title's own integrity pass** if one exists (map not exhaustive on that point — if a patch silently "does nothing", suspect the check ran first), and a continued-past watchdog run may corrupt save state, so treat the patched prefix as disposable. If the first experiments pay off, the same table belongs in our runtime's docs too — our contributors are hand-patching builds for exactly this (the thread's modified-build A/Bs), so I will cross-post the table there.
Author
Owner

@⁠Halfect on GitHub · 2026-11-24 15:07 UTC · original

I've implemented this knob on a branch: https://github.com/Halfect/VIctory/tree/fix/loader-patch-knob

Design:

  • VICTORY_PATCH=<module>:<rva>:<hex bytes>,..., parsed in victory-loader with the same comma/hex conventions as the other debugging knobs (VICTORY_WATCH etc.); malformed entries are skipped.
  • The module name is matched case-insensitively against the loaded module's file name, so an entry can target the title image or any of its DLLs.
  • The write happens in load(), after LoadLibraryExW has mapped and relocated the image and before TLS redirection and import binding — the earliest point where every patch site mentioned here is in its final, relocated state.
  • Each entry is bounds-checked against size_of_image; the target pages are temporarily made writable with VirtualProtect and restored afterwards, and every applied write is logged at info level with the bytes it replaced, so a run is reproducible from its own log.

Verified locally, CPU-only: cargo test -p victory-loader (30 tests pass, 5 new ones cover parsing, malformed entries, module/bounds matching and overflow, and write semantics), cargo clippy -p victory-loader --all-targets --locked -- -D warnings (default and --all-features), and cargo xtask policy (155 files ok).

I can't open the PR yet — this repository currently restricts pull requests to collaborators (see #717), and I'm not one. I'll open it as soon as that restriction is lifted; if a maintainer would rather pull the branch directly or wants the knob shaped differently, happy to adjust.

**@⁠Halfect** on GitHub · 2026-11-24 15:07 UTC · [original](https://github.com/Marvisak/VIctory/issues/917#issuecomment-7135503434) I've implemented this knob on a branch: https://github.com/Halfect/VIctory/tree/fix/loader-patch-knob Design: - `VICTORY_PATCH=<module>:<rva>:<hex bytes>,...`, parsed in `victory-loader` with the same comma/hex conventions as the other debugging knobs (`VICTORY_WATCH` etc.); malformed entries are skipped. - The module name is matched case-insensitively against the loaded module's file name, so an entry can target the title image or any of its DLLs. - The write happens in `load()`, after `LoadLibraryExW` has mapped and relocated the image and before TLS redirection and import binding — the earliest point where every patch site mentioned here is in its final, relocated state. - Each entry is bounds-checked against `size_of_image`; the target pages are temporarily made writable with `VirtualProtect` and restored afterwards, and every applied write is logged at info level with the bytes it replaced, so a run is reproducible from its own log. Verified locally, CPU-only: `cargo test -p victory-loader` (30 tests pass, 5 new ones cover parsing, malformed entries, module/bounds matching and overflow, and write semantics), `cargo clippy -p victory-loader --all-targets --locked -- -D warnings` (default and `--all-features`), and `cargo xtask policy` (155 files ok). I can't open the PR yet — this repository currently restricts pull requests to collaborators (see #717), and I'm not one. I'll open it as soon as that restriction is lifted; if a maintainer would rather pull the branch directly or wants the knob shaped differently, happy to adjust.
Author
Owner

@⁠Halfect on GitHub · 2026-11-24 15:27 UTC · original

The PR is open now: #1059. The collaborator restriction appears to have been lifted, so the branch went up as-is — same design and checks as in the comment above. Happy to adjust the shape if maintainers prefer something different.

**@⁠Halfect** on GitHub · 2026-11-24 15:27 UTC · [original](https://github.com/Marvisak/VIctory/issues/917#issuecomment-7136069478) The PR is open now: #1059. The collaborator restriction appears to have been lifted, so the branch went up as-is — same design and checks as in the comment above. Happy to adjust the shape if maintainers prefer something different.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 06:51 UTC · original

Automated triage for the maintainers.

A debugging switch that writes bytes into a loaded module would fit the project's scope (Windows host, the user's own files, offline); whether to add one is for the maintainers. On main, crates/victory-loader has read-side switches such as VICTORY_WATCH but nothing that writes at a requested address. Open PR #1059 (from the branch mentioned above) implements VICTORY_PATCH, so review can happen there.

Please do not post the title's code here: the instruction sequences, byte patterns and patch tables quoted in this thread come from the game's files and must not be posted in this repository.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 06:51 UTC · [original](https://github.com/Marvisak/VIctory/issues/917#issuecomment-7155228042) <!-- victory-issue-triage v1 verdict=tracked seen=2026-11-24T15:27:51Z at=2026-11-25T06:51:18Z --> Automated triage for the maintainers. A debugging switch that writes bytes into a loaded module would fit the project's scope (Windows host, the user's own files, offline); whether to add one is for the maintainers. On `main`, `crates/victory-loader` has read-side switches such as `VICTORY_WATCH` but nothing that writes at a requested address. Open PR #1059 (from the branch mentioned above) implements `VICTORY_PATCH`, so review can happen there. Please do not post the title's code here: the instruction sequences, byte patterns and patch tables quoted in this thread come from the game's files and must not be posted in this repository. --- _Generated by [Claude Code](https://claude.ai/code)_
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/Marvisak--VIctory#917
No description provided.