From 6f97dca93a612d3d72207d799e15fce0b5d4cfc7 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Wed, 25 Nov 2026 16:06:54 +0300 Subject: [PATCH] A plugin's call to a function it defines itself is its own code, not an import (#1422, #1461) A plugin built with default visibility calls its own exported functions through its PLT. Challenge Mode's Enemy Health Regeneration plugin (exefs subsdk8) does so for the std::vector constructor it carries, and the service run counted that as a library call outside the reviewed list, so the plugin was refused and its whole mod stayed off. runtime/loader.c resolve binds such a JUMP_SLOT straight to the plugin's own definition (a host override still wins and stays counted), and tools/exefs_plugins.py plt_imports maps the PLT stub to that code, so the reach check follows into it instead of naming an import. Co-Authored-By: Claude Opus 5.5 --- docs/mods.md | 4 +++- runtime/loader.c | 8 +++++++- tests/exefs_plugins_test.py | 20 ++++++++++++++++++++ tools/exefs_plugins.py | 15 +++++++++++++-- 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/docs/mods.md b/docs/mods.md index 3d4ba533..6b65f716 100644 --- a/docs/mods.md +++ b/docs/mods.md @@ -128,7 +128,9 @@ The rebuild refuses a plugin when its start-up or the code its redirects reach n system calls other than the few its start-up needs (memory queries and maps, the heap size, the clock, debug output), or a library call the game itself never makes and a reviewed list does not hold (memory and string functions, the heap, text formatting, mutexes, the clock, the system language, the SD card's files), such as network sockets or the module -loader. A library call the game makes (threads, input, time, its files) runs on the path the game runs on. A start-up +loader. A library call the game makes (threads, input, time, its files) runs on the path the game runs on. A call to a +function the plugin itself holds counts as its own code, even when it goes through the plugin's import table (C++ +library templates such as `std::vector` built into it). A start-up still gets only the system calls above, so it cannot start a thread or open a service; a redirect that is not one of exlaunch's hook shapes (inline hook, replace hook, call-site rewrite, a branch into its code from inside a game function, a pointer in the game's data swapped for one into its code); a write into the game's read-only data or into another module; two runs of diff --git a/runtime/loader.c b/runtime/loader.c index 635d4313..3051eb9e 100644 --- a/runtime/loader.c +++ b/runtime/loader.c @@ -397,7 +397,13 @@ static Res resolve(Mod *m, uint32_t si, int jump) { uint64_t guest = sym_defined(m, si) ? m->pub.base + m->syms[si].value : find_symbol(name, NULL); GuestFn f; Res r; - if (jump && m->pub.plugin && ldr_plugin_import) { // the plugin service run counts the plugin's calls by name + // A plugin's calls out of its own code are counted by name (plugin_init.c plugin_import), so the plugin check can + // judge what its init reached. A JUMP_SLOT whose symbol the plugin defines itself is no call out: a plugin built + // with default visibility calls its own exported functions through its PLT, such as the std::vector + // constructor of Challenge Mode's Enemy Health Regeneration (exefs subsdk8), and it binds to that definition as + // any other own symbol. A host override of the name still wins and stays counted. + int own_code = sym_defined(m, si) && !hostfn_override(name); + if (jump && m->pub.plugin && ldr_plugin_import && !own_code) { uint64_t to = (f = hostfn_override(name)) ? hostfn_register(name, f) : guest; if (!to) to = hostfn_register(name, unresolved_stub); r = (Res){hostfn_register_observer(name, ldr_plugin_import, to), RES_OBSERVER}; diff --git a/tests/exefs_plugins_test.py b/tests/exefs_plugins_test.py index 727b161c..318500e5 100644 --- a/tests/exefs_plugins_test.py +++ b/tests/exefs_plugins_test.py @@ -452,6 +452,26 @@ class Reach(unittest.TestCase): svcs, imports, _, _, _ = xp.reach(img, self.BASE, 0x200, [self.BASE], {self.BASE + 0x80: 'malloc'}) self.assertEqual((svcs, imports), (set(), {'malloc': 1})) + def test_own_function_through_plt_is_followed(self): + # bl plt; ret. The PLT stub at 0x80 binds to the plugin's own function at 0x100: svc 0x40; ret + img = bytearray(code([b(self.BASE, self.BASE + 0x80, True), RET_W])) + struct.pack_into(' constructor of Challenge Mode's Enemy Health Regeneration).""" + slots = {} + for off, typ, sym, _ in nso.relocs: + if typ == R_AARCH64_JUMP_SLOT: + name, _, shndx, value, _ = nso.syms[sym] + slots[off] = base + value if shndx else name out = {} for o in range(0, text_end - 16, 4): w0, w1, _, w3 = struct.unpack_from('<4I', img, o) @@ -499,6 +506,10 @@ def reach(img, base, text_end, roots, plt, stubs=()): if a in seen: break if a in plt: + if isinstance(plt[a], int): # the plugin's own function behind its PLT: the path goes on there + seen.add(a) + a = plt[a] + continue imports[plt[a]] = imports.get(plt[a], 0) + 1 break if not base <= a < base + text_end: