"""recomp/layout.py with and without mod plugins, and tools/exefs_plugins.py's check of a plugin service run record: a synthetic exlaunch-shaped record with one inline hook that passes, and one bad record per rule. No game files. Run with .venv (lz4 and numpy, as recomp/): python tests/exefs_plugins_test.py """ import json import struct import sys import tempfile import unittest from pathlib import Path ROOT = Path(__file__).resolve().parent.parent sys.path.insert(0, str(ROOT / 'tools')) sys.path.insert(0, str(ROOT / 'recomp')) import exefs_plugins as xp # noqa: E402 import layout # noqa: E402 from nso import Nso # noqa: E402 def nso(size_text, bss=0x1000): """An uncompressed NSO: .text of size_text bytes (b over MOD0's offset word), .rodata with MOD0 at 0x1000 past .text, .data with an empty .dynamic.""" text = bytearray(size_text) struct.pack_into('> 2) & 0x3FFFFFF def record(original=0x94000010, trampoline_first=None, stub=None, writes=None, **extra): """A record of one inline hook at main+SITE_OFF whose original is `original` (default bl main+SITE_OFF+0x40).""" site, stub_at, tramp = MAIN + SITE_OFF, PLUGIN + STUB_OFF, PLUGIN + TRAMP_OFF img = bytearray(0x14000) words = stub or [xp.STUR_X30, b(stub_at + 4, PLUGIN + IMPL_OFF, True), xp.LDUR_X30, b(stub_at + 12, tramp)] struct.pack_into('<4IQ', img, STUB_OFF, *words, PLUGIN + CB_OFF) if trampoline_first is None: rel = xp.pc_relative(original, site) trampoline_first = (b(tramp, rel[1], True) if rel and rel[0][0] == 'b' else original) struct.pack_into('