"""tools/exefs_patches.py on modules it makes itself: code writes become sites, data writes become runs of the data file as emulators apply a patch file before the dynamic linker (plain bytes, DT_RELR words rebased, writes into words an explicit-addend relocation fills dropped), the writes it refuses (outside the image, into the linker's tables or a lazily bound pointer), the status and data files, and the check after the lift against the bytes recomp/gen.py lists in folded.txt, with gen.py run on a module with one jump table. No game files. Run with .venv (lz4 and numpy, as recomp/): python tests/exefs_patches_test.py """ import struct import subprocess import sys import tempfile import unittest from pathlib import Path ROOT = Path(__file__).resolve().parent.parent sys.path.insert(0, str(ROOT / 'tools')) import exefs_patches as ep # noqa: E402 BUILD_ID = bytes.fromhex('0123456789abcdef') + bytes(24) BID_NAME = '0123456789ABCDEF' # an IPS file name may leave the build id's trailing zeros out MOV_W8_100, MOV_W8_200, RET = 0x52802008, 0x52804008, 0xD65F03C0 R_RELATIVE, R_GLOB_DAT, R_JUMP_SLOT = 1027, 1025, 1026 def nso(text, ro, data, bss=0x1000): """An uncompressed NSO with .text at 0, .rodata at 0x1000 and .data at 0x2000.""" segs = [(0x0, text), (0x1000, ro), (0x2000, data)] hdr = bytearray(0x100) hdr[0:4] = b'NSO0' off = 0x100 for i, (mem, d) in enumerate(segs): struct.pack_into('