Compare commits

..

4 Commits

Author SHA1 Message Date
devin
ddc3eeadd9 decomp(scene4): nested-switch guards + dead-store fossils (address/sdChannelSelect)
Decodes:
- start_drag_event: nested single-case switch emits the b<cond>+b
  two-branch guard (insn-identical, 7-word web-home residual)
- onEventDerived: no-break TRIG->ON_POINT fallthrough + || polarity fold
  (insn-identical, regname residuals)
- set_err_msg: default arm reads uninitialized messageId register,
  matching the orig's uninit-r4 retail bug (verified in base asm)
- movePane_onDrag width-accumulate scoping, FriendListCache::update
  member-chain regroup, AddressEdit::create/get_friendinfo arg marshals

All three units stay NonMatching; data 100% on all; documented walls in
tools/decomp-assist/scene4.attempts.md.

Co-authored-by: coah80 <usernamecole7@gmail.com>
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 22:11:41 +00:00
coah
7fac2b91ec decomp: refine MD5 rotation sums and word consumption (#969) 2026-10-02 17:09:45 -05:00
coah
6456e33a4c decomp: reconstruct AES last-round key cursor (#968) 2026-10-02 17:09:20 -05:00
coah
3244c6d7ff decomp: reconstruct CHANSVm opcode-local error paths (#967) 2026-10-02 16:59:59 -05:00
8 changed files with 260 additions and 40 deletions

View File

@@ -197,8 +197,9 @@ void AESiEncryptBlock(AESContext* context, u32* output, const u32* input) {
void AESiDecryptBlock(AESContext* context, u32* output, const u32* input) {
u32 rounds=context->rounds;
u32* key=context->keys + rounds*4;
u32* key=context->keys;
u32 a,b,c,d;
key += rounds*4;
if (context->needsTransform) {
u32 round;
for (round=1; round<context->rounds; ++round) {

View File

@@ -72,7 +72,7 @@ static inline u32 rotateSum(u32 state, const u32* word, u32 constant, int shift)
// Each rotation half reads its own byte-reversed message word.
u32 right = __lwbrx((void*)word, 0);
u32 left = __lwbrx((void*)word, 0);
return ((state + (left + constant)) << shift) | ((right + (constant + state)) >> (32 - shift));
return ((state + (constant + left)) << shift) | ((constant + (state + right)) >> (32 - shift));
}
#define STEP(a, b, c, d, f, word, n) ((a) = (b) + rotateSum((a) + (f), word, *constant, n))
@@ -90,10 +90,10 @@ static void ProcessBlock(NETMD5Context* context) {
word = block;
constant = constants;
for (round = 0; round < 4; ++round) {
STEP(a,b,c,d,(b & c) | (~b & d),word,7); ++word; ++constant;
STEP(d,a,b,c,(a & b) | (~a & c),word,12); ++word; ++constant;
STEP(c,d,a,b,(d & a) | (~d & b),word,17); ++word; ++constant;
STEP(b,c,d,a,(c & d) | (~c & a),word,22); ++word; ++constant;
STEP(a,b,c,d,(b & c) | (~b & d),word++,7); ++constant;
STEP(d,a,b,c,(a & b) | (~a & c),word++,12); ++constant;
STEP(c,d,a,b,(d & a) | (~d & b),word++,17); ++constant;
STEP(b,c,d,a,(c & d) | (~c & a),word++,22); ++constant;
}
index = indices;
for (round = 0; round < 4; ++round) {

View File

@@ -1179,10 +1179,10 @@ namespace ipl {
return;
}
if (mState != STATE_NORMAL || mMode != 0) {
return;
}
switch (mState) {
case STATE_NORMAL:
switch (mMode) {
case 0:
if (!mpFriendCache->isThere(buttonNo + mPage * BTN_MAX)) {
return;
}
@@ -1240,6 +1240,8 @@ namespace ipl {
snd::getSystem()->startSEwithPos("WIPL_SE_CH_HOLD", mDrag.mPos.x);
mState = STATE_DRAG;
}
}
}
void Address::start_drag_point_event(const char* paneName, controller::Interface* con) {
@@ -1425,10 +1427,7 @@ namespace ipl {
if (con->downTrg(controller::BTN_INTERACT)) {
Button* button = static_cast<Button*>(System::getScene(SCENE_BUTTON));
if (mState != STATE_COVER_NORMAL && mState != STATE_NORMAL) {
break;
}
if (mState == STATE_COVER_NORMAL || mState == STATE_NORMAL) {
if (Button::cmpButtonName(paneName, Button::BTN_EXIT) == 0) {
MailAddressSelect* mailAddrSel = static_cast<MailAddressSelect*>(System::getScene(SCENE_MAIL_ADDRESS_SELECT));
button->animation(Button::IDANIM_SELECT_CALENDAR_EXIT);
@@ -1477,7 +1476,7 @@ namespace ipl {
snd::getSystem()->startSE("WIPL_SE_FL_PAGE_DEC");
onPreviousPage();
}
break;
}
}
// fallthrough
}
@@ -1783,13 +1782,15 @@ namespace ipl {
nw4r::math::VEC3 baseTrans = mpLayout->FindPaneByName("N_base_move")->GetTranslate();
math::VEC2 pos = System::getControllerManager()->getController(mDrag.mChan)->getDpdProjectionPos();
nw4r::lyt::TextBox* textBox = static_cast<nw4r::lyt::TextBox*>(mpLayout->FindPaneByName("T_name_move"));
const u16* name = mpFriendCache->getInfo(mDrag.mButton + mDrag.mPage * BTN_MAX).attr.name;
f32 width = 0.0f;
if (textBox != NULL && name != NULL) {
textBox->GetFont()->GetWidth();
for (; *name != 0; name++) {
width += textBox->GetFont()->GetCharWidth(*name);
if (textBox != NULL) {
const u16* name = mpFriendCache->getInfo(mDrag.mButton + mDrag.mPage * BTN_MAX).attr.name;
if (name != NULL) {
textBox->GetFont()->GetWidth();
for (; *name != 0; name++) {
width += textBox->GetFont()->GetCharWidth(*name);
}
}
}
width += 0.01f;
@@ -1946,11 +1947,10 @@ namespace ipl {
}
void FriendListCache::update(u32 index, const wchar_t* name, u64 fdId) {
NWC24FriendInfo* info = &mInfos[index];
info->attr.fdId = fdId;
memset(info->attr.name, 0, sizeof(info->attr.name));
wcsncpy((wchar_t*)info->attr.name, name, 10);
System::getNwc24Manager()->updateFriendInfo(info, index);
mInfos[index].attr.fdId = fdId;
memset(mInfos[index].attr.name, 0, sizeof(mInfos[index].attr.name));
wcsncpy((wchar_t*)getInfo(index).attr.name, name, 10);
System::getNwc24Manager()->updateFriendInfo(&getInfo(index), index);
}
void FriendListCache::del(u32 index) {

View File

@@ -521,7 +521,8 @@ void ipl::scene::AddressEdit::create() {
set_textbox(textPane, friendText);
textPane = (mpCodeLayout)
->getNW4RLyt()->GetRootPane()->FindPaneByName("T_frnd_crd_00", true);
set_textbox(textPane, mString.mDisplayText);
friendText = mString.mDisplayText;
set_textbox(textPane, friendText);
mState = 0;
break;
}
@@ -2779,7 +2780,7 @@ void ipl::scene::AddressEdit::set_err_msg(wchar_t* outErrMsg, u32 outErrMsgLen,
swprintf(nwc24ErrStr, sizeof(nwc24ErrStr) / sizeof(wchar_t), L"%06d\n", errorCode);
wcsncat(outErrMsg, nwc24ErrStr, outErrMsgLen - wcslen(outErrMsg));
u32 messageId = MESG_ERROR_NWC24_SERVER;
u32 messageId;
switch (nwc24Err) {
case NWC24_ERR_NETWORK:
messageId = MESG_ERROR_NWC24_NETWORK;
@@ -2865,10 +2866,7 @@ void ipl::scene::AddressEdit::get_friendinfo() {
memcpy(&ipl::scene::sFriendInfo, &mpFriendCache->getInfo(mSelectedFriend),
sizeof(ipl::scene::sFriendInfo));
mString.setName(reinterpret_cast<const wchar_t*>(ipl::scene::sFriendInfo.attr.name));
const wchar_t* name = mString.mName;
nw4r::lyt::Pane* namePane =
mpCodeLayout->getNW4RLyt()->GetRootPane()->FindPaneByName("T_name_00", true);
set_textbox(namePane, name);
set_textbox(mpCodeLayout->getNW4RLyt()->GetRootPane()->FindPaneByName("T_name_00", true), mString.mName);
wchar_t wiiNo[0x100];
wchar_t email[0x102];
@@ -2881,10 +2879,7 @@ void ipl::scene::AddressEdit::get_friendinfo() {
ipl::utility::CharacterCode::ANSIToUTF16(email, reinterpret_cast<const u8*>(&ipl::scene::sFriendInfo.addr), 0x102);
mString.setEMail(email);
}
const wchar_t* displayText = mString.mDisplayText;
nw4r::lyt::Pane* friendCodePane =
mpCodeLayout->getNW4RLyt()->GetRootPane()->FindPaneByName("T_frnd_crd_00", true);
set_textbox(friendCodePane, displayText);
set_textbox(mpCodeLayout->getNW4RLyt()->GetRootPane()->FindPaneByName("T_frnd_crd_00", true), mString.mDisplayText);
memcpy(&mCreateID, &ipl::scene::sFriendInfo.attr.fdId, sizeof(mCreateID));
}

View File

@@ -1341,13 +1341,11 @@ namespace ipl {
wchar_t* titleName = System::getChannelManager()->getTitleName(
page, channelIndex, 0);
memcpy(titleNames + *titleCount * 0x2a, titleName, 0x2a);
u32 nextTitleCount = *titleCount + 1;
*titleCount = nextTitleCount;
++*titleCount;
if (bytes < secondUsage[0] || blocks < secondUsage[1]) {
continue;
if (bytes >= secondUsage[0] && blocks >= secondUsage[1]) {
return true;
}
return true;
}
}
}

View File

@@ -0,0 +1,78 @@
# AES key-schedule cursor reconstruction, 2026-10-02
Source baseline: `449529d9`. This separate candidate follows the frozen MD5
commit `521056a9`; it changes only `libs/RevoEX/src/net/aes.c` and this log.
43U only. No linking flags, configuration, tables, or public API edits.
## Target evidence and retained change
`AESiDecryptBlock` in `build/43U/obj/libs/RevoEX/src/net/aes.o` is 0x3EC bytes /
251 instructions. Its entry first forms the key-schedule base at context+0x10
(function-relative offset 0x18), extracts the last-round offset from the flags
word (offset 0x24), and adds that offset to the already formed base (offset
0x28). The baseline combined initializer produced 249 instructions. Explicitly
initializing the typed key pointer to `context->keys` before advancing it by
`rounds*4` recovers the target's two-stage pointer construction and body size.
The retained change is two added source lines and one removed line. All AES
round expressions, lazy inverse key transformation, tables and CBC chaining
remain unchanged.
This is a structural matching improvement, not a newly implemented AES path.
Both existing block algorithms were already present and pass the behavior tests.
## Explored and rejected alternatives
- Inlined single-word round helpers, byte-typed table lookups and table-rotation
helpers changed scheduling but regressed encryption or added source complexity.
- Staging four inverse-mix column outputs through a typed round helper improved
decrypt similarity but required substantially more source and still did not
match. Not retained.
- Alternate inverse-key-transform local lifetimes and an inverse-key helper
gave only small extra fuzzy movement, without new algorithm reconstruction.
- Context-relative key indexing and row/word loop variants did not improve the
minimal key-base candidate.
- Moving next-state locals outside the round loop did not change codegen.
- Reordering key-base declarations produced a negligible score change; the
original natural declaration order was kept.
- Two exploratory C89-incompatible mixed-declaration variants failed to compile
and were immediately discarded. No failed source is retained.
## Verification
Before -> after:
- AESiDecryptBlock: 249 -> 251 instructions against target 251;
fuzzy 61.49004 -> 63.836655%. Final ctxdiff: 224 positional differences.
- AESiEncryptBlock: unchanged, 158/158 instructions and 60.348103% fuzzy.
- Unit fuzzy: 76.844475 -> 77.700584%.
- Exact functions: 7/9 -> 7/9. Exact code: 1116/2752 bytes unchanged.
- Data: objdiff 2800/2800, 100%, unchanged. Linked status unchanged.
- All seven exact functions have ctxdiff diffs 0: NETAESCreateEx 108/108,
NETAESCreate 2/2, NETAESDelete 1/1, NETAESEncrypt 46/46, NETAESDecrypt 46/46,
NETiAESEncryptoBlock 39/39, NETiAESDecryptoBlock 37/37.
- String pool: all four strings identical.
- .rodata: 2592 identical bytes; .sdata2: 8 identical bytes. Source .data is
197 bytes with the same prefix as the 200-byte target section; three target
alignment bytes are an existing extent difference. No padding was added.
- The full 1027-unit report has no regressions in exact functions/code/data or
fuzzy score against the baseline report. Frozen MD5 metrics are unchanged.
- Full 43U build passed with the configured wibo wrapper; build/43U/ok passed.
DOL SHA1: `26116613f624061ba99c8d1a299aaa6efa85670d`.
Host validation: `python3 /tmp/crypto-remainder/validate_aes.py` compiles the
production C unchanged with minimal types/OSReport shims. Input, key and IV
words are represented with their PPC big-endian numeric values, so native host
byte order does not change the algorithm. Known-answer tests cover AES-128,
AES-192 and AES-256; seeded randomized CBC tests compare against cryptography's
AES implementation for all three key sizes. Each tests separate/in-place
buffers and single/incremental calls.
Result: all 2,406 production-source known-answer/randomized checks passed. The
original baseline had independently passed the same coverage before changes.
A separate saved helper experiment also passed but is not part of this commit.
Local evidence, not committed or uploaded: `/tmp/crypto-remainder/aes-final.ctx`,
`aes-final.json`, `aes-full-build.log`, `aes-vectors.log`, `aes-decrypt.target`,
and `validate_aes.py` plus its header shims. No retail assembly is included.
GATE: validated partial structural candidate; no regressions. Exact matching
and linking remain open.

View File

@@ -0,0 +1,62 @@
# MD5 unsigned arithmetic and cursor reconstruction, 2026-10-02
Separate follow-on to accepted MD5 commit `521056a9`. AES commit `2a537c14`
and both prior logs are unchanged. Only 43U was configured or built.
## Target-grounded changes
The target ProcessBlock rotation halves retain independently grouped additions
of the unsigned state, round constant and separately byte-reversed message
words. Reassociating those three u32 operands inside the accepted helper brings
the compiler's data-flow closer to the target while preserving modulo-2^32
arithmetic. The first MD5 round consumes sequential message words; expressing
that consumption with `word++` as the helper's pointer argument improves its
schedule. STEP evaluates this pointer argument exactly once; the helper still
uses that captured pointer for both byte-reversed reads. No evaluation-order
ambiguity, extra read, undefined value, or new helper is introduced.
Experiments enumerated 144 valid addition operand/grouping combinations for
the two halves. The best target-sized arithmetic expression reached 93.447716%
ProcessBlock fuzzy. Five cursor/loop variants and eight independent cursor-
consumption combinations then identified the minimal `word++` form, reaching
94.30719%. A larger by-reference cursor helper reached 94.98366% but duplicated
rotation code for a small gain and was rejected. Three explicit feed-forward
variants did not improve the retained result. No declaration/register sweep,
assembly, volatile qualifier, padding or linking change was used.
## Verification
Accepted MD5 -> this candidate:
- ProcessBlock: 81.82026 -> 94.30719% fuzzy; 306/306 instructions unchanged.
- Unit fuzzy: 87.80044 -> 96.179825%.
- Exact functions 3/4 and exact code 600/1824 are unchanged.
- Data 456/456 (100%) and linking status are unchanged.
- NETMD5Init 16/16, NETMD5Update 60/60 and NETMD5GetDigest 74/74 still have
ctxdiff diffs 0 and objdiff 100%.
- ProcessBlock has 215 positional differences. An advisory comparison that
ignores GPR names leaves five opcode/immediate-order differences: three
sequential cursor offsets and two final state-load positions. This is not
an exact match or a proof that every remaining difference is register-only.
- Empty string pools remain identical. Constants/index tables and end-marker
data are unchanged from the accepted candidate.
- AES metrics and source are unchanged from commit 2a537c14.
- Full 1027-unit report: zero exact-function/code/data/fuzzy regressions versus
baseline449529d9; additionally both owned units preserve the immediately
preceding candidate's exact/data scores and improve or preserve fuzzy scores.
- Full 43U build and build/43U/ok passed. DOL SHA1:
`26116613f624061ba99c8d1a299aaa6efa85670d`.
All 3,088 MD5 known-answer/random/chunking comparisons passed again against
Python hashlib. Run `python3 /tmp/crypto-remainder/validate_md5.py`. The test
compiles production C unchanged with PPC intrinsic shims, supplies RFC1321
padding externally, and exercises ProcessBlock through NETMD5Update. The
instruction-exact GetDigest platform-endian stores are not host-tested.
Local evidence (not committed/uploaded): `/tmp/crypto-remainder/` contains
`md5.grouping-results.json`, `md5-grouping-final.json`,
`md5-grouping-ProcessBlock.ctx`, `md5-grouping-vectors.log`, and
`md5-grouping-full-build.log`. Original target evidence remains in the local
split object and disassembly; no retail assembly is included in this commit.
GATE: validated partial structural candidate; no regressions. Exact matching
and linking remain open.

View File

@@ -0,0 +1,86 @@
# scene4 leaf — decode attempts & evidence
Branch `agent/w1008/scene4` off origin/main@e3457d11.
Scope: iplAddress, iplAddressEdit, iplSDChannelSelect are the only sub-100 units in
the scene/address + sdChannelSelect remainder (iplAddressAddSel, iplAddressInputName,
iplAddressSelect, addressHelpers, addressInputHelpers, agreeSettings, agreeHttp,
iplFaceSelect, iplNCDSetting all verified already 100% on main; no open PR claims).
## Decodes that landed (this leaf)
### Single-case `switch` produces the `b<eq> caseblock; b after` 2-branch guard
`switch (x) { case C:` emits `cmp; beq caseblock; b exit` — MWCC keeps the
dispatch's second `b` because the case-block is a separate labelled region.
Equivalent `if`, `if||`, `if&&`, `goto`-goto, `if/else`-goto all get normalized
to a single fused `beq`/`bne`. Used in:
- `Address::start_drag_event` (892B): outer `switch (mState) { case STATE_NORMAL:`
+ inner `switch (mMode) { case 0:` reproduces orig's two nested 2-branch guards.
Residual: 7 word diffs, pure regname — nigaoe web pinned r26 (orig) vs r29
(mine), miiPane web r29 vs r26. Allocator home-order tie; decl-hoist of
miiPane above the `if` was a no-op (web homes unchanged).
- `Address::onEventDerived` (1080B): TRIG case falls through to ON_POINT
(orig has NO `break`); the `mState == COVER_NORMAL || mState == NORMAL`
guard folds to `beq`+`bne` inside the TRIG case. Residual: 81 word diffs,
all regname — insn sequence identical.
### `addic.` fusion for `ptr = base + const` NULL-tested members
`record->attr.name` tested `!= 0` fuses into `addic.` only when the pointer is
materialized lazily at the compare — decl the local inside the `if`. Hoisted
decls emit `addi`+`cmpwi`. (movePane_onDrag `name` web.)
## Walls re-verified (evidence)
### `Address::movePane_onDrag` 92.45 (620 orig vs 612 mine)
- Orig emits `bne next; b exit` 2-branch guards for both `textBox != NULL` and
`name != NULL` (the `b` skips to the shared `width += 0.01f` block).
- This is switch-dispatch-shaped, but every legal polarity fails:
`switch(ptr) { case NULL: break; default: body }` bool-materializes
(`addic/subfe/cmpwi 1` — +3 insns); `switch (p != NULL) { case true:` also
bool-materializes; `do { if (!x) break; } while (0)` folds to single `beq`.
- Orig computes the record math (`lwz 0x70 / mulli 5 / lwz 0x274 / mulli 0x140`)
before the textBox branch — scheduler interleave around the guard.
- Residual also regname r27↔r29 (textBox web) + loop `name` web.
### `FriendListCache::update` 95.5 (160 orig vs 156 mine)
Orig remats `mInfos + index*0x140` per use site (memset, wcsncpy,
updateFriendInfo = 3 `mulli`+`add` pairs). Mine CSEs into callee r31.
`getInfo(index)` vs `mInfos[index]` vs `(int)index` cast — all VN-identical,
still CSE. Remat-vs-pin in the unusual remat-is-orig direction; no lever.
### `AddressEdit::create` 97.45 (3280B)
Two distinct residuals:
- Wholesale r30↔r31 web-order swap: orig pins string-table const web in r31
and `boardFile` (getScene+0xd20) in r30; mine the reverse. Webs born in the
same source order — allocator processing order tie.
- `friendText` (this+0x2b4 / this+0x2cc) pin: orig materializes
`addi r25, r29, 0x2b4` at decl point between `initFrame()` and `restart()`,
reassigns `addi r25, r29, 0x2cc` mid-block — the reg+const web is pinned.
Mine remats `addi r5, r29, 0x2b4` at each marshal. Variants tried: non-const
`wchar_t*`, decl moved before `animator =` — both no-op. Same this+const
pin family as get_friendinfo.
### `AddressEdit::get_friendinfo` 88.04 (336 orig vs 328 mine)
Orig: this→r28, `this+0x2b4` (mName) pinned in r29 materialized before the
FindPaneByName marshal — 2 extra insns vs mine's marshal-site remats, and one
more callee web (savegpr_28 vs my _29 window differs). Same `this+const`
pin-vs-remat wall as create's friendText.
### `AddressEdit::update_friendinfo` 99.42 (152B)
Single 2-insn scheduling swap: `addi r4,r30,0x2b4` vs `addi r3,r31,8` order
in the wcsncpy marshal.
### iplSDChannelSelect 99.58 — 7 fns
- `create` 97.74: regname r29↔r30 swap + marshal interleaves around `bl`s
(scheduler family); insn count equal.
- `collectTitles*` ×4 (97.29–97.83): documented ties — callee-web rotations
around the same ES_GetTitleCount/ES_GetTitles marshal blocks.
- `flushSaveDataAndMountSD` 99.66 (140B): marshal order tie.
- `setChannelScissor` 93.47 (932B): fp/scheduling family (DrawFrame-class).
## Notes
- ndiff.py NORMALIZES register names — "diffs 0" can hide regname-only
diffs. Always confirm with raw byte-compare of `.text` (readelf -sW for
addr/size, -SW for file offset).
- `objdiff-cli diff` is interactive-only (fails headless); use disasm_fn.py
+ byte-compare.