The generator lifts a mod plugin's hook sites: a call into its stub, its replace target and its call-site rewrite (#845)

After the design in #845 by itaskaev2. New patch lines carry an exlaunch plugin whose init runs at every
start: `plugin` lifts the module from its image after the init (the hook stubs and trampolines the file
has as zeros) and names the hash of that .text, `expect` lists the words the init writes into the game,
`stub` lifts an inline-hook stub's branch to its trampoline as a return, `seed` adds the callbacks, impls
and targets, and `orig` lists an unpatched copy of a hooked main function (fo_<address>) at the replace
hook's trampoline address in the plugin's function table, so the plugin's call of the original does not
reach the hook again and rt_dispatch stays as it is.

A replacement word @call:<module>+<offset> calls the stub without writing x30, with every register in
the Cpu before it and read back after it; the site's own instruction runs after it in place. patches.h
gets RT_PLUGINS, RT_PLUGIN_WRITES and RT_PLUGIN_ROOTS for the runtime. Without plugin lines the output is
byte-identical to dev (generated C, patches.h and layout of 1.2.1 and 1.4.3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Valiantsin DzerakhandClaude Opus 5.5 committed 2026-11-17 08:48:14 +03:00
1 parent b2b85c05fa
commit db6d548ba2
3 files changed
+240 -23

No files matched your search

+17 -1
View File
@@ -12,6 +12,7 @@ import numpy as np
from lifter import Insn, Lifter, Unsupported, hx
from nso import DT_INIT, DT_INIT_ARRAY, DT_INIT_ARRAYSZ, Nso, R_AARCH64_RELATIVE
RET = 0xD65F03C0
LIFT_CACHE = 1 << 16 # lifted instructions kept per module; analyses revisit nearby addresses only
@@ -33,13 +34,27 @@ def _read_encoded(img, off, enc, pc_base):
class Module:
def __init__(self, name, path, base, simd='c', plugin=False):
def __init__(self, name, path, base, simd='c', plugin=False, image=None, rets=(), seeds=()):
"""image, rets, seeds: a plugin's lift (recomp/patches.py `plugin`): its .text is taken from image (the plugin's
image after its init, holding the hook stubs and trampolines the file has as zeros), the words at the image
offsets rets become `ret` (an inline-hook stub's b to its trampoline), and the image offsets seeds are function
starts too."""
self.name = name
self.nso = Nso(str(path))
self.base = base
self.plugin = plugin # a mod's code module (recomp/layout.py plugin<N>): its init functions are seeds too
n = self.nso
self.image = bytes(n.image)
if image is not None:
t0, t1 = n.text[0], n.text[0] + n.text[1]
if len(image) < t1:
raise ValueError(f'{name}: the image after the init is shorter than its .text')
img = bytearray(self.image)
img[t0:t1] = image[t0:t1]
for o in rets:
img[o:o + 4] = RET.to_bytes(4, 'little')
self.image = bytes(img)
self.extra_seeds = [base + o for o in seeds]
self.lo = base + n.text[0]
self.hi = self.lo + n.text[1]
self.words = np.frombuffer(self.image, dtype='<u4', count=n.text[1] // 4, offset=n.text[0])
@@ -120,6 +135,7 @@ class Module:
starts = set(self.eh_frame_functions())
if self.plugin:
starts.update(self.init_functions())
starts.update(self.extra_seeds)
for _, info, shndx, value, _ in self.nso.syms:
if shndx and (info & 0xF) == 2:
starts.add(self.base + value)