feat(dev): reverse-engineering tools for finding hook sites: a code index, a function-hit trace and a write-watch #2924
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2924
Loading…
Reference in a new issue
No description provided.
Delete branch "re/tools"
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?
Summary
Finding a new hook site meant reading lifted code by hand. This adds three development-only tools that take a behaviour
of the game to the function and instruction a site goes on, and a page on how to use them
(docs/dev/reference/reverse-engineering.md, with a worked synthetic example and how the site's signature or
fingerprint is then written):
longshot-builder dev factswrites what the lift's own discovery knows of each function (calls pastPLT stubs, virtual-call slots, string and data references, constants and floats, function pointers and vtables,
exports, guest stores), and
dev disasmdecodes a range.scripts/re.py indexloads the facts into SQLite under~/.cache/longshot-dev/re. It then answers callers/callees, xrefs, strings, const, float, vtable, vslot, vcalls,path, dis and ir queries, as text or
--json.tracecommand marks a window;re.py trace difflists the functions that ran in one window and not in another.LONGSHOT_WATCH_STORES=1, the lift tests every guest store against a watched range. Thebridge's new
watchcommand sets the range and writes what hit it: each writing function and instruction, thevalues and the frames.
watchneedsHOS_CONTROL_MEM.dev.py rt --rebuilds both intobuild-linux/rt-<checkout>-re, from a work folder of its own.Read first:
builder/crates/llvm/src/lib.rs(watch),host/re_watch.c,host/control.c(cmd_re),builder/crates/longshot-builder/src/dev/facts.rs,scripts/re.py.Everything the tools make (the index, the traces, the watches) is made from the game and stays on the PC, under
~/.cache/longshot-dev/re. Nothing of it is in this PR; the tests use synthetic images, facts and windows.Testing
Tested: Linux, RTX 3090. Tested in game: the index on the real game (built from this PC's game, every query
answered). In one shared run of the
--reruntime, the trace windows diffed (walking against idle, rollingagainst walking, each naming the functions only in the second), and a write-watch on the player's position named one
writer with its three stores, a hit every frame while he walked; 12 more watches on other objects named their writers.
The game-free parts of trace and watch are also covered by the tests below.
Checks, in one build-mode job (retools-check), all pass:
dev.py rt: the normal runtime builds over the base.scripts/check_host_compile.py: 82 host units, 0 failed.cargo testandcargo clippy -D warningsfor llvm and longshot-builder. llvm has a new watch-IR test, compiled byclang; with the option off, nothing of it is emitted.
run_all --exact: test_re, test_re_dev, test_control (the control and re_dev C tests, and control.c's llvm-mingwcompile), test_doc_commands, test_doc_anchors.
host/re_watch.candhost/guest_profile.ccompiled with llvm-mingw (-Wall -Wextra -Werror).Earlier, outside the queue:
cargo test -p lift,-p build-driver, test_guest_profile_write, test_switch_table,pre-commit.
Still to test:
dev.py rt --re, then two trace windows and a watch of a known field, expecting a shortdiff and the field's writers named (by hand, in the first site-finding session).
Measurements
Nothing to measure: with the switch off the lifted IR is unchanged (a test checks it), so normal builds and fps are unchanged; the
-rebuild is development only. Every lift cache is rebuilt once, as with any change to the lifter's sources.Risks
Development only.
LONGSHOT_WATCH_STORESis off unless set to1, andtraceandwatchanswerunavailablein anormal build. A revert is enough. Players notice nothing, apart from the lift rebuilding once after the update.
Checklist
Ready for review
mod-api; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). (the tests that read the changed files pass in retools-check; the whole suite is not run)main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
https://claude.ai/code/session_016o1k1SQVyAWsujjFVd8Wuc
Checked without a game run: dev.py rt built; cargo test and clippy -D warnings on llvm and longshot-builder pass; run_all --exact test_re, test_re_dev, test_control (with the C tests), test_doc_commands and test_doc_anchors pass; the host compiles on Linux (82 units, 0 failed), and re_watch.c and guest_profile.c compile with llvm-mingw for Windows under -Werror. Tested in game: Linux, RTX 3090, the code index built from this PC's game and every query answered. The trace and write-watch get their first real-game run in the first site-finding session.
Tested in game (Linux, RTX 3090, one shared run of the --re runtime): trace windows diffed (walking vs idle, rolling vs walking), and a write-watch on the player's position named its writer and three stores, a hit every frame; 12 more watches named their writers. Note for users: two idle windows already differ (background work), so take several windows per side.
WIP: feat(dev): reverse-engineering tools for finding hook sites: a code index, a function-hit trace and a write-watchto feat(dev): reverse-engineering tools for finding hook sites: a code index, a function-hit trace and a write-watch