From 7649d9b1ec2a40030ae9d3f561ac51eeaa3f0d89 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Fri, 2 Oct 2026 21:51:37 -0500 Subject: [PATCH 1/2] fix(cdb): correct crypt-buffer ownership slot types (#1027) --- libs/RevoEX/src/cdb/CDBCrypt.c | 12 ++++----- .../allhands-cdb-buffer-ownership.attempts.md | 26 +++++++++++++++++++ 2 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 tools/decomp-assist/allhands-cdb-buffer-ownership.attempts.md diff --git a/libs/RevoEX/src/cdb/CDBCrypt.c b/libs/RevoEX/src/cdb/CDBCrypt.c index 8dfb9c6a..6827ea6b 100644 --- a/libs/RevoEX/src/cdb/CDBCrypt.c +++ b/libs/RevoEX/src/cdb/CDBCrypt.c @@ -8,13 +8,11 @@ void CDBCryptBufSysInit(CDBCryptBuf* cryptBuf) { cryptBuf->allocated = FALSE; } -// Some weird crap is going on with these functions. - -CDBErr CDBCryptBufAllocate(CDBCryptBuf* cryptBuf) { +CDBErr CDBCryptBufAllocate(CDBCryptBuf** cryptBuf) { CDBErr err = CDB_ERROR_OK; if (s_cryptBuf->allocated == FALSE) { - cryptBuf->buffer32[0] = (u32)&s_cryptBuf[err]; + *cryptBuf = &s_cryptBuf[err]; s_cryptBuf[err].allocated = TRUE; return CDB_ERROR_OK; } else { @@ -23,12 +21,12 @@ CDBErr CDBCryptBufAllocate(CDBCryptBuf* cryptBuf) { } } -CDBErr CDBCryptBufFree(CDBCryptBuf* cryptBuf) { +CDBErr CDBCryptBufFree(CDBCryptBuf** cryptBuf) { CDBErr err = CDB_ERROR_OK; - if ((CDBCryptBuf*)*cryptBuf->buffer32 == s_cryptBuf) { + if (*cryptBuf == s_cryptBuf) { s_cryptBuf[err].allocated = FALSE; - *cryptBuf->buffer32 = 0; + *cryptBuf = NULL; return CDB_ERROR_OK; } else { CDBReportError("failed to free crypt buffer\n"); diff --git a/tools/decomp-assist/allhands-cdb-buffer-ownership.attempts.md b/tools/decomp-assist/allhands-cdb-buffer-ownership.attempts.md new file mode 100644 index 00000000..63dcd12e --- /dev/null +++ b/tools/decomp-assist/allhands-cdb-buffer-ownership.attempts.md @@ -0,0 +1,26 @@ +# CDB crypt-buffer ownership contract + +Base: 20ba34a8, 43U. Focused source correction after the read-only CDBRecordEncrypt audit found only register-allocation differences in that function. + +## Evidence and change + +CDBRecord.c already declares CDBCryptBufAllocate and CDBCryptBufFree with CDBCryptBuf** parameters. Its callers supply the address of the record's crypt-buffer pointer slot. CDBCrypt.c instead declared CDBCryptBuf* and accessed buffer32[0] as a u32-encoded pointer, producing incompatible cross-translation-unit function types and describing the caller's pointer slot as an entire crypt-buffer object. + +Both definitions now take CDBCryptBuf** and use direct typed pointer loads/stores. Allocation assigns the pool pointer; free compares the owned pointer and clears the slot to NULL. The existing pool-index expression, flag update order, diagnostics and failure behavior are retained. The obsolete placeholder comment is removed. No header, payload layout, pool extent, Encrypt implementation, or linking change. + +## Validation + +- Configure: `python3 configure.py --version 43U --wrapper ../toolchain/wibo-build/wibo` +- Build: `WIBO_SJIS_MISSING_IMPORTS=1 ../.venv/bin/ninja` +- Entire compiled CDBCrypt.o is byte-identical to the baseline, including all code/data, symbols and relocations +- CDBCryptBufAllocate: 36/36 instructions, ctxdiff zero +- CDBCryptBufFree: 33/33 instructions, ctxdiff zero +- Unit remains 100% fuzzy, 3/3 exact functions, 296/296 code bytes and 80/80 data bytes +- Full-project before/after objdiff reports are identical; no metric gain is claimed +- Pool identical: 2/2 strings; literal-reference audit: 2 arguments across all 3 functions, no candidates/errors/skips +- Host test compiles the production source with the actual CDBCryptBuf layout and minimal platform/error stubs. AddressSanitizer and UBSan pass 50,036 ownership transitions, including every combination of six representative allocation flags and null/owned/foreign pointer slots, 10,000 randomized state cases, and 10,000 allocate/reallocate/free/refree cycles. Checks cover pointer-slot canaries, complete payload preservation, allocation flag, return value and diagnostic count +- LeakSanitizer is disabled because it cannot run under this execution environment's ptrace; the harness makes no heap allocations. Address and undefined-behavior instrumentation remain enabled +- Full 43U build and build/43U/ok pass; DOL SHA1 is 26116613f624061ba99c8d1a299aaa6efa85670d +- git diff --check passes + +Private reproducible evidence is in /tmp/cdb-buffer-ownership (baseline object, full reports, host validator and build log). Original objects/disassembly from the preceding read-only audit remain private under /tmp/cdb-record-encrypt-audit. -- 2.49.1 From 03ac61f399322318ab8b46ace157093f4bcc796b Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Fri, 2 Oct 2026 21:53:04 -0500 Subject: [PATCH 2/2] fix(chans): declare HMAC helpers with external linkage --- src/channelScript/CHANSVm.c | 8 +- .../CHANSVm-hmac-linkage-20261003.md | 79 +++++++++++++++++++ 2 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 tools/decomp-assist/CHANSVm-hmac-linkage-20261003.md diff --git a/src/channelScript/CHANSVm.c b/src/channelScript/CHANSVm.c index 4d91638e..fe3ac942 100644 --- a/src/channelScript/CHANSVm.c +++ b/src/channelScript/CHANSVm.c @@ -19,10 +19,10 @@ typedef struct { u64 work[0xD0 / sizeof(u64)]; } NETHMACContext; -static const void* NETGetSHA1Interface(void); -static void NETHMACInit(NETHMACContext* ctx, const void* interface, const void* key, u32 keyLen); -static void NETHMACUpdate(NETHMACContext* ctx, const void* data, u32 len); -static void NETHMACGetDigest(NETHMACContext* ctx, void* digest); +extern const void* NETGetSHA1Interface(void); +extern void NETHMACInit(NETHMACContext* ctx, const void* interface, const void* key, u32 keyLen); +extern void NETHMACUpdate(NETHMACContext* ctx, const void* data, u32 len); +extern void NETHMACGetDigest(NETHMACContext* ctx, void* digest); extern char VmReportFormat[]; #define CHANSVmDebugLength 1024 diff --git a/tools/decomp-assist/CHANSVm-hmac-linkage-20261003.md b/tools/decomp-assist/CHANSVm-hmac-linkage-20261003.md new file mode 100644 index 00000000..0843176a --- /dev/null +++ b/tools/decomp-assist/CHANSVm-hmac-linkage-20261003.md @@ -0,0 +1,79 @@ +# CHANSVm HMAC external declarations + +Base: `20ba34a80f9d0a09c4a8fad51352f0dd97d84be0` (43U). +Leaf: `agent/bittle/chans-hmac-linkage`. + +## Source evidence + +The four HMAC/SHA1 helper declarations at the top of `CHANSVm.c` had +`static` linkage but no definitions in that translation unit. A fresh MWCC +compile emitted four warning 10532 diagnostics. The definitions in +`libs/RevoEX/src/net/sha1.c` and `hmac.c` have external linkage; +`CDBRecord.c` already declares these imports `extern`. + +The original CHANS object imports all four as `STB_GLOBAL`, `SHN_UNDEF`. +The baseline source object instead imported them as `STB_LOCAL`, +`SHN_UNDEF`. Change only the four declaration storage classes to `extern`. +Do not change the context, parameter types, shared headers, or linking flags. + +Independent original-DOL call decoding agrees with the extracted relocations: + +| Caller | Call address | Destination | Import | +| --- | --- | --- | --- | +| VmBlobCalcHMAC | 0x81452720 | 0x81494144 | NETGetSHA1Interface | +| VmBlobCalcHMAC | 0x81452734 | 0x814944EC | NETHMACInit | +| VmBlobCalcHMAC | 0x81452744 | 0x81494728 | NETHMACUpdate | +| VmBlobCalcHMAC | 0x81452750 | 0x81494738 | NETHMACGetDigest | +| VmBlobCalcRangeHMAC | 0x814528F4 | 0x81494144 | NETGetSHA1Interface | +| VmBlobCalcRangeHMAC | 0x81452908 | 0x814944EC | NETHMACInit | +| VmBlobCalcRangeHMAC | 0x81452918 | 0x81494728 | NETHMACUpdate | +| VmBlobCalcRangeHMAC | 0x81452924 | 0x81494738 | NETHMACGetDigest | + +The ABI contracts agree: Init takes context/interface/key/u32 length in +r3-r6, Update takes context/data/u32 length, and GetDigest takes +context/output. The interface helper returns its pointer in r3. +Original caller context addresses are sp+8 and sp+0x10. The exact HMAC +implementation uses the interface at 0x00-0x1B, key length at 0x1C, +96-byte digest state at 0x20, and 64-byte key at 0x80, totaling 0xC0. +The existing CHANS opaque context reserves 0xD0 with 8-byte alignment. +That storage is unchanged. Caller opaque types and callee named types +remain separate declarations; this change fixes linkage only, not complete +cross-translation-unit type compatibility. + +## Validation + +- Configured 43U with `../toolchain/wibo-build/wibo`; fresh baseline full + source/report/DOL build passed, followed by a forced owned-object rebuild. +- Baseline emitted exactly four warning 10532 diagnostics; candidate emitted + none. No other compiler warning appeared in the candidate object build. +- The four imports now have exactly the original symbol records, including + global undefined binding. Every other symbol record is unchanged. +- All six allocated sections retain identical contents, extents, alignment, + type and flags, including the NOBITS section's extent. +- All 2,010 relocation sites, types, symbol identities and addends are + unchanged. Comparison resolves symbol indexes because binding changes + can reorder the ELF symbol table. +- All 1,027 unit report records are unchanged. CHANS: fuzzy 99.4341%, + exact code 38,136/53,564 bytes, exact functions 222/233, + matched data 6,904/6,904 bytes. +- Independently compared all 222 exact functions against original + instruction streams, with zero differences. +- The two HMAC callers remain 64/64 and 119/119 instructions, diffs 0. +- Pool: identical 125/125 entries. Literal advisory: 233 functions, + 40 arguments, no candidates, errors, or skips. +- Eight call destinations and 392 nonrelocated instruction words across + the two callers and four helpers agree with original DOL bytes. +- Final `WIBO_SJIS_MISSING_IMPORTS=1 ../.venv/bin/ninja all_source + build/43U/report.json build/43U/ok` passes; DOL SHA1 remains + `26116613f624061ba99c8d1a299aaa6efa85670d`. `git diff --check` passes. + +Whole-object identity is intentionally not claimed: symbol bindings changed. +SHA256 before: +`f971cabf817dba7e5cb240df01e1e8f814bb0a973e357a594d031046a56e691b`. +SHA256 after: +`5bf3f4a0a404e2a574287c16de81d702a1402d9fca416455e84dc1df67c9eb76`. + +Private reproducibility artifacts are under +`validation/chans-hmac-linkage-20261003/` in the workspace parent and +`/tmp/chans-hmac-linkage/`. No original binary or disassembly is committed. +This is a source declaration correction with no decompilation percentage gain. -- 2.49.1