From a36e8b65b3d7afd3b6e1a4b697d18cca34e86ca7 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Sat, 3 Oct 2026 00:48:21 -0500 Subject: [PATCH 1/3] decomp(keyboard): express literal input through an output builder --- src/keyboard/tiString.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/keyboard/tiString.cpp b/src/keyboard/tiString.cpp index a2bcfe5a..1731f3f3 100644 --- a/src/keyboard/tiString.cpp +++ b/src/keyboard/tiString.cpp @@ -141,6 +141,28 @@ wchar_t StringBase::getLastWChar() { return 0; } +namespace { +class CharacterOutput { +public: + CharacterOutput(wchar_t* output) : mpOutput(output), mCount(0) { + mpOutput[0] = 0; + } + + void append(wchar_t ch) { + mpOutput[mCount++] = ch; + } + + u16 finish() { + mpOutput[mCount] = 0; + return mCount; + } + +private: + wchar_t* mpOutput; + u32 mCount; +}; +} + void Decolated::inputChar(wchar_t ch) { if (ch != 0xfffe) { wchar_t input[8]; @@ -173,9 +195,9 @@ void Decolated::inputChar(wchar_t ch) { } nonKana: if (mTranslateMode == 3) { - input[0] = ch; - input[1] = 0; - count = 1; + CharacterOutput output(input); + output.append(ch); + count = output.finish(); mKanaStream.mOutput[0] = 0; } else { count = 1; -- 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