Skip to content

Exefs mods: patches may write into the rest of the .text's last page (code caves) - #150

Closed
RootChad wants to merge 1 commit into
mainfrom
exefs-code-cave
Closed

RootChad wants to merge 1 commit into
mainfrom
exefs-code-cave

Conversation

@RootChad

Copy link
Copy Markdown
Collaborator

Discord #issues, 19/11 ("exefs patches not applying according to log", "exefs mods dont seem to work"): Always-On Rupee Counter, Faster Dash and HUD of Time were left out, "in the gap between two segments".

Why: the game's .text ends at 0x3c461d0 and its .rodata starts at 0x3c47000. The console maps the code a page at a time, so the rest of that page exists and is executable; these mods put their own code there (a code cave), which emulators accept. nx2/exefs_mods.py treated it as a gap and left the whole patch out.

Change (nx2/exefs_mods.py):

  • A write in [.text end, min(page end, .rodata start)) is applied: the patched copy's .text grows to cover it (zeros up to the patch, in the game's and the copy's bytes alike, so only the patch's bytes count as changed), and its size in the NSO header (0x18 + 0x10*i) is written with it. The lift then translates the cave's code with the rest (nso.py code_range).
  • A write past that page, or anywhere else outside the segments, is still left out whole; one that starts in the page and runs past it now says ".text's last page, and goes past its end".

Tests: nx2/test_exefs_mods.py CodeCave: the cave applied, the copy's .text 0x1d40 → 0x1e08 with its SHA-256 made again, the description counting only the patch's bytes, a write across the page end left out. 27 tests pass (1 skipped).

Not verified: no game build with these mods yet (needs the mods and a full lift + compile).

🤖 Generated with Claude Code

…(code caves)

Discord, 19/11 ("exefs patches not applying according to log"): Always-On Rupee Counter, Faster Dash and HUD of Time were
left out, "in the gap between two segments". The game's .text ends at 0x3c461d0 and its .rodata starts at 0x3c47000: the
console maps the code a page at a time, so the rest of that page is there and executable, and those mods put their own code
in it, as emulators let them. Such a write is applied now: the patched copy's .text is made that much longer (zeros up to
the patch, the game's and the copy's alike, so only the patch's bytes count as changed) and its size in the header with it,
so the translation takes the cave's code with the rest (nso.py code_range). A write past the page, or anywhere else
outside the segments, is still left out whole; one that starts in the page and runs past it says so.

Tests: test_exefs_mods.py CodeCave (the cave applied, the .text 0x1d40 -> 0x1e08 in the copy, its SHA-256 made again, a
write across the page end left out); the 27 tests pass. Not yet tried on a game build with those mods.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pixl27

pixl27 commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Merged into 0.7.9.3 (https://github.com/pixl27/ProjectReLink/releases/tag/v0.7.9.3), through the hotfix branch rather than this pull request, with your authorship kept in the commit (Co-authored-by). Thank you, RootChad.

@pixl27 pixl27 closed this Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants