A plugin hook on main's module header gets only its expect line, not a lift site (#1422, #1461)

exlaunch adds a table offset to main's base, so an update the plugin's table lacks hooks main+0x0 (Challenge
Mode's Enemy Health Regeneration names 1.0.0 to 1.4.1). Nothing runs there, on the Switch either; the site line
made the generator refuse the lift ("patched instruction is a trap") and the installer dropped every plugin. The
report notes such a hook.

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:06:28 +03:00
1 parent 5c5c6d1dd0
commit 340da7c6e6
2 files changed
+28

No files matched your search

+14
View File
@@ -603,6 +603,20 @@ 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_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.
new = b(MAIN, PLUGIN + THUNK_OFF)
rec = record(writes=[{'module': 'main', 'offset': 0, 'old': 1, 'new': new}])
hook = {'kind': 'replace', 'site': 'main+0x0', 'original': '0x00000001', 'target': f'plugin0+{THUNK_OFF:#x}',
'trampoline': f'plugin0+{TRAMP_OFF:#x}'}
with tempfile.TemporaryDirectory() as d:
(Path(d) / 'plugin0.img').write_bytes(rec['images']['plugin0'])
rec['modules'][2]['image'] = 'plugin0.img'
out = xp.plugin_lines(rec, [hook], 'mod_x', d, 'plugin0')
self.assertIn(f'expect mod_x main 0 00000001 {new:08x}', out)
self.assertFalse(any(x.startswith(('site', 'orig', 'seed', 'entry')) for x in out), out)
def test_call(self):
new = b(MAIN + SITE_OFF, PLUGIN + THUNK_OFF, True)
w = [{'module': 'main', 'offset': SITE_OFF, 'old': 0x94000010, 'new': new}]
+14
View File
@@ -132,6 +132,14 @@ def u(v):
return int(v, 16) if isinstance(v, str) else v
def header_site(h):
"""The hook sits on main's module header, not on code. exlaunch adds a table offset to main's base, and a game
update the plugin's table lacks gives offset 0 (Challenge Mode's Enemy Health Regeneration names 1.0.0 to 1.4.1).
Nothing runs there, on the Switch either: the write is kept and checked, and the lift gets no site for it (its
first word, 1, decodes as a trap the generator refuses to patch)."""
return h['site'] == 'main+0x0'
def ran_view(rec):
"""The record as seen from the plugins whose inits ran: a plugin that only stayed loaded (TOTK_PLUGIN_ONLY) counts
as a module that is no plugin, so its exports and code are not checked as this record's. A record without "ran"
@@ -621,6 +629,7 @@ def entries(rec, hooks, module):
back there too."""
mods = {m['name']: m for m in rec['modules']}
main, p = mods['main'], mods[module]
hooks = [h for h in hooks if not header_site(h)] # never run: no way back into main, no code to seed
out = {int(h['site'].split('+')[1], 16) + 4 for h in hooks
if h['kind'] == 'branch' or h['kind'] == 'replace' and not h.get('trampoline')}
base, img = p['base'], rec['images'][module]
@@ -667,6 +676,8 @@ def plugin_lines(rec, hooks, name, record_dir, module):
for h in hooks:
site = int(h['site'].split('+')[1], 16)
if header_site(h):
continue
if h['kind'] == 'inline':
sm, so = at(h['stub'])
stubs.setdefault(sm, set()).add(so)
@@ -853,6 +864,9 @@ def report(rec, label, game=frozenset()):
else:
print(f' {h["kind"]} {h["site"]} (was {h["original"]}) -> {"bl" if h["kind"] == "call" else "b"} '
f'{h["target"]}' + (f', Orig trampoline {h["trampoline"]}' if h.get('trampoline') else ''))
if header_site(h):
print(f' note: {h["site"]} is main\'s module header, not code: the plugin has no address for this game '
f'update there, and this hook does nothing, as on the Switch')
for r in reasons:
print(f' REFUSED: {r}')
if not reasons: