mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 22:45:53 +01:00
[PR #582] [CLOSED] RT-GUEST-POKE-KNOB: LEONIDA_GUEST_POKE writes bytes into a mapped image #625
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#625
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/582
Author: @fiestorra
Created: 11/24/2026
Status: ❌ Closed
Base:
main← Head:carry/rt-guest-poke-knob📝 Commits (1)
9cbc75fRT-GUEST-POKE-KNOB: LEONIDA_GUEST_POKE writes bytes into a mapped image📊 Changes
3 files changed (+204 additions, -0 deletions)
View changed files
📝
runtime/README.md(+13 -0)📝
runtime/src/pe_loader.cpp(+123 -0)📝
runtime/test/pe_loader_test.cpp(+68 -0)📄 Description
Claimed in the coordination issue as: RT-GUEST-POKE-KNOB — comment https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7126729056
Windows only, no game data needed for the test, nothing online. The measurement that motivated it is in comments https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7126682372 and https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7126728672.
What this changes
LEONIDA_GUEST_POKEwrites bytes into a mapped image while it is still writable. Entries are separated by;and each one is<module>:<rva>:<hex bytes>: the module is its basename, matched case-insensitively with or without its extension; the rva is 1 to 8 hexadecimal digits with or without a0xprefix; the bytes are 1 to 256 hexadecimal pairs.write_guest_pokes(runtime/src/pe_loader.cpp) is called frommap_image, after relocations and beforeinitialize_tlsandprotect_sections. After relocations so an rva means what the caller wrote; before the TLS template is copied so a poke reads as the image's own value to everything that runs afterwards, per-thread TLS copies included; before the protection step so noVirtualProtectdance is needed. It is inmap_imagerather than inload()so a run-timeLoadLibrarygets the same treatment. Every mapped image is offered the entries and only the ones naming it apply. An entry that does not parse, or that would run past the end of the image, is reported on the loader's log and changes nothing; with the variable unset nothing is read and nothing is written.runtime/README.mdgets a paragraph next to the existingLEONIDA_TLS_GA_PATCHone, which is the loader's only other image rewrite.Why this exists
The byte at
game_scarlett_master.exe+0xa9438f4decides whether the title's window stage continues: it is 0 at the check inexe+0x24785cd, the routine returns 0, and the boot stops at theint 3inexe+0x19f4f58. Writing 1 there with a debugger moved the boot to the title's ownCreateCommittedResource3andCreateRenderTargetViewcalls, and the stop was never reached. Repeating that, and anything like it, wants a way to put a byte into the image from outside without attaching a debugger and re-running under it.This is a measuring tool, not a compatibility feature. It does not make the title run: the run with that byte at 1 reported 160 first-chance access violations, and what should have raised the byte is still unknown.
What the test found
test/pe_loader_test.cppgainstest_guest_poke, run frommainaftertest_unwind. It takes the last eight bytes of the fixture image (SizeOfImage - 8, past the code and data the fixture runs), loadstiny_dllthrough the publicLoaderAPI with different values of the variable, and reads those bytes back from the mapped image. It checks that a poke naming<module>.dlland one naming the module without its extension, in upper case and with a0xprefix, both write; that two entries separated by;are both applied; that a poke naming another module, one that would run past the end of the image, and eight malformed entries each change nothing; and that with the variable unset the bytes are the fixture's own.Built and run in this checkout at
d42773d07, Windows 11, MSVC, CPU only: no GPU, nospirv-as/spirv-val, no game executable.One thing the test caught on the first run, worth naming because it is easy to get wrong:
getenv_sreports the length with the terminating NUL counted, so a first version that built the entry list fromstd::string(spec, length)took that NUL as the last byte of the last entry. A single-entry…:deadbeefcafebabethen looked like 17 hex characters and was rejected, while a multi-entry value applied its first entry and rejected its last. The parse now drops trailing NULs before splitting, and the test's positive cases are what showed it.Written with an AI assistant.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.