From 8e8f6528b88e02052512fbb968e33df4a91beab5 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Sat, 3 Oct 2026 00:48:33 -0500 Subject: [PATCH 1/3] decomp(jpeg): scope RGB565420 edge pixel values --- .../src/texturecvtr/Texture_MCUtoRGB565.c | 23 +++-- .../allhands-jpeg-pixel-lifetime.attempts.md | 99 +++++++++++++++++++ 2 files changed, 110 insertions(+), 12 deletions(-) create mode 100644 tools/decomp-assist/allhands-jpeg-pixel-lifetime.attempts.md diff --git a/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565.c b/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565.c index d61c700d..6165aa37 100644 --- a/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565.c +++ b/libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGB565.c @@ -575,12 +575,9 @@ static void TMCJPEGDEC_converterYUV420toRGB565edge(TMCCJPEGDecWork* work, s32 x, s32 xEnd; s8 cbValue; s32 yEnd; - s32 red; - s32 blue; u32 tileWidth; s32 height; TMCCJPEGDecState* state; - s32 green; s32 lumaSkip; s32 chromaSkip; s32 redOffset; @@ -619,16 +616,18 @@ static void TMCJPEGDEC_converterYUV420toRGB565edge(TMCCJPEGDecWork* work, s32 x, greenOffset = -(cbValue * 88 + crValue * 183) >> 8; blueOffset = (cbValue * 454) >> 8; } - blue = *luminance++; - red = blue + redOffset; - green = blue + greenOffset; - blue = blue + blueOffset; - if ((blue | red | green) >> 8) { - blue = blue > 255 ? 255 : blue < 0 ? 0 : blue; - green = green > 255 ? 255 : green < 0 ? 0 : green; - red = red > 255 ? 255 : red < 0 ? 0 : red; + { + s32 value = *luminance++; + s32 red = value + redOffset; + s32 blue = value + blueOffset; + s32 green = value + greenOffset; + if ((blue | red | green) >> 8) { + blue = blue > 255 ? 255 : blue < 0 ? 0 : blue; + green = green > 255 ? 255 : green < 0 ? 0 : green; + red = red > 255 ? 255 : red < 0 ? 0 : red; + } + output[(column & 3) + (((column >> 2) + tileRow) << 4)] = ((blue & 0xF8) >> 3) + ((red & 0xF8) << 8) + ((green & 0xFC) << 3); } - output[(column & 3) + (((column >> 2) + tileRow) << 4)] = ((blue & 0xF8) >> 3) + ((red & 0xF8) << 8) + ((green & 0xFC) << 3); } luminance += lumaSkip; if (y & 1) { diff --git a/tools/decomp-assist/allhands-jpeg-pixel-lifetime.attempts.md b/tools/decomp-assist/allhands-jpeg-pixel-lifetime.attempts.md new file mode 100644 index 00000000..b8812b69 --- /dev/null +++ b/tools/decomp-assist/allhands-jpeg-pixel-lifetime.attempts.md @@ -0,0 +1,99 @@ +# RGB565420 edge pixel lifetime + +Base: `57ccda3883537a308568c03924af2cebf2d8a789`, branch +`agent/bittle/jpeg-pixel-lifetime`, 43U only. One authorized source trial; +no additional variants, header/configuration changes, or remote writes. + +## Source reconstruction + +The existing exact RGB565444 sibling has a pixel-scoped independent luminance +value and pixel-scoped RGB locals. Apply that lifetime boundary to RGB565420 +edge, retaining its current chroma sampling and every address/step expression. +Initialize red, blue, then green, matching original instructions 60..62 after +the luminance load at 58. The original overflow reduction at 63..64 is +blue/red/green; that existing source expression remains unchanged, as do clamps +and the RGB565 packing expression. No declaration-permutation search was used. + +Chroma products are bounded signed integer arithmetic. For signed byte Cb/Cr, +red/green/blue offsets stay within [-180,178], [-135,135], and [-227,225]. Adding +an unsigned luminance byte cannot overflow s32. There are no floating-point +operations. Removing the blue variable's temporary ownership of luminance and +limiting RGB lifetimes to the pixel does not add or remove input reads or output +writes. The arithmetic order changes only among independent initialized scalars. + +The historical tex1 log records a different sibling-template trial at +96.00877%, discarded for being nonexact. Its original source is unavailable; +this candidate is an independently measured reconstruction, not that artifact. + +## Measured result + +- `TMCJPEGDEC_converterYUV420toRGB565edge`: 94.692986 -> 95.570175% +- 114/114 instructions; ctxdiff differences 73 -> 65 +- Unit fuzzy: 96.5207 -> 96.58538% +- Exact functions remain 7/13; matched code remains 2648/6184 bytes +- No allocated non-code sections in source or original; data remains 100% +- Global fuzzy: 99.71608 -> 99.7162%; all exact/link/data totals unchanged +- No function- or unit-level regressions across the full 1027-unit report +- Only this function's body differs from the saved baseline object; all twelve + sibling function bodies are byte-identical to baseline +- Seven existing exact functions remain objdiff 100% and ctxdiff zero + +This is partial fuzzy progress, not an exact match or linking result. + +## Validation + +Pool checks before the trial and after the full build: identical, zero strings. +The full 43U build passed. `ninja build/43U/ok` passed with no work pending. +DOL SHA1: `26116613f624061ba99c8d1a299aaa6efa85670d`. +`git diff --check` passed. Literal-reference audit: no candidates/errors; +twelve functions analyzed, unchanged nonexact setter skipped for unequal size. + +A focused independent scalar pixel model was compared with the compiled +candidate, original, and saved baseline through the existing bounded PPC +interpreter. All 8,721 vectors passed (26,163 object executions): + +- 808 cases covering every valid edge width and height for scales 1/2/4/8, + both starting-row parities, and even-column residues 0/2 within a tile +- 256 cases covering both width/height selection branches, zero/full/partial + extents, row parity and column residues +- 6,400 saturation cases: all 256 luminance values crossed with all Cb/Cr + pairs from {-128,-1,0,1,127} +- 1,257 aligned input/output overlaps; every output byte stays inside the + actual 0x184-byte convBuf backing array and state remains separate + +All 114 instructions in candidate, original, and baseline were exercised. +Every non-stack byte, including guards, was compared against the scalar model. +The interpreter also checked LR, stack pointer, and GPR14..GPR31 preservation. +Odd input x is excluded by the existing entry assertion; valid multi-pixel +rows exercise both odd/even column paths. Unsupported scales and invalid +pointers are not asserted valid API inputs. These are bounded interpreter +checks, not formal equivalence or Wii runtime validation. The existing integer +interpreter's limitations remain; no FPU, MMIO, exception or timing model is used. + +## Reproduction artifacts + +Local evidence directory: `/tmp/jpeg-pixel-lifetime/`. +- `baseline-report.json`, `baseline-rgb.o`: saved before source edits +- `candidate-report.json`, `candidate.ctx`: focused candidate measurements +- `full-build.log`: full build output +- `audit.py`, `audit-results.json`, `audit-output.txt`: independent pixel model + and targeted differential evidence + +The test script reads the current candidate object, current original object, +and saved baseline object. It does not write repository source or original +binary bytes. Re-run from this worktree: + +```sh +PYTHONPATH=../local-tools ../.venv/bin/python /tmp/jpeg-pixel-lifetime/audit.py +``` + +Build configuration uses cached approved tools: + +```sh +../.venv/bin/python configure.py --version 43U \ + --wrapper ../toolchain/wibo-build/wibo --compilers build/compilers \ + --dtk build/tools/dtk --objdiff build/tools/objdiff-cli \ + --sjiswrap build/tools/sjiswrap.exe +WIBO_SJIS_MISSING_IMPORTS=1 ../.venv/bin/ninja +build/tools/objdiff-cli report generate -p . -o build/43U/report.json -f json +``` -- 2.49.1 From d54f8be29aef9b6221b1bc27a5bd60745ab362e4 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Sat, 3 Oct 2026 00:51:39 -0500 Subject: [PATCH 2/3] decomp(nwc24): scope writable task validation (#1058) --- libs/RevoEX/src/nwc24/NWC24Download.c | 32 ++++++- ...llhands-nwc24-write-permission.attempts.md | 89 +++++++++++++++++++ 2 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 tools/decomp-assist/allhands-nwc24-write-permission.attempts.md diff --git a/libs/RevoEX/src/nwc24/NWC24Download.c b/libs/RevoEX/src/nwc24/NWC24Download.c index 2c1e4d2f..802941f0 100644 --- a/libs/RevoEX/src/nwc24/NWC24Download.c +++ b/libs/RevoEX/src/nwc24/NWC24Download.c @@ -728,6 +728,34 @@ static inline NWC24Err UpdateDlTaskAccessTime(NWC24DlTask* dlTask) { return result; } +static inline NWC24Err ValidateWritableDlTask(const NWC24DlTask* dlTask) { + const DlTaskData* task = (const DlTaskData*)dlTask; + DlTaskListHeader* header = GetCachedDlHeader(); + if (task == NULL) { + return NWC24_ERR_INVALID_VALUE; + } + if (header == NULL) { + return NWC24_ERR_LIB_NOT_OPENED; + } + if (!NWC24IsMsgLibOpenedByTool() && !IsDlTaskOwner(task->appId)) { + BOOL allowed = FALSE; + u32 flags = task->flags; + u16 groupId = task->groupId; + if (flags & 0x40) { + if (groupId == NWC24GetGroupId()) { + allowed = TRUE; + } + } + if (!allowed) { + return NWC24_ERR_PROTECTED; + } + } + if (task->id != 0xffff && task->id >= header->maxTaskCount) { + return NWC24_ERR_INVALID_VALUE; + } + return NWC24_OK; +} + NWC24Err NWC24UpdateDlTask(NWC24DlTask* dlTask) { DlTaskData* task = (DlTaskData*)dlTask; DlTaskListHeader* header; @@ -735,13 +763,13 @@ NWC24Err NWC24UpdateDlTask(NWC24DlTask* dlTask) { OSTime universalTime; NWC24Err result; - result = ValidateDlTask(dlTask, TRUE); + result = ValidateWritableDlTask(dlTask); if (result != NWC24_OK) { return result; } taskId = task->id; if (taskId == 0xffff || taskId >= GetCachedDlHeader()->maxTaskCount) { return NWC24_ERR_INVALID_VALUE; } result = UpdateDlTaskAccessTime(dlTask); if (result < NWC24_OK) { return result; } - result = ValidateDlTask(dlTask, TRUE); + result = ValidateWritableDlTask(dlTask); if (result == NWC24_OK) { task->unknown_0x20 = 0; task->unknown_0x1a = 0; diff --git a/tools/decomp-assist/allhands-nwc24-write-permission.attempts.md b/tools/decomp-assist/allhands-nwc24-write-permission.attempts.md new file mode 100644 index 00000000..45d9fbb9 --- /dev/null +++ b/tools/decomp-assist/allhands-nwc24-write-permission.attempts.md @@ -0,0 +1,89 @@ +# NWC24 writable-task validation recovery, 2026-10-03 + +Base: `57ccda38`. One bounded source trial in +`libs/RevoEX/src/nwc24/NWC24Download.c`; 43U only. This is a partial +instruction-structure gain, not an exact match, behavior fix or linking change. + +## Recovery screening and source rationale + +Older exact-only attempts had restored valid partials: pk2 records a task-view +permission helper at 98.695656%; structural round12 records more extensive +permission/access/retry forms up to 99.48617%. Their temporary source artifacts +are absent in this workspace. This candidate was reconstructed from current +source and original instructions, not copied from an unavailable best snapshot. +Only the smallest writable validation operation was tried; no retry helper, +AddTaskInternal, compareToken or ATERM variant was mixed into it. + +The new private `ValidateWritableDlTask(const NWC24DlTask*)` returns the same +NWC24Err as the existing validator with write=TRUE. It reads the actual task +view and snapshots its cached header. In the owner-mismatch fallback, it reads +flags and the u16 group ID into operation-local values, initializes a real +permission result false, and makes it true only when bit 0x40 permits the group +query and the IDs match. These values belong to that validation operation; +none is dummy state, an optimization barrier or artificial spill. + +Only NWC24UpdateDlTask's two existing writable validation calls use this helper. +The shared validator and all other callers stay unchanged. The second call +reacquires the current header and repeats tool/owner/group permission checks +after the time update. Its failure deliberately suppresses only the two reset +stores, rather than returning early; the original retry/store behavior remains. +No object is allocated, freed or written by the new helper. No pointer escapes, +public type changes, flags, assembly, padding or forced register use is added. + +## Original call/data-flow checks + +- Target and candidate place all nine direct calls at identical instruction + indices: tool/app/group queries, universal-time query, signed divide helper, + repeated tool/app/group queries, final StoreDlTask. +- Tool query precedes owner query, and group query occurs only after both fail + and flags bit 0x40 is set. The three query callees consume no incoming argument; + their actual implementations read process/library metadata. +- Both group IDs are loaded before NWC24GetGroupId and compared as u16 after + the call. Flags are u32; the permission result is BOOL. The task/header are + read-only, and the cached header lifetime survives the query sequence. +- Null task/header return -3/-9 before metadata queries. Permission failure is + -7. The 0xFFFF sentinel and u16 maximum-count checks retain their ordering. +- The time-output pointer remains the same eight-byte stack slot; __div2i still + receives the high/low time words and signed divisor 60. StoreDlTask receives + the original task pointer. No file/resource cleanup is owned by this helper. +- Current unsigned retry-mask semantics, retry loop, time helper, ID rechecks + and second-failure behavior are unchanged. + +## Fresh measurements and validation + +- NWC24UpdateDlTask: 95.00395 -> 98.695656%; source 249 -> 253 instructions, + target 253. Frame 0x30 -> target 0x20. Positional ctxdiff 250 -> 43 differences. +- Unit: 99.252884 -> 99.55186%; exact functions 27/30 and exact code 9304/12496 + preserved; data 80/80 preserved. No linking changes. +- Every other one of the 29 functions has identical instructions and resolved + relocations versus the baseline, including all 27 exact functions. +- Every allocated data byte and section extent is unchanged. Existing source/ + target alignment extents (.data 49/56 and .sbss 4/8) are unchanged; .sdata 16/16. +- Pool 3/3 identical. Literal advisory: 29 functions, 5 arguments, no candidates + or errors; unchanged AddTaskInternal is skipped because its size differs + from original. It remains 97.7182% and was not edited. +- Full 1,027-unit reports show only UpdateDlTask improved and no exact-function, + code, data or fuzzy regressions. Final post-build report equals candidate. +- ASan/UBSan: 262,144 exhaustive u16 group/flag cases, mutating the task group + during the group query to verify captured-value semantics. Seven directed + cases check nulls, sentinel/range behavior, tool/owner short-circuiting and + successful/failed second-validation stores. +- ASan/UBSan: 60,000 baseline/candidate Update scenarios compare return values, + task/header bytes, selected work pointer and ordered external call traces. + They cover metadata-query/time/store statuses, ID boundaries, group/owner + mismatches, retry counts/masks including bit 31, signed times, and controlled + task/header/work mutations at query boundaries. Actual production helper + bodies are extracted unchanged; metadata/time/store I/O is stubbed. No network + or file operation is performed. Leak detection is disabled for ptrace; + address and undefined-behavior instrumentation remain enabled. +- Full 43U build and build/43U/ok pass. DOL SHA1: + `26116613f624061ba99c8d1a299aaa6efa85670d`. +- git diff --check passes. + +Private evidence: `/tmp/nwc24-write-permission/` contains baseline/candidate +sources and objects, reports, disassembly audit, host test generator/harness, +pool/ctxdiff/literal results and build logs. The preceding read-only screen is +in `/tmp/network-partial-recovery-screen/`. No retail assembly/binary is committed. + +GATE: single justified partial recovery passes; frozen for independent review. +Historical 99.48617% is not claimed. Exact matching and linking remain open. -- 2.49.1 From a41f565889ce06e60a55ce02e6079680e4dffd01 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Sat, 3 Oct 2026 00:52:05 -0500 Subject: [PATCH 3/3] decomp(card): scope the permission-check result (#1059) --- src/scene/cardSequence/iplCardSequence.cpp | 40 ++++++----- .../card-permission-lifetime-20261003.md | 69 +++++++++++++++++++ 2 files changed, 90 insertions(+), 19 deletions(-) create mode 100644 tools/decomp-assist/card-permission-lifetime-20261003.md diff --git a/src/scene/cardSequence/iplCardSequence.cpp b/src/scene/cardSequence/iplCardSequence.cpp index 2a3c86db..e65aede5 100644 --- a/src/scene/cardSequence/iplCardSequence.cpp +++ b/src/scene/cardSequence/iplCardSequence.cpp @@ -1004,27 +1004,29 @@ sectorSizeError: sectorSizeDone: ; - result = 0; - statusResult = __CARDGetStatusEx(slot, fileNo, &checkedStatus); - if (statusResult >= 0) { - switch (command) { - case 2: - if (checkedStatus.permission & 8) { - result = -10; + { + s32 permissionResult = 0; + statusResult = __CARDGetStatusEx(slot, fileNo, &checkedStatus); + if (statusResult >= 0) { + switch (command) { + case 2: + if (checkedStatus.permission & 8) { + permissionResult = -10; + } + break; + case 3: + if (checkedStatus.permission & 0x10) { + permissionResult = -10; + } + break; } - break; - case 3: - if (checkedStatus.permission & 0x10) { - result = -10; - } - break; + } else { + permissionResult = CARDGetResultCode(slot); + } + if (permissionResult < 0) { + reportCardThreadError(slot, command, permissionResult); + goto finish; } - } else { - result = CARDGetResultCode(slot); - } - if (result < 0) { - reportCardThreadError(slot, command, result); - goto finish; } result = __CARDGetStatusEx(slot, fileNo, &createStatus); diff --git a/tools/decomp-assist/card-permission-lifetime-20261003.md b/tools/decomp-assist/card-permission-lifetime-20261003.md new file mode 100644 index 00000000..a3effff6 --- /dev/null +++ b/tools/decomp-assist/card-permission-lifetime-20261003.md @@ -0,0 +1,69 @@ +# Card move/copy permission result lifetime + +Base: `57ccda3883537a308568c03924af2cebf2d8a789`. +Owned source: `src/scene/cardSequence/iplCardSequence.cpp` only. + +## Retained reconstruction + +Give the permission-check stage of `runCardMoveOrCopy` its own initialized +`permissionResult`, scoped around the existing status query, command permission +checks and error gate. The later transfer result remains separate. There is no +copy back, added operation, dummy local or initializer-order search. + +Original `runCardMoveOrCopy` begins at `0x813D3D14`. Its permission stage +`+0xC8..+0x148` initializes r16 to zero at `+0xD4`, sets -10 for denied copy/move +permissions, or takes `CARDGetResultCode` after a failed status query. The error +report consumes that value at `+0x140/+0x144`, and failure branches to the final +return. Success reaches a new status query at `+0x158`; the old permission value +is dead, and r16 is reused for `createSize` at `+0x170`. + +The current source previously reused `result` across the permission and transfer +stages. Narrowing the permission result follows the original lifetime without +changing control or output ownership: failed permission goes to `finish`, whose +only operation is return; successful permission is followed by a new assignment +to `result` from `__CARDGetStatusEx`. No cleanup path reads the scoped value. + +This recovers a natural partial previously restored under exact-only acceptance. +`gk3.attempts.md` lines 108/240 recorded 185 -> 176 instruction differences, +identical pool and no exact regressions, but no isolated fuzzy score. The older +`iplCardSequence.attempts.md` also restored this result scope for its focused +exact-function diff. The fresh score below was measured directly. + +## Results + +- `runCardMoveOrCopy`: 97.8125% -> 97.88651% +- Instructions: unchanged 608/608; ctxdiff differences: 185 -> 176 +- Unit fuzzy: 97.20097% -> 97.219246% +- Exact functions: unchanged 27/30; matched code: unchanged 4168/9852 bytes +- All 27 exact functions individually checked: zero ctxdiff differences +- Matched data: unchanged 1496/1496 bytes +- All allocated non-text bytes, sizes and alignments unchanged +- Every other unit's complete report unchanged; no function regression across + the 1027-unit report +- Pool: 43/43 identical before and after +- Literal audit: 45 arguments across 29 functions; no candidates/errors. The + unchanged unequal-extent icon loader is the only skip +- Full 43U all_source/report/DOL gates: pass +- DOL SHA1: `26116613f624061ba99c8d1a299aaa6efa85670d` +- `git diff --check`: pass + +## Focused original-machine validation + +A bounded integer-PPC interpreter executes the actual baseline, candidate and +original instruction prefixes. It models the CARD calls and records fixed-ABI +arguments and error reports through either permission failure return or the next +status query beginning transfer. No arbitrary register renaming is assumed. + +All 17,328 cases agree, including both slots, file numbers 0/63/126, all 256 +permission bytes, copy/move/other command values and signed boundaries, negative +status results, and negative/nonnegative `CARDGetResultCode` results. In +particular, the retail continuation when that latter result is nonnegative is +preserved. Outcomes: 12,912 transfer entries and 4,416 early returns. Each version +covers 79 prefix instructions, and early returns preserve SP and nonvolatile +GPRs. An in-memory wrong-permission-mask mutation is detected. + +The whole original function's 513 nonrelocated instruction words and all 79 +call destinations agree with raw DOL bytes. Baseline, candidate and original +retain the same ordered call identities. This is bounded permission-stage +proof, not a full copy/move or Wii runtime test. The function remains nonexact; +no linking or full decompilation claim is made. -- 2.49.1