Runtime knob to write bytes into a loaded module (VICTORY_PATCH=<module>:<rva>:<bytes>) #917
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory#917
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@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:
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):+0x247af2dis a conditionalint 3:subof two stack values,addof 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.+0x19f4f58is another conditionalint 3, right aftercall +0x2478440handtest al,al / jne +1— a bring-up routine whose byte result gates what follows.+0x1c8and+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>andVICTORY_CRASH_SAVE=<rva>:<len>read the guest image; nothing writes to it.--unimplemented trap|zerochanges how host methods answer, not the guest.victory-loaderdoes write into images while loading (prepare.rs,tls.rs), just never at an address someone asks for.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.tomlsection 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.
@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 = thegame+0x…number, image-base-relative), each with the reading it buys:+0x23cf68390×11 (mov dword ptr [0], 4d8bd421hNOP'd; the function's ownadd rsp,48h; retfollows)+0x247af2dcc→90+0x5c8fa7x. If oversized ranges render fine, the cap is conservative vs console behavior and reports of that record are noise, not walls.+0x193e00fcc→90int3after the failedcall [rax+0x428]: thejnsskip already handles success; NOP'ing the failure path continues with the HR negative inesi. 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.+0x2215c35c7 04 25 00 00 00 00 00 00 00 00→90×11je) already exists and is probably the tolerated route.+0x19f4f58cc→90+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.
@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 invictory-loaderwith the same comma/hex conventions as the other debugging knobs (VICTORY_WATCHetc.); malformed entries are skipped.load(), afterLoadLibraryExWhas 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.size_of_image; the target pages are temporarily made writable withVirtualProtectand 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), andcargo 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: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.
@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-loaderhas read-side switches such asVICTORY_WATCHbut nothing that writes at a requested address. Open PR #1059 (from the branch mentioned above) implementsVICTORY_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