Repository navigation
host/exefs: apply mods' IPS, IPS32 and pchtxt patches - #3158
Eriksrevenge1 wants to merge 5 commits into
Conversation
…dds#3158) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…edds#3158) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Rebased on current main (a README conflict only); t_exefs, test_exefs_patch, test_docs, test_patches and the host build pass. |
1ebae3e to
6b7aa2b
Compare
|
Fixed the ruff and pyright ratchet failure (6 new findings in exefs_patch.py and its test); lint_python shows 0 new, and test_exefs_patch and test_docs pass. |
|
Rebased on current main (one conflict in build_ipa_from_nsp.py's rewrite key: kept main's mod_layout.py and added exefs_patch.py); test_exefs_patch, test_docs, test_patches, test_env_switches pass and the host builds. The clang-tidy failure was main's baseline at the time. Not run: GPU and game checks. |
eee4f09 to
39a99b6
Compare
|
Fixed the Tool tests failure: patch_nso.py now writes .exefs.tsv for every module, so test_nso_match no longer finds no output folder for a build that lost nothing; it checks that no match.tsv is written instead. Rebased on current main; all dm/tools/tests pass here except test_vk_* (needs spirv-as). Not run: GPU and game checks. |
39a99b6 to
040523c
Compare
|
Rebased on current main: main.c (beside the new dm_exl_fake_rtld call), main.m (beside DM_ALBUM_DIR) and patch_nso.py (beside the ALIAS_APPLIED check) conflicted only next to main's additions; both sides kept, the mods' code patches still applied before the cuts. The host builds; t_exefs, test_exefs_patch, test_nso_match, test_patches, test_docs and test_env_switches pass. |
040523c to
73e89bd
Compare
73e89bd to
04e7a27
Compare
|
Rebased on current main (39 commits behind); the CI failures came from the old merge base. The host builds; host tests, test_docs, test_env_switches and test_patches pass (test_exefs_patch and test_nso_match too on #3158). Not run: GPU and game checks (no Metal 4 here). |
Integrate seedds/nxnative PR seedds#3158. Load enabled mod patches before guest execution, checking their module build IDs, bounds, overlaps and rewriter-changed words before applying any record. Validation: native ExeFS parser fixtures and all 5 Python ExeFS tests pass. App rebuild and runtime validation remain pending.
04e7a27 to
5d78b9b
Compare
|
Rebased on current main: build_ipa_from_nsp.py conflicted beside the new _nrr_files (both kept). The host builds; test_exefs_patch, test_nso_match, test_patches and test_docs pass; test_env_switches fails the same way on main's tree. Not run: GPU and game checks (no Metal 4 here). |
5d78b9b to
a51c128
Compare
|
Rebased on current main: dm/host/tests/Makefile conflicted beside main's t_cheats rules (both kept). The host builds; t_exefs, test_exefs_patch, test_nso_match, test_patches, test_docs and test_env_switches pass. Not run: GPU and game checks (no Metal 4 here). |
|
Rebased on current main (25 commits behind); the ruff/pyright and Tool tests failures came from the old merge base: the lint ratchet shows 0 new findings and test_env_switches, test_docs, test_patches, test_exefs_patch and test_nso_match pass on the rebased tree. The host builds. Not run: GPU and game checks (no Metal 4 here). |
a51c128 to
1425095
Compare
1425095 to
8ce0c0a
Compare
|
Rebased on current main: docs/env_switches.tsv conflicted beside main's DM_SCREEN_MATCH row (both kept). The host builds; test_docs, test_env_switches, test_patches, test_exefs_patch and test_nso_match pass. Not run: GPU and game checks (no Metal 4 here). |
8ce0c0a to
788817c
Compare
|
Rebased on current main (9 commits behind); the Tool tests failure was test_dmsh_abi's nvn_mtl.m ratchet, which fails on main's tree too (not this change). The host builds; test_exefs_patch, test_nso_match, test_patches, test_docs and test_env_switches pass. Not run: GPU and game checks (no Metal 4 here). |
788817c to
9c0bb41
Compare
|
Rebased on current main. The ruff/pyright, clang-tidy and Tool tests failures came from main's own state at the old base (jump_solver.py and test_split_ktgl_zl.py, the NVN clang-tidy baseline), which main has since fixed (eeee07a, 6d7682b, ae7a692). The lint ratchet shows 0 new findings; test_exefs_patch, test_nso_match, test_env_switches, test_docs, test_patches and t_exefs pass. Not run: GPU and game checks. |
…odules A mod made of code patches (exefs/<build ID>.ips, exefs/*.pchtxt) did nothing: only RomFS folders were read. Atmosphère and the yuzu family patch the NSO before it is loaded; this host loads the rewriter's modules and maps their text executable and never writable, so there was no place to apply them. dm/host/hle_exefs.c applies them once, after the modules are loaded and relocated and before the game's first instruction, through a writable alias of the module (mach_vm_remap, as the cheat engine writes code). The folders come from DM_EXEFS_PATCHES=<dir>[:<dir>…], first mod first. Offsets count from the NSO header (IPS; pchtxt after its offset_shift); a file names its module by build ID (at least the first 8 bytes compared). A file is checked whole before any byte is written and refused whole, with a [RED] line, when it would touch a word the rewriter changed or moved (<module>.changed.tsv), reach past the image, or change a byte an earlier mod already patched differently (two mods that put code in the same padding). A mod whose exefs also holds a module or main.npdm is refused: its patches branch into code this host does not load. Not on the iPhone (signed code pages). Found on The Legend of Zelda: Ocarina of Time: Fast Travel's 17,183 pchtxt records and Bunny Hood Speed Boost's IPS32 file touch no word the rewriter changed; Fast Travel and L3 Sprint Toggle put code in the same padding, and the second is refused. Checked: t_exefs (IPS, IPS32, pchtxt: runs, offset shifts, endianness, @enabled/@disabled groups, build ID names), the host build, test_docs, test_settings. Front-ends: a front end that installs mods sets DM_EXEFS_PATCHES to the exefs folders of the mods that are on (docs/reference/rewriter.md). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…host; SD card mount Ocarina of Time's Fast Travel mod aborted when its menu opened: its code finds nn::fs::MountSdCard in the sdk module and calls the address, which main never imports, so the host's take-over (bound through imports) was bypassed and the SDK's definition opened fsp-srv and aborted (0xE15). - hle_fs.c: MountSdCard / MountSdCardForDebug mount $DM_SDCARD (default $DM_ROOT/sdmc, made at the first mount); IsSdCardInserted is true. The iOS app sets Documents/sdmc. - hle_exefs.c: when code patches are applied, each take-over for fsp-srv that no import bound gets its SDK definition's first 16 bytes replaced with a jump to the host (ldr x16, #8; br x16), through the module's alias; a start the rewriter changed is a [RED] line and left alone, one a mod patched is left alone. Only with code patches on, on the Mac. - loader.c: dm_force_unbound lists the unbound take-overs. Tested on Ocarina of Time (bench save copy): 38 definitions redirected, the menu opens and warps Hyrule Field → Kokiri Forest. Docs: rewriter.md entry, the game note, env_switches.tsv (DM_SDCARD), the symptom index. regress.py not run: the redirect happens only with code patches on, and the SD card functions only bind for games that call them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ting them Fast Travel's menu drew some letters as only their top rows: its blendMask (main+0x1dced28) keeps a glyph's height in w18, and the patch, applied at load after the rewriter, kept that use of x18, which the Apple kernel may change at any instruction. Code a mod adds was never rewritten (x18, system calls, timers, exclusive accesses). - dm/tools/exefs_patch.py: the host's IPS / IPS32 / pchtxt readers and folder rules in Python; code_words: the patched words reached from a hook site or a function entry (pacibsp, stp x29, x30, [sp, #-n]!) by fall-through and direct branches are code, the rest data a mod keeps between functions. - patch_nso.py applies DM_EXEFS_PATCHES before the cuts (a file writing into a cut or over another file's bytes is skipped, [RED]), adds the data words to its data blocks, and writes <module>.exefs.tsv (FNV-1a 64 of each baked file; written for every module). - build_ipa_from_nsp.py keys the rewrite on the patch files; pack_app.py and build_ipa.sh pack the table (code mods now work on the iPhone too). - hle_exefs.c skips baked files, logs a [RED] line for a baked file whose mod is off, still applies the others at load, and keeps the SDK fs redirect for baked patches. Checked: Fast Travel 1.4.0 Visited Patch: 13,621 code words, no word of its state chain (walked from its head) among them, every x18 use reached; in the game every letter draws and the patch reads "baked into main"; the NSP script's rewrite baked it (main.exefs.tsv). test_exefs_patch (new), t_exefs, test_docs, test_env_switches; host and Cartridge build. Front-ends: a front end that builds games passes DM_EXEFS_PATCHES (the enabled mods' exefs folders) to the build, and can ask for a rebuild when they change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
startswith and endswith take a tuple, the build-ID matches cannot be None, and the capstone tests assert it is loaded. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…rites, not a missing folder
9c0bb41 to
eb36d2d
Compare
|
Rebased on current main (26 commits behind): the Build check failure was t_pfv.m's mtl_sub_commit call against an older signature, which main has since changed. t_pfv builds now; the host builds; test_docs, test_env_switches, test_patches, test_exefs_patch and test_nso_match pass. The clang-tidy ratchet failure is main's own (the same on its tree). Not run: GPU and game checks (no Metal 4 here). |
What and why
A mod made of code patches (exefs/<build ID>.ips, exefs/*.pchtxt) did nothing: only RomFS folders were read. Atmosphère and the yuzu family patch the NSO before it is loaded; this host loads the rewriter's modules and maps their text executable and never writable, so there was no place to apply them.
dm/host/hle_exefs.c applies them once, after the modules are loaded and relocated and before the game's first instruction, through a writable alias of the module (mach_vm_remap, as the cheat engine writes code). The folders come from DM_EXEFS_PATCHES=<dir>[:<dir>…], first mod first. Offsets count from the NSO header (IPS; pchtxt after its offset_shift); a file names its module by build ID (at least the first 8 bytes compared). A file is checked whole before any byte is written and refused whole, with a [RED] line, when it would touch a word the rewriter changed or moved (<module>.changed.tsv), reach past the image, or change a byte an earlier mod already patched differently (two mods that put code in the same padding). A mod whose exefs also holds a module or main.npdm is refused: its patches branch into code this host does not load. Not on the iPhone (signed code pages).
Found on The Legend of Zelda: Ocarina of Time: Fast Travel's 17,183 pchtxt records and Bunny Hood Speed Boost's IPS32 file touch no word the rewriter changed; Fast Travel and L3 Sprint Toggle put code in the same padding, and the second is refused.
Checked
0400486024DEC000, 1.1.1), a Mac app built from this branch, fullscreen on a DELL S2725QC, about 2 minutes from a Hyrule Field save, with two GameBanana mods asDM_EXEFS_PATCHESfolders:exefs: Fast Travel/exefs/fast-travel-patch.pchtxt → main, 17183 writes, 227416 bytes,exefs: Bunny Hood Speed Boost/exefs/E0F3…3348.ips → main, 2 writes, 203 bytes,exefs: 2 patch files applied; no crash, no[RED]line, 60 fps (p50 16.72 ms).lint_clocally (no LLVM release installed here; CI runs it);regress.py check(no local game has a smoke route).Second commit: a mod's own calls to SDK file system functions, and the SD card
Fast Travel's menu (L3 + R3) aborted:
[RED] sf: the game connects to service fsp-srv itself, thennn::diag abort: Result 0xe15. Its code findsnn::fs::MountSdCardin the sdk module at run time and calls the address (sdk+0x10F0C0on this build;maindoes not import it), so the take-over, which the loader binds through imports (HLE_FORCE), was bypassed and the SDK's own definition opened fsp-srv, which the host never serves.hle_fs.c:MountSdCardandMountSdCardForDebugmount$DM_SDCARD(default$DM_ROOT/sdmc, made at the first mount; the iOS app setsDocuments/sdmc);IsSdCardInsertedis true.hle_exefs.c: when patches were applied, each take-over for fsp-srv (its reason startsfsp-srv) that no import bound has its SDK definition's first 16 bytes replaced with a jump to the host's function (ldr x16, #8; br x16; .quad), through the module's alias like a patch. Those definitions could only abort on this host. A start the rewriter changed is a[RED]line and left alone; one a mod patched is left alone. Only with patches applied, on the Mac.loader.c:dm_force_unboundlists the take-overs no relocation bound.Checked:
exefs: 38 SDK file system functions the game does not import now run in the host; the menu opens and warps (Hyrule Field → Kokiri Forest); no abort. Without mods nothing of this runs.regress.py check --baseline 27cdfcd8(this PR's first commit) on Ocarina of Time, Donkey Kong Bananza, Nintendo Switch 2 Welcome Tour, Xenoblade Chronicles 3 and Xenoblade Chronicles Definitive Edition (the local NVN games; the change reaches every game's loader and file system): PASS on all five, shaders and pipelines unchanged (42847, 23636, 6767 with 27 known interface notes, 27055, 16971). No boot runs: none of these has a smoke route.lint_clocally (no LLVM release here; CI runs it).Front-ends: a front end may set DM_SDCARD to a folder of its own for the SD card (default $DM_ROOT/sdmc).
Third commit: code patches baked into the modules before the rewrite
Fast Travel's menu drew some letters as only their top row or two: its drawing loop (
blendMask,main+0x1dced28) keeps a glyph's height inw18, and the patch, applied at load after the rewriter, kept that use of x18, which the Apple kernel may change at any instruction. Code a mod adds was never rewritten (x18, system calls, timers, exclusive accesses).dm/tools/exefs_patch.py: the host's IPS / IPS32 / pchtxt readers and folder rules in Python, andcode_words: patched words reached from a hook site (a word that replaced one of the module's instructions) or a function entry (pacibsp,stp x29, x30, [sp, #-n]!) by fall-through and direct branches are code; the rest are data a mod keeps between functions (Fast Travel's packed state chain).patch_nso.pyappliesDM_EXEFS_PATCHESbefore the cuts (a file writing into a cut or over another file's bytes is skipped with a[RED]line), adds the data words to its data blocks, and writes<module>.exefs.tsv(FNV-1a 64 of each baked file; written for every module).build_ipa_from_nsp.pykeys the rewrite on the patch files;pack_app.pyandbuild_ipa.shpack the table, so code patches also work on the iPhone.hle_exefs.cskips baked files at load, logs a[RED]line for a baked file whose mod is off, and still applies the others at load.Checked: Fast Travel 1.4.0 (Visited Patch): 13,621 code words, no word of its state chain (walked from its head) among them, every x18 use reached; every letter draws in the game, and the log reads "baked into main"; the NSP script's rewrite baked it (
main.exefs.tsv).test_exefs_patch(new),t_exefs,test_docs,test_env_switches; the host builds. Not run:lint_clocally (no LLVM release here; CI runs it).Front ends
Front-ends: a front end that installs mods sets DM_EXEFS_PATCHES to the exefs folders of the mods that are on (docs/reference/rewriter.md).
Docs
docs/referenceentry or game note, andpython3 dm/tools/docs_symptoms.pywas run