decomp(nhttp): distinguish raw token bytes from signed folds #1063

Merged
coah80 merged 1 commits from agent/bittle/nhttp-token-review into main 2026-10-03 06:03:32 +00:00
coah80 commented 2026-10-03 06:02:48 +00:00 (Migrated from github.com)

Partial reconstruction

Keep the left raw byte in its native word-sized lifetime, and make the right input's byte-load/signed-fold boundary explicit. The target reads right before left, preserves raw left separately from its signed folded result, and sign-extends that raw byte again for NUL/space termination. Only these two source lines change.

  • compareToken: 98.844444% → 99.73333%, still 45/45 instructions
  • Unit: 99.88612% → 99.9573%
  • All 12 exact functions, 1,864 matched code bytes and 112/112 data bytes preserved

The sole remaining mismatch is the order of two independent initial li instructions (r9=0 and r7=0x5a), both before use. No exact or linking claim.

Independent verification

Base e3095dfb979ded66d2b6a71228563066c5445f5a; tested tree c5fcaca90a.

  • Full 43U build/progress/report/DOL passed; complete 1,027-unit report changes only this function's fuzzy score, no regressions
  • All 256 original PPC carry-based fold values and 65,536 byte pairs checked, including actual right-before-left read traces and multi-byte termination
  • 75,536 production-C token vectors against independent reference, baseline and candidate
  • 95,504 ASan/UBSan byte-pair/token/aliased-overlapping-input cases; inputs preserved, leak detection disabled under ptrace
  • High-bit bytes retain their value through folding and compare equal only to the same byte
  • Independent instruction comparison confirms only the two commuting constant-load positions differ; all 13 other functions and allocated data unchanged, 12 exact functions checked
  • Pool 1/1 identical; literal audit all 14 functions, no candidates/skips/errors
  • DOL SHA1 26116613f624061ba99c8d1a299aaa6efa85670d; worktree/diff checks pass

Details: tools/decomp-assist/allhands-nhttp-token-byte-roles.attempts.md. No new helper, shared header, compiler setting or linking flag.

Note

Fix signed byte handling in nhttp NHTTPi_compareToken

In NHTTP_stdlib_RVL.c, NHTTPi_compareToken now loads the right input byte as u8 and converts it through s8 before calling LowerCase, matching the explicit conversion already used for the left byte. The raw left-byte temporary is widened from u8 to u32; the later signed-byte termination test is unchanged. Adds a recovery report in allhands-nhttp-token-byte-roles.attempts.md covering validation and build/hash gates.

Macroscope summarized a3e522c.

## Partial reconstruction Keep the left raw byte in its native word-sized lifetime, and make the right input's byte-load/signed-fold boundary explicit. The target reads right before left, preserves raw left separately from its signed folded result, and sign-extends that raw byte again for NUL/space termination. Only these two source lines change. - compareToken: 98.844444% → 99.73333%, still 45/45 instructions - Unit: 99.88612% → 99.9573% - All 12 exact functions, 1,864 matched code bytes and 112/112 data bytes preserved The sole remaining mismatch is the order of two independent initial li instructions (r9=0 and r7=0x5a), both before use. No exact or linking claim. ## Independent verification Base e3095dfb979ded66d2b6a71228563066c5445f5a; tested tree c5fcaca90aee37fe156186994f74910b018a2d65. - Full 43U build/progress/report/DOL passed; complete 1,027-unit report changes only this function's fuzzy score, no regressions - All 256 original PPC carry-based fold values and 65,536 byte pairs checked, including actual right-before-left read traces and multi-byte termination - 75,536 production-C token vectors against independent reference, baseline and candidate - 95,504 ASan/UBSan byte-pair/token/aliased-overlapping-input cases; inputs preserved, leak detection disabled under ptrace - High-bit bytes retain their value through folding and compare equal only to the same byte - Independent instruction comparison confirms only the two commuting constant-load positions differ; all 13 other functions and allocated data unchanged, 12 exact functions checked - Pool 1/1 identical; literal audit all 14 functions, no candidates/skips/errors - DOL SHA1 26116613f624061ba99c8d1a299aaa6efa85670d; worktree/diff checks pass Details: tools/decomp-assist/allhands-nhttp-token-byte-roles.attempts.md. No new helper, shared header, compiler setting or linking flag. <!-- Macroscope's pull request summary starts here --> <!-- Macroscope will only edit the content between these invisible markers, and the markers themselves will not be visible in the GitHub rendered markdown. --> <!-- If you delete either of the start / end markers from your PR's description, Macroscope will append its summary at the bottom of the description. --> > [!NOTE] > ### Fix signed byte handling in `nhttp` `NHTTPi_compareToken` > In [NHTTP_stdlib_RVL.c](https://github.com/coah80/wii-ipl/pull/1063/files#diff-451176525fe0c24879eb5db3b3e1156fa67ab292110f71f6ce1991a868d61aff), `NHTTPi_compareToken` now loads the right input byte as `u8` and converts it through `s8` before calling `LowerCase`, matching the explicit conversion already used for the left byte. The raw left-byte temporary is widened from `u8` to `u32`; the later signed-byte termination test is unchanged. Adds a recovery report in [allhands-nhttp-token-byte-roles.attempts.md](https://github.com/coah80/wii-ipl/pull/1063/files#diff-eb17f82462e62bc0945d13757e9578cf69428453f1feba959826738b032ea6ca) covering validation and build/hash gates. > > <!-- Macroscope's review summary starts here --> > > <sup><a href="https://app.macroscope.com">Macroscope</a> summarized a3e522c.</sup> > <!-- Macroscope's review summary ends here --> > <!-- Macroscope's pull request summary ends here -->
coah80 commented 2026-10-03 06:03:29 +00:00 (Migrated from github.com)

Reviewed and merged: rebased on main, full build ok, DOL sha1 26116613f624061ba99c8d1a299aaa6efa85670d, 0 regressions, 0 forbidden patterns.

Reviewed and merged: rebased on main, full build ok, DOL sha1 26116613f624061ba99c8d1a299aaa6efa85670d, 0 regressions, 0 forbidden patterns.
Sign in to join this conversation.