Skip to content

host/exefs: apply mods' IPS, IPS32 and pchtxt patches - #3158

Open
Eriksrevenge1 wants to merge 5 commits into
seedds:mainfrom
Eriksrevenge1:pr/mods-exefs
Open

Eriksrevenge1 wants to merge 5 commits into
seedds:mainfrom
Eriksrevenge1:pr/mods-exefs

Conversation

@Eriksrevenge1

@Eriksrevenge1 Eriksrevenge1 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Tests: t_exefs (IPS, IPS32, pchtxt: runs, offset shifts, endianness, @enabled/@disabled groups, build ID names), the host build, test_docs, test_settings.
  • Games run: The Legend of Zelda: Ocarina of Time (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 as DM_EXEFS_PATCHES folders: 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).
  • Devices and OS: Apple M6 Mac mini, macOS 27.0.1, Xcode 27.2
  • Not run: lint_c locally (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, then nn::diag abort: Result 0xe15. Its code finds nn::fs::MountSdCard in the sdk module at run time and calls the address (sdk+0x10F0C0 on this build; main does 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: MountSdCard and MountSdCardForDebug mount $DM_SDCARD (default $DM_ROOT/sdmc, made at the first mount; the iOS app sets Documents/sdmc); IsSdCardInserted is true.
  • hle_exefs.c: when patches were applied, each take-over for fsp-srv (its reason starts fsp-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_unbound lists the take-overs no relocation bound.

Checked:

  • Ocarina of Time 1.1.1, Mac app built from this branch's change, bench save: 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.
  • t_exefs, the host build, test_docs, test_env_switches. Not run: lint_c locally (no LLVM release here; CI runs it).
  • Open, recorded in the game note: some of Fast Travel's menu letters are drawn incompletely; being traced.

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 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, and code_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.py applies DM_EXEFS_PATCHES before 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.py keys the rewrite on the patch files; pack_app.py and build_ipa.sh pack the table, so code patches also work on the iPhone.
  • hle_exefs.c skips 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_c locally (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

  • The finding is in its docs/reference entry or game note, and python3 dm/tools/docs_symptoms.py was run
  • No game files, keys or data extracted from a game in the change or the attachments

Eriksrevenge1 added a commit to Eriksrevenge1/cartridge that referenced this pull request Nov 21, 2026
…dds#3158)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added host The Horizon host: SVCs, services, threads, memory (dm/host) docs Documentation game: 0400486024DEC000 A game ios The iPhone and iPad app (dm/ios) labels Nov 21, 2026
Eriksrevenge1 pushed a commit to Eriksrevenge1/cartridge that referenced this pull request Nov 22, 2026
…edds#3158)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Eriksrevenge1 pushed a commit to Eriksrevenge1/cartridge that referenced this pull request Nov 22, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added rewriter The NSO rewriter and per-build patches packing Building an IPA or a Mac app: the NSP script, extraction, the shader split, the packers mac The Mac front end and app (dm/mac, front_mac.m) tools Tools and scripts (dm/tools, scripts) labels Nov 22, 2026
@Eriksrevenge1

Copy link
Copy Markdown
Contributor Author

Rebased on current main (a README conflict only); t_exefs, test_exefs_patch, test_docs, test_patches and the host build pass.

@Eriksrevenge1

Copy link
Copy Markdown
Contributor Author

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.

@Eriksrevenge1

Copy link
Copy Markdown
Contributor Author

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.

@Eriksrevenge1

Copy link
Copy Markdown
Contributor Author

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.

@Eriksrevenge1

Copy link
Copy Markdown
Contributor Author

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.

@Eriksrevenge1

Copy link
Copy Markdown
Contributor Author

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).

ProfDrLuigi pushed a commit to ProfDrLuigi/nxnative that referenced this pull request Nov 25, 2026
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.
@Eriksrevenge1

Copy link
Copy Markdown
Contributor Author

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).

@Eriksrevenge1

Copy link
Copy Markdown
Contributor Author

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).

@Eriksrevenge1

Copy link
Copy Markdown
Contributor Author

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).

@Eriksrevenge1

Copy link
Copy Markdown
Contributor Author

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).

@Eriksrevenge1

Copy link
Copy Markdown
Contributor Author

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).

@Eriksrevenge1

Copy link
Copy Markdown
Contributor Author

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.

Eriksrevenge1 and others added 5 commits November 28, 2026 18:27
…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>
@Eriksrevenge1

Copy link
Copy Markdown
Contributor Author

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation game: 0400486024DEC000 A game host The Horizon host: SVCs, services, threads, memory (dm/host) ios The iPhone and iPad app (dm/ios) mac The Mac front end and app (dm/mac, front_mac.m) packing Building an IPA or a Mac app: the NSP script, extraction, the shader split, the packers rewriter The NSO rewriter and per-build patches tools Tools and scripts (dm/tools, scripts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants