From 6f2e3402ae7acc77f735bfe7bee1d6d530a8a681 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Thu, 8 Oct 2026 18:51:15 +0000 Subject: [PATCH] decomp(nhttp): link NHTTP_stdlib_RVL and NHTTP_recvbuf (mscharged prior art, GC/3.0a5) (worker 1fcdff13) --- configure.py | 4 +- libs/RevoEX/src/nhttp/NHTTP_recvbuf.c | 52 +++++++++++++++++++----- libs/RevoEX/src/nhttp/NHTTP_stdlib_RVL.c | 41 +++++++++++-------- tools/decomp-assist/opus-art.attempts.md | 29 +++++++++++++ 4 files changed, 96 insertions(+), 30 deletions(-) create mode 100644 tools/decomp-assist/opus-art.attempts.md diff --git a/configure.py b/configure.py index a1de7533..7f3ee52a 100644 --- a/configure.py +++ b/configure.py @@ -1057,11 +1057,11 @@ config.libs = [ Object(Matching, "nhttp/NHTTP_control.c"), Object(Matching, "nhttp/NHTTP_list.c"), Object(Matching, "nhttp/NHTTP_os_RVL.c"), - Object(NonMatching, "nhttp/NHTTP_recvbuf.c"), + Object(Matching, "nhttp/NHTTP_recvbuf.c", mw_version="GC/3.0a5"), Object(Matching, "nhttp/NHTTP_request.c"), Object(Matching, "nhttp/NHTTP_response.c"), Object(Matching, "nhttp/NHTTP_socket_RVL.c"), - Object(NonMatching, "nhttp/NHTTP_stdlib_RVL.c"), + Object(Matching, "nhttp/NHTTP_stdlib_RVL.c", mw_version="GC/3.0a5"), Object(Matching, "nhttp/NHTTP_thread.c"), Object(Matching, "nhttp/d_nhttp_private.c"), Object(Matching, "nhttp/d_nhttp.c"), diff --git a/libs/RevoEX/src/nhttp/NHTTP_recvbuf.c b/libs/RevoEX/src/nhttp/NHTTP_recvbuf.c index 5a618318..cd03848d 100644 --- a/libs/RevoEX/src/nhttp/NHTTP_recvbuf.c +++ b/libs/RevoEX/src/nhttp/NHTTP_recvbuf.c @@ -3,6 +3,8 @@ void* NHTTPi_memcpy(void*, const void*, u32); s32 NHTTPi_SocRecv(void*, NHTTPRequestInfo*, s32, void*, s32, s32); +#define NHTTPi_TOLOWER(c) ((((c) >= 'A') & ((c) <= 'Z')) ? (c) + ('a' - 'A') : (c)) + static void FindHeaderBlock(const NHTTPResponseInfo* response, s32 position, NHTTPi_HDRBUFLIST** block, s32* offset) { if(positionblock[(*offset)++]; } -static int LowerCase(int character) { - return ((character >= 'A') & (character <= 'Z')) ? character + ('a' - 'A') : character; -} - s32 NHTTPi_findNextLineHdrRecvBuf(const NHTTPResponseInfo* response, s32 position, s32 limit, s32* colon, s32* newlineLength) { NHTTPi_HDRBUFLIST* block; s32 offset; @@ -75,16 +73,48 @@ s32 NHTTPi_skipSpaceHdrRecvBuf(const NHTTPResponseInfo* response, s32 position, s32 NHTTPi_compareTokenN_HdrRecvBuf(const NHTTPResponseInfo* response, s32 position, s32 limit, const char* token, s8 delimiter) { NHTTPi_HDRBUFLIST* block; s32 offset; - int character; + s32 i; + s32 tokenChar; + s32 character; if (position < limit) { FindHeaderBlock(response, position, &block, &offset); - character = ReadHeaderChar(response, &block, &offset); - while (LowerCase((s8)character) == LowerCase(*token)) { - if (*token == 0 || *token == ' ' || *token == delimiter || position == limit - 1) return 0; - character = ReadHeaderChar(response, &block, &offset); - ++position; - ++token; + + if (block == NULL) { + if (offset < NHTTP_HDRRECVBUF_INILEN) { + character = (s8)response->hdrBufFirst[offset++]; + goto compare_characters; + } + block = response->hdrBufBlock_p; + offset = 0; + } else if (offset == NHTTP_HDRRECVBUF_BLOCKLEN) { + offset = 0; + block = block->next_p; + } + character = block->block[offset++]; + + compare_characters: + i = position; + while (NHTTPi_TOLOWER((s8)character) == NHTTPi_TOLOWER((s8)*token)) { + tokenChar = (s8)*token; + if (tokenChar == '\0' || tokenChar == ' ' || tokenChar == delimiter || i == limit - 1) return 0; + + if (block == NULL) { + if (offset < NHTTP_HDRRECVBUF_INILEN) { + character = (s8)response->hdrBufFirst[offset++]; + goto advance_token; + } + block = response->hdrBufBlock_p; + offset = 0; + } else if (offset == NHTTP_HDRRECVBUF_BLOCKLEN) { + offset = 0; + block = block->next_p; + } + character = block->block[offset++]; + + advance_token: + i++; + token++; } } return -1; diff --git a/libs/RevoEX/src/nhttp/NHTTP_stdlib_RVL.c b/libs/RevoEX/src/nhttp/NHTTP_stdlib_RVL.c index 0df8254f..b7e722f7 100644 --- a/libs/RevoEX/src/nhttp/NHTTP_stdlib_RVL.c +++ b/libs/RevoEX/src/nhttp/NHTTP_stdlib_RVL.c @@ -1,6 +1,8 @@ #include #include +#define NHTTPi_TOLOWER(c) ((((c) >= 'A') & ((c) <= 'Z')) ? (c) + ('a' - 'A') : (c)) + void* NHTTPi_memcpy(void* destination, const void* source, u32 size) { return memcpy(destination, source, size); @@ -26,28 +28,33 @@ static int LowerCase(int character) return ((character >= 'A') & (character <= 'Z')) ? character + 32 : character; } -s32 NHTTPi_strnicmp(const char* left, const char* right, s32 length) +s32 NHTTPi_strnicmp(const char* left, const char* right, s32 size) { - while (length > 0) + char leftChar; + char rightChar; + + while (size > 0) { - int a = *left++, b = *right++; - if (a == 0 || b == 0) + leftChar = *left++; + rightChar = *right++; + + if (leftChar == '\0' || rightChar == '\0') { - if (a == 0 && b == 0) + if (leftChar == '\0' && rightChar == '\0') { - length = 0; + size = 0; break; } } - b = LowerCase(b); - a = LowerCase(a); - if (a != b) + + if (NHTTPi_TOLOWER(leftChar) != NHTTPi_TOLOWER(rightChar)) { break; } - --length; + size--; } - return length; + + return size; } static BOOL UrlPlain(int character) @@ -237,18 +244,18 @@ s32 NHTTPi_intToStr(char* destination, u32 value) return length + 1; } -s32 NHTTPi_compareToken(const char* left, const char* right) +s32 NHTTPi_compareToken(const char* string, const char* token) { - u32 rawLeft; - while (LowerCase((s8)(rawLeft = *(const u8*)left)) == LowerCase((s8)*(const u8*)right)) + while (NHTTPi_TOLOWER(*string) == NHTTPi_TOLOWER(*token)) { - if ((s8)rawLeft == 0 || (s8)rawLeft == ' ') + if (*string == '\0' || *string == ' ') { return 0; } - ++left; - ++right; + string++; + token++; } + return -1; } diff --git a/tools/decomp-assist/opus-art.attempts.md b/tools/decomp-assist/opus-art.attempts.md new file mode 100644 index 00000000..6a2c93ef --- /dev/null +++ b/tools/decomp-assist/opus-art.attempts.md @@ -0,0 +1,29 @@ +# opus-art: prior-art port attempts (library units) + +| unit | symbol | sources found | result | +|------|--------|---------------|--------| +| libs/RevoEX/src/nhttp/NHTTP_stdlib_RVL | NHTTPi_strnicmp | yannicksuter/mscharged-decomp src/RVL_SDK/nhttp/NHTTP_stdlib_RVL.c (+ configure note: NHTTP exact under GC/3.0a5 only); InusualZ/mhtri-decomp src/NHTTP/d_nhttp.c (non-matching there) | 2 -> 0. mscharged source alone stays at 2 under 3.0a5.2; our old int-helper source stays at 2 under 3.0a5; mscharged source + `mw_version="GC/3.0a5"` = exact. | +| libs/RevoEX/src/nhttp/NHTTP_stdlib_RVL | NHTTPi_compareToken | same | 2 -> 0, same fix. Unit fully exact, flipped to Matching, DOL SHA1 unchanged. Using a `LowerCase()` helper instead of the literal ternaries regresses (2 / 17 differing). | +| libs/RevoEX/src/net/aes | AESiEncryptBlock | none (searched AESiEncryptBlock, NETiAESEncryptoBlock, AESiRoundKeyRcon0, NET_AES_BLOCK_MODE_CBC, NETAESCreate: only symbol maps in riptl/wii-symbols and a WiiLink patch header) | no change; GC/3.0a5, 3.0a3.4, 3.0a3 give the same score | +| libs/RevoEX/src/net/aes | AESiDecryptBlock | none (same searches) | no change; same compiler sweep | +| libs/RVL_SDK/src/kbd/kbd_lib | kbdProcMod | headers only (DarkRTA/rb3 kbd.h, galaxymaster2007/THPConv kbd.h); robojumper/sdk_2009-12-11 has kpr_lib.c but no kbd_lib.c | no change (4 differing); compiler sweep no effect | +| libs/RVL_SDK/src/kbd/kbd_lib | kbd_led_handler | same | 3 differing; if/else, `err = 7; if (success == TRUE)`, reordered switch cases give 13-23 (worse); compiler sweep no effect | +| libs/RVL_SDK/src/kbd/kbd_lib | KBDSetModState | same | no change (4 differing) | +| libs/RVL_SDK/src/fa/driver/sd_drv | pfd_sddrv_init / pfd_sddrv_finalize / pfd_sddrv_build_fat32_mbr_bpb | ACreTeam/cf-decomp has only sd_drv.h (VF variant) and nand_drv.c (nanddrv_init/finalize: different body, saved to _refs/prior) | no portable code; compiler sweep no effect | +| libs/RVLMiddleware/TMC_JPEG/src/buffer/idct_block_var | TMCJPEGDEC_IdctBlock_Lumi / _Col | none outside upstream | no change; compiler sweep no effect | +| libs/RVLMiddleware/TMC_JPEG/src/texturecvtr/Texture_MCUtoRGBA8 | TMCJPEGDEC_set_converterRGBA8 / TMCJPEGDEC_converterYUV411toRGBA8 | none outside upstream | no change; compiler sweep no effect | +| libs/RVLMiddleware/TMC_JPEG/src/jpegdec/jdec_main | TMCJPEGDEC_err_restart (asm PLACEHOLDER) | none outside upstream | still asm | +| libs/RVL_SDK/src/cntcache/cntcache | CNTCACHEClear (asm PLACEHOLDER) | bgsamm/pbr-dtk cntcache.h (header only, saved); pret/pokerevo has asm only | still asm | + +Note for the NHTTP_recvbuf owner: mscharged-decomp builds all of NHTTP with GC/3.0a5 ("retail code keeps the older compiler's constant order and saved-register zeros ... exact under GC/3.0a5 only"). That is what fixed NHTTP_stdlib_RVL here, so NHTTPi_compareTokenN_HdrRecvBuf is worth trying with `mw_version="GC/3.0a5"` and mscharged's NHTTP_recvbuf.c (already in _refs/prior). + +## Round 2: readability +- NHTTP_stdlib_RVL: replaced the four inline tolower ternaries with `NHTTPi_TOLOWER(c)` macro. 14/14 exact, pool identical, DOL SHA1 26116613. `LowerCase()` kept (still used by NHTTPi_strToHex). + +## Round 2: NHTTP_recvbuf +- mw_version GC/3.0a5 alone: 6/7, compareTokenN still 5/124. +- Reference compareTokenN control flow (prior/yannicksuter_mscharged-decomp__NHTTP_recvbuf.c), with NHTTPi_TOLOWER macro: 0/124, 7/7. +- Same, without the gotos (if/else reads): 86/128. Rejected; goto form kept. +- Locate step through the existing FindHeaderBlock() helper: still 0/124. Kept. +- Removed the unused static LowerCase(): still 7/7, pool identical, ctxdiff diffs 0. +- Flipped to Matching: DOL SHA1 26116613. -- 2.49.1