Repository navigation
Conversation
An NRO's text segment starts at offset 0 with the file's own header in
it (the start word, the MOD0 offset, NRO0 at +0x10, the segment table at
+0x20, the build ID at +0x40): Hades' EOSSDK-Switch-Shipping.nro has text
{0x0, 0xa41000} in its segment table. The rewriter scanned the text from
0, so a header word that decodes as a site counts as one: on Final
Fantasy X/X-2 HD Remaster the build ID read as "ldr x18,
#0xfffffffffff40370" and stopped the rewrite (LNPANDY/NX2Apple#14). The
segment table cannot give the bound, since it says 0.
code_start() is 0x80 for an NRO and 0 for an NSO; code_ranges() starts
no code range before it, and the function starts below it are dropped.
Both scans (the x18 words and the rewrite sites) walk those ranges.
An NSO's ranges are as before.
test_nro_code_start.py takes the two functions from patch_nso.py, as
test_jump_copies does, and checks them on a synthetic NRO laid out as
Hades' (a build ID word that decodes as an x18 load). Hades' EOS NRO
rewrites byte-identically before and after (patched.bin and every table;
its header holds no word that reads as a site). test_jump_copies,
test_nso_match, test_patches, test_spin_waits, test_tail_call and
test_size_prefixed_frames pass.
This was referenced Oct 27, 2026
v0lumehi
added a commit
to v0lumehi/NX2Apple
that referenced
this pull request
Oct 27, 2026
…skip as seedds/nxnative#397 9f7d421 restored the NRO header skip (issue LNPANDY#14) as a carrier, and its patcher put TEXT_LO into the site bound (starts = sorted(... TEXT_LO + TEXT_END)) 13 lines above TEXT_LO = segs[0][1]. Every rewrite of every game stopped there: "NameError: name 'TEXT_LO' is not defined", found building Hades from the launcher after it pulled main. The bound itself was also not the fix: an NRO's text segment starts at offset 0 with the header inside it (Hades' EOSSDK-Switch-Shipping.nro: text {0x0, 0xa41000}), so segs[0][1] is 0 and the header was still scanned. patch_patch_nso now applies seedds/nxnative#397 instead: code_start() is 0x80 for an NRO and 0 for an NSO, code_ranges() starts no code range before it, and TEXT_END keeps its meaning. When LNPANDY#397 is merged upstream, every hunk is found applied and the patcher can go. front_mac.m, patch_nso.py and Hades II's game.tsv had patchers but were not in PATCHED, so pr-scope refused a PR that touches them; they are in. Checked: Hades' main and sdk rewrite (exit 0, the step that failed); the patcher reproduces this tree from upstream's patch_nso.py and is idempotent; a sync run with --old = --new ends SYNC OK. test_nro_header now tests the behaviour (the header outside every code range, an NSO unchanged, each bound assigned before the scan uses it); test_jump_copies, test_nso_match, test_patches, test_spin_waits, test_tail_call, test_size_prefixed_frames, test_docs and test_env_switches pass.
LNPANDY
added a commit
to LNPANDY/NX2Apple
that referenced
this pull request
Oct 27, 2026
…tests behaviour (v0lumehi) patch_nso.py: every rewrite stops with a NameError on main (TEXT_LO); the NRO header skip as seedds/nxnative#397
seedds
added a commit
that referenced
this pull request
Oct 28, 2026
PR #397 correctly identifies instruction-like bytes in NRO metadata. Its linear-scan cutoff still lets per-function analysis reenter the header when code precedes the first unwind entry, failing with "jump table 44". Keep the shared data-block exclusion already on main and extend the real rewriter regression to cover this path. Document that both scans and function analysis must exclude metadata. The new test fails against the original PR and passes with the existing implementation; 108 related and documentation tests pass. Production code is unchanged. Refs #397 Co-authored-by: v0lumehi <[email protected]>
Owner
|
Thank you for tracing the rewrite failure to NRO metadata being treated as instructions and for documenting why the segment table alone cannot exclude the header.
I'm closing this PR as already addressed on |
This was referenced Oct 28, 2026
Know-It-All-Brother
pushed a commit
to Know-It-All-Brother/nxnative
that referenced
this pull request
Nov 9, 2026
PR seedds#397 correctly identifies instruction-like bytes in NRO metadata. Its linear-scan cutoff still lets per-function analysis reenter the header when code precedes the first unwind entry, failing with "jump table 44". Keep the shared data-block exclusion already on main and extend the real rewriter regression to cover this path. Document that both scans and function analysis must exclude metadata. The new test fails against the original PR and passes with the existing implementation; 108 related and documentation tests pass. Production code is unchanged. Refs seedds#397 Co-authored-by: v0lumehi <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An NRO's text segment starts at offset 0, and the file's own header lies inside it: the start word, the MOD0 offset,
NRO0at +0x10, the segment table at +0x20 and the build ID at +0x40.patch_nso.pyscanned the text from 0, so any header word that decodes as a rewrite site counts as one. On Final Fantasy X/X-2 HD Remaster the build ID read asldr x18, #0xfffffffffff40370and stopped the rewrite (LNPANDY/NX2Apple#14).The segment table cannot give the bound. Hades'
EOSSDK-Switch-Shipping.nro, for example, reads:Change
code_start(d): 0x80 for an NRO, 0 for an NSO.code_ranges(data_blocks, text_end, start): the gaps between the data blocks, as before, but none starting beforestart. The function starts below it are dropped.Checked
dm/tools/tests/test_nro_code_start.pytakes the two functions frompatch_nso.pyitself, astest_jump_copiesdoes. It checks them on a synthetic NRO laid out like Hades', with a build ID word that decodes as an x18 load: the bound is 0x80 although the segment table says 0, no code range holds that word, and NSO ranges are unchanged.patched.binand every table are the same; its header has no word that reads as a site.test_jump_copies,test_nso_match,test_patches,test_spin_waits,test_tail_callandtest_size_prefixed_framespass.host_preload,MAX_MOD), which this does not touch.Context
The NX2Apple fork had fixed this in its own copy with
TEXT_LO = segs[0][1]. Because that offset is 0 for an NRO, the fix never took effect; it is discussed in LNPANDY/NX2Apple#51. Fixed here, the fork can drop its carrier forpatch_nso.pyand take this file with the sync.