Each exlaunch inline stub a plugin writes back to back at init is a lift entry, with its callback (#1388, #1451)

Zonai Fieldworks writes one stub per member hook in a row at init and points a gate slot at it when the player switches
the member on. init_code took only the first stub of the row as a start and read the 8-byte callback after it as more
code, so the other stubs (Hookshot at plugin2+0x135048, Fleet Sync at plugin2+0x1350f0) were never lifted and switching
them on ended the game with "no function at guest pc".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Valiantsin DzerakhandClaude Opus 5.5 committed 2026-11-25 21:19:50 +03:00
1 parent 340da7c6e6
commit 4fccaa5bef
2 files changed
+35 -3

No files matched your search

+16
View File
@@ -603,6 +603,22 @@ class Lines(unittest.TestCase):
self.assertIn(f'orig mod_x plugin0 {TRAMP_OFF:x} main {SITE_OFF:x}', out)
self.assertIn(f'seed plugin0 {THUNK_OFF:x}', out)
def test_stubs_written_back_to_back_are_each_a_start(self):
# Zonai Fieldworks writes an inline-hook stub per member hook at init, back to back; a member switched on at
# play points its gate at one (1.4.3 plugin+0x135048, the 4th). The .quad callback after each stub is data.
rec = record()
img, row = bytearray(rec['images']['plugin0']), 0x8000
for k in range(3):
at = row + 0x18 * k
struct.pack_into('<4IQ', img, at, xp.STUR_X30, b(PLUGIN + at + 4, PLUGIN + IMPL_OFF, True), xp.LDUR_X30,
b(PLUGIN + at + 12, PLUGIN + TRAMP_OFF), PLUGIN + CB_OFF)
rec['images']['plugin0'] = bytes(img)
pre = bytearray(img)
pre[row:row + 0x48] = bytes(0x48)
rec['pre_images'] = {'plugin0': bytes(pre)}
starts = xp.init_code(rec, [], 'plugin0')
self.assertEqual(starts, {PLUGIN + row, PLUGIN + row + 0x18, PLUGIN + row + 0x30, PLUGIN + CB_OFF})
def test_hook_on_main_header_keeps_only_its_expect(self):
# Challenge Mode's Enemy Health Regeneration on an update its table lacks: a replace hook at main+0x0, whose
# word 1 is main's module header. The write is checked at start; the lift gets no site, orig or seed for it.
+19 -3
View File
@@ -602,7 +602,12 @@ def init_code(rec, hooks, module):
trampolines of its far hooks (the moved original words and a branch back). The plugin may point a veneer at any of
them at play (Zonai Fieldworks turns its features' hooks on and off), so each is a root of the reach check and a
seed of the lift. The trampolines of inline hooks (never run) and the Orig trampolines of replace hooks (the lift
serves them with the function's unpatched copy) are left out: their way back would split main's functions."""
serves them with the function's unpatched copy) are left out: their way back would split main's functions.
An exlaunch inline-hook stub the init writes (stur x30; bl impl; ldur x30; b trampoline; .quad callback) may be the
target of a hook the plugin turns on at play: Zonai Fieldworks writes one per member hook at init, back to back,
and a member switched on points its gate's pointer at it (the 4th of a row is plugin+0x135048 on 1.4.3). Each stub
and its callback are starts; the .quad is data, not code running on into the next stub."""
p = {m['name']: m for m in rec['modules']}[module]
img, pre = rec['images'].get(module), rec.get('pre_images', {}).get(module)
if img is None or pre is None:
@@ -611,13 +616,24 @@ def init_code(rec, hooks, module):
now, old = struct.unpack_from(f'<{n}I', img), struct.unpack_from(f'<{n}I', pre)
known = {p['base'] + int(h['trampoline'].split('+')[1], 16) for h in hooks
if (h.get('trampoline') or '').startswith(module + '+')}
out, inside = set(), False # inside: the word before is a written word that goes on to this one
for i in range(n):
text = range(p['base'], p['base'] + p['text_end'])
out, inside, i = set(), False, 0 # inside: the word before is a written word that goes on to this one
while i < n:
new = old[i] == 0 and now[i] != 0
if (new and i + 5 < n and now[i] == STUR_X30 and now[i + 1] & 0xFC000000 == 0x94000000
and now[i + 2] == LDUR_X30 and now[i + 3] & 0xFC000000 == 0x14000000):
stub = p['base'] + 4 * i
callback = now[i + 4] | now[i + 5] << 32
out.add(stub)
if callback in text:
out.add(callback)
inside, i = False, i + 6
continue
if new and not inside:
out.add(p['base'] + 4 * i)
# b, br, ret end a trampoline; one may follow right after
inside = new and now[i] & 0xFC000000 != 0x14000000 and now[i] & 0xFFFFFC1F not in (0xD61F0000, 0xD65F0000)
i += 1
return out - known