diff --git a/libs/RVL_SDK/src/nup/nup.cpp b/libs/RVL_SDK/src/nup/nup.cpp index 4807bf90..6f025d0d 100644 --- a/libs/RVL_SDK/src/nup/nup.cpp +++ b/libs/RVL_SDK/src/nup/nup.cpp @@ -169,6 +169,7 @@ static inline char* __nupFindTag(char* response, const char* startTag, const cha char** value, size_t* length) { char* start; char* end; + /* MWCC needs the tag searches in this short-circuit expression. */ if (response == 0 || (start = strstr(response, startTag)) == 0 || (end = strstr(start, endTag)) == 0) { return 0; @@ -266,6 +267,7 @@ static s32 __nupParseServerInfo(NUPContextInfo* context, char* response, char* m titleCount = 0; cursor = response; { + /* MWCC needs both tag searches in the loop condition to preserve instruction order. */ while ((cursor = __nupFindTag(cursor, "", "", &start, &valueLength)) != 0 && (cursor = __nupFindTag(cursor, "", "", &start, &valueLength)) != 0) { titleCount++; @@ -285,6 +287,7 @@ static s32 __nupParseServerInfo(NUPContextInfo* context, char* response, char* m size_t titleLength; size_t versionLength; char* parsedEnd; + /* MWCC needs both tag searches in the loop condition to preserve instruction order. */ while ((cursor = __nupFindTag(cursor, "", "", &titleStart, &titleLength)) != 0 && (cursor = __nupFindTag(cursor, "", "", &versionStart, &versionLength)) != 0) { unsigned long long titleId = strtoull(titleStart, &parsedEnd, 16); @@ -424,6 +427,7 @@ static s32 __nupGetTicketViews(ESTitleId titleId, ESTicketView** ticketViews, u3 return result; } +/* MWCC must keep this helper out of line to match its callers. */ #pragma dont_inline on static u32 __nupSetAuditState(u8 state) { const char* auditPath = "NUPAUDIT"; @@ -618,6 +622,7 @@ done: return result; } +/* MWCC must keep this helper out of line to match its callers. */ #pragma dont_inline on static s32 __nupGetTmdView(ESTitleId titleId, ESTmdView** tmdView) { u32 tmdViewSize; @@ -646,10 +651,9 @@ static inline BOOL __nupHasContent(const Title* title, ESContentId contentId) { if (title->contentCount == 0 || title->contentIds == 0) { return FALSE; } - ESContentId* installedContent; u32 index; for (index = 0; index < title->contentCount; index++) { - if (contentId == *(installedContent = &title->contentIds[index])) { + if (contentId == title->contentIds[index]) { break; } } @@ -661,10 +665,9 @@ static inline BOOL __nupHasInstalledContent(const ESTitleVersion* title, ESConte if (contentCount == 0 || title->contentIds == 0) { return FALSE; } - ESContentId* installedContent; u32 index; for (index = 0; index < contentCount; index++) { - if (contentId == *(installedContent = &title->contentIds[index])) { + if (contentId == title->contentIds[index]) { break; } } @@ -841,7 +844,7 @@ static s32 __nupGetTmd(NUPTitleInfo* title, char* contentPrefixUrl) { result = -5000; } else { result = ES_DiGetTmdView((ESTitleMeta*)title->tmd, title->tmdSize, - (ESTmdView*)title->tmdView, &title->tmdViewSize); + title->tmdView, &title->tmdViewSize); if (result != 0) { nup::__nupFree(title->tmdView); title->tmdView = 0; @@ -907,10 +910,10 @@ static s32 __nupGetContentFull(NUPContextInfo* context, NUPTitleInfo* title, cha char* url = 0; u8* response = 0; unsigned long responseSize = 0; - tmdView = (ESTmdView*)title->tmdView; + tmdView = title->tmdView; for (contentIndex = 0; contentIndex < tmdView->head.numContents; contentIndex++) { - if (contentId == ((ESTmdView*)title->tmdView)->contents[contentIndex].cid) { + if (contentId == title->tmdView->contents[contentIndex].cid) { break; } } @@ -954,11 +957,11 @@ static s32 __nupGetContentIncr(NUPContextInfo* context, NUPTitleInfo* title, cha if (url == 0) { result = -5000; } else { - for (contentIndex = 0; contentIndex < ((ESTmdView*)title->tmdView)->head.numContents; contentIndex++) { - ESContentId contentId = ((ESTmdView*)title->tmdView)->contents[contentIndex].cid; + for (contentIndex = 0; contentIndex < title->tmdView->head.numContents; contentIndex++) { + ESContentId contentId = title->tmdView->contents[contentIndex].cid; if (!__nupHasContent(title, contentId)) { snprintf(url, urlSize, "%s/%016llx/%08x", contentPrefixUrl, title->titleId, contentId); - unsigned long contentSize = (u32)((((ESTmdView*)title->tmdView)->contents[contentIndex].size + 0xf) & 0xfffffffffffffff0ULL); + unsigned long contentSize = (u32)((title->tmdView->contents[contentIndex].size + 0xf) & 0xfffffffffffffff0ULL); ESFd fd = ES_ImportContentBegin(title->titleId, contentId); result = fd; if (result < 0) { @@ -1021,6 +1024,7 @@ static void __nupCleanup(NUPContextInfo* context) { if (context->titles != 0) { for (u32 i = 0; i < context->titleCount; i++) { NUPTitleInfo* title = &context->titles[i]; + /* MWCC emits a separate null check before title cleanup. */ if (title != 0) { __nupCleanupTitleInfo(title); } @@ -1072,7 +1076,7 @@ static s32 __nupUpdateTitle(NUPContextInfo* context, NUPTitleInfo* title, char* if (result != 0) { goto done; } - ESTmdView* tmdView = (ESTmdView*)title->tmdView; + ESTmdView* tmdView = title->tmdView; if (tmdView->head.numContents != 1) { result = -0x1389; goto done; @@ -1135,8 +1139,11 @@ static inline s32 __nupGetBoot2Version(u16* version) { s32 result = ES_GetBoot2Version(&bootVersion); if (result == 0) { u16 checkedVersion = bootVersion; - if (checkedVersion != bootVersion) { result = -0x1389; } - if (checkedVersion == bootVersion) { *version = checkedVersion; } + if (checkedVersion != bootVersion) { + result = -0x1389; + } else { + *version = checkedVersion; + } } return result; } @@ -1323,7 +1330,7 @@ extern "C" void* __nupOp(void* argument) { } } if (menuTitle != 0 && menuTitle->updateRequired != 0) { - ESTitleId requiredSystemTitle = ((ESTmdView*)menuTitle->tmdView)->head.sysVersion; + ESTitleId requiredSystemTitle = menuTitle->tmdView->head.sysVersion; for (i = 0; i < context->titleCount; i++) { if (context->titles[i].titleId == requiredSystemTitle) { systemTitle = &context->titles[i]; @@ -1390,7 +1397,8 @@ void* NUP_Init(MEMAllocator* allocator) { NUPContextInfo* context = (NUPContextInfo*)instance; OSInitMutex(&context->mutex); OSLockMutex(&context->mutex); - context->progress.message = (context->progress.result = 1, __nupStatusMessage[1]); + context->progress.result = 1; + context->progress.message = __nupStatusMessage[1]; OSUnlockMutex(&context->mutex); } } @@ -1444,6 +1452,7 @@ int NUP_Start(void* instance, const char* serverAddress, const char* countryCode if (result < 0) { OSLockMutex(&context->mutex); context->progress.result = result; + /* MWCC retains these status alternatives under the negative-result guard. */ if (result < 0) { context->progress.message = __nupStatusMessage[5]; } else { diff --git a/libs/RVL_SDK/src/nup/nup_nhttp.cpp b/libs/RVL_SDK/src/nup/nup_nhttp.cpp index 5252924b..8a9b0de1 100644 --- a/libs/RVL_SDK/src/nup/nup_nhttp.cpp +++ b/libs/RVL_SDK/src/nup/nup_nhttp.cpp @@ -73,6 +73,7 @@ static u8* __nupNhttpBufFull(u8** buffer, unsigned long* length, unsigned long r if (state->error != 0) goto done; } next = *buffer; + /* MWCC needs the switch's extra branch around buffer allocation. */ switch ((u32)next) { case 0: { requested = NhttpBufferSize(requested); @@ -142,6 +143,7 @@ static int __nupNhttpOp(char* url, NHTTPReqMethod method, char* headers, u8* bod char* field = headerCopy; char* colon; char* end; + /* MWCC needs the header searches in this loop condition to preserve instruction order. */ while (*field != 0 && (colon = strchr(field, ':')) != NULL && (end = strstr(colon, "\r\n")) != NULL) { *colon = 0; *end = 0; @@ -194,7 +196,6 @@ static int __nupNhttpOp(char* url, NHTTPReqMethod method, char* headers, u8* bod goto cleanup; } if (status != 200 && status != 202) result = -5000 - status; - goto cleanup; cleanup: if (state.response != NULL || result == -5009) NHTTPDestroyResponse(state.response); if (headerCopy != NULL) nup::__nupFree(headerCopy); @@ -233,6 +234,7 @@ static long __nupHttpStringFlush(u8* data, unsigned long length, unsigned long r return AppendHttpString(length, data, requested, (HttpString*)context); } } +/* MWCC must keep this helper out of line to match its callers. */ static int __nupNhttpOpString(u8** output, unsigned long* outputLength, char* url, NHTTPReqMethod method, char* headers, u8* body, unsigned long bodyLength, unsigned long limit, ProgressCallback progress, void* context) NO_INLINE; static int __nupNhttpOpString(u8** output, unsigned long* outputLength, char* url, NHTTPReqMethod method, char* headers, u8* body, unsigned long bodyLength, unsigned long limit, ProgressCallback progress, void* context) { HttpString text; diff --git a/libs/RevoEX/src/nwc24/NWC24MsgSubject.c b/libs/RevoEX/src/nwc24/NWC24MsgSubject.c index 23fde3f3..7c0f95ee 100644 --- a/libs/RevoEX/src/nwc24/NWC24MsgSubject.c +++ b/libs/RevoEX/src/nwc24/NWC24MsgSubject.c @@ -199,6 +199,7 @@ NWC24Err NWC24SetMsgSubjectPublic(NWC24MsgObj* msg, const u16* subject, u32 subj nwcWork = NWC24WorkP; result = NWC24iDetectEncodingToSend(nwcWork->stringWork, 0x40, subject, subjectSize, NULL, 0, region); + /* MWCC needs the success-only switches to retain their extra branches. */ switch (result) { case NWC24_OK: break; @@ -206,29 +207,29 @@ NWC24Err NWC24SetMsgSubjectPublic(NWC24MsgObj* msg, const u16* subject, u32 subj goto done; } if (NWC24ParseCharsetStr(&charset, nwcWork->stringWork) != NWC24_OK) { - charset = 0; + charset = NWC24_US_ASCII; } - if (charset == 0) { + if (charset == NWC24_US_ASCII) { result = NWC24iSetMsgSubjectPlain(msg, subject, subjectSize, region, alternative, work, workSize, charset, nwcWork->stringWork); goto done; } switch (region) { - case 0: - result = 2; + case NWC24_ENCODING_REGION_JPN: + result = NWC24_ENC_BASE64; break; - case 1: - case 2: - result = 3; + case NWC24_ENCODING_REGION_USA: + case NWC24_ENCODING_REGION_EUR: + result = NWC24_ENC_QUOTED_PRINTABLE; break; - case 3: - case 4: - result = 2; + case NWC24_ENCODING_REGION_KOR: + case NWC24_ENCODING_REGION_CHN: + result = NWC24_ENC_BASE64; break; default: - result = 2; + result = NWC24_ENC_BASE64; break; } - if (result == 3) { + if (result == NWC24_ENC_QUOTED_PRINTABLE) { result = NWC24iSetMsgSubjectQP(msg, subject, subjectSize, region, alternative, work, workSize, charset, nwcWork->stringWork); } else { result = NWC24iSetMsgSubjectBase64(msg, subject, subjectSize, region, alternative, work, workSize, charset, nwcWork->stringWork); @@ -275,6 +276,7 @@ NWC24Err NWC24SetMsgSubjectAndTextPublic(NWC24MsgObj* msg, const u16* subject, u nwcWork = NWC24WorkP; result = NWC24iDetectEncodingToSend(nwcWork->stringWork, 0x40, subject, subjectSize, text, textSize, region); + /* MWCC needs the success-only switches to retain their extra branches. */ switch (result) { case NWC24_OK: break; @@ -282,7 +284,7 @@ NWC24Err NWC24SetMsgSubjectAndTextPublic(NWC24MsgObj* msg, const u16* subject, u goto done; } if (NWC24ParseCharsetStr(&charset, nwcWork->stringWork) != NWC24_OK) { - charset = 0; + charset = NWC24_US_ASCII; } textCapacity = (workSize * textSize) / (textSize + subjectSize * 4); textWorkSize = textCapacity; @@ -300,23 +302,23 @@ NWC24Err NWC24SetMsgSubjectAndTextPublic(NWC24MsgObj* msg, const u16* subject, u result = ENCIs7BitEncoding(&is7Bit, nwcWork->stringWork); if (!is7Bit || (result != ENC_OK)) { switch (region) { - case 0: - result = 2; + case NWC24_ENCODING_REGION_JPN: + result = NWC24_ENC_BASE64; break; - case 1: - case 2: - result = 3; + case NWC24_ENCODING_REGION_USA: + case NWC24_ENCODING_REGION_EUR: + result = NWC24_ENC_QUOTED_PRINTABLE; break; - case 3: - case 4: - result = 2; + case NWC24_ENCODING_REGION_KOR: + case NWC24_ENCODING_REGION_CHN: + result = NWC24_ENC_BASE64; break; default: - result = 2; + result = NWC24_ENC_BASE64; break; } } else { - result = 0; + result = NWC24_ENC_7BIT; } result = NWC24SetMsgText(msg, (char*)work, textWorkSize - 1, charset, result); switch (result) { @@ -325,27 +327,27 @@ NWC24Err NWC24SetMsgSubjectAndTextPublic(NWC24MsgObj* msg, const u16* subject, u default: goto done; } - if (charset == 0) { + if (charset == NWC24_US_ASCII) { result = NWC24iSetMsgSubjectPlain(msg, subject, subjectSize, region, alternative, subjectWork, subjectWorkSize, charset, nwcWork->stringWork); goto done; } switch (region) { - case 0: - result = 2; + case NWC24_ENCODING_REGION_JPN: + result = NWC24_ENC_BASE64; break; - case 1: - case 2: - result = 3; + case NWC24_ENCODING_REGION_USA: + case NWC24_ENCODING_REGION_EUR: + result = NWC24_ENC_QUOTED_PRINTABLE; break; - case 3: - case 4: - result = 2; + case NWC24_ENCODING_REGION_KOR: + case NWC24_ENCODING_REGION_CHN: + result = NWC24_ENC_BASE64; break; default: - result = 2; + result = NWC24_ENC_BASE64; break; } - if (result == 3) { + if (result == NWC24_ENC_QUOTED_PRINTABLE) { result = NWC24iSetMsgSubjectQP(msg, subject, subjectSize, region, alternative, subjectWork, subjectWorkSize, charset, nwcWork->stringWork); } else { result = @@ -360,33 +362,32 @@ NWC24Err NWC24iGetDefaultCharset(char* charset, u32 charsetSize, NWC24EncodingRe NWC24Err result = NWC24_OK; switch (region) { - case 0: + case NWC24_ENCODING_REGION_JPN: strncpy(charset, DefaultCharsetJp, charsetSize - 1); charset[charsetSize - 1] = 0; - goto done; - case 1: + break; + case NWC24_ENCODING_REGION_USA: strncpy(charset, "iso-8859-1", charsetSize - 1); charset[charsetSize - 1] = 0; - goto done; - case 2: + break; + case NWC24_ENCODING_REGION_EUR: strncpy(charset, "iso-8859-1", charsetSize - 1); charset[charsetSize - 1] = 0; - goto done; - case 3: + break; + case NWC24_ENCODING_REGION_KOR: strncpy(charset, DefaultCharsetKr, charsetSize - 1); charset[charsetSize - 1] = 0; - goto done; - case 4: + break; + case NWC24_ENCODING_REGION_CHN: strncpy(charset, "gb2312", charsetSize - 1); charset[charsetSize - 1] = 0; - goto done; + break; default: strncpy(charset, "iso-8859-1", charsetSize - 1); charset[charsetSize - 1] = 0; result = NWC24_ERR_INVALID_VALUE; } -done: return result; } @@ -403,6 +404,7 @@ NWC24Err NWC24iConvertToInternalEncoding(u16* dst, u32* dstSize, const u8* src, result = NWC24_ERR_OVERFLOW; goto done; } + /* MWCC needs the success switch and short-circuit setup for this instruction order. */ if (charset[0] == '\0') { result = NWC24iGetDefaultCharset(charset, charsetSize, region); switch (result) { @@ -421,52 +423,29 @@ NWC24Err NWC24iConvertToInternalEncoding(u16* dst, u32* dstSize, const u8* src, dst[convertedBytes >> 1] = 0; *dstSize = (convertedBytes >> 1) + 1; } - if (result == ENC_ERR_NO_MAP_RULE) { - goto invalidCharacter; + switch (result) { + case ENC_OK: + result = NWC24_OK; + break; + case ENC_ERR_INVALID_PARAM: + result = NWC24_ERR_INVALID_VALUE; + break; + case ENC_ERR_NO_BUF_LEFT: + result = NWC24_ERR_OVERFLOW; + break; + case ENC_ERR_NO_MAP_RULE: + case ENC_ERR_INVALID_FORMAT: + result = NWC24_ERR_INVALID_CHAR; + break; + case ENC_ERR_UNKNOWN_ENCODING: + case ENC_ERR_UNSUPPORTED: + case ENC_ERR_NOT_LOADED: + result = NWC24_ERR_NOT_SUPPORTED; + break; + default: + result = NWC24_ERR_FATAL; + break; } - if (result < ENC_ERR_NO_MAP_RULE) { - if (result == ENC_ERR_INVALID_FORMAT) { - goto invalidCharacter; - } - if (result >= ENC_ERR_INVALID_FORMAT) { - goto invalidValue; - } - if (result >= ENC_ERR_NOT_LOADED) { - goto notSupported; - } - } else { - if (result == ENC_OK) { - goto success; - } - if (result >= ENC_OK) { - goto fatal; - } - goto overflow; - } - goto fatal; - -success: - result = ENC_OK; - goto done; - -invalidValue: - result = NWC24_ERR_INVALID_VALUE; - goto done; - -overflow: - result = NWC24_ERR_OVERFLOW; - goto done; - -invalidCharacter: - result = NWC24_ERR_INVALID_CHAR; - goto done; - -notSupported: - result = NWC24_ERR_NOT_SUPPORTED; - goto done; - -fatal: - result = NWC24_ERR_FATAL; done: return result; @@ -486,6 +465,7 @@ NWC24Err NWC24iConvertFromInternalEncoding(u8* dst, u32* dstSize, const u16* src result = NWC24_ERR_OVERFLOW; goto done; } + /* MWCC needs the success switch and short-circuit setup for this instruction order. */ if (charset[0] == '\0') { result = NWC24iGetDefaultCharset(charset, charsetSize, region); switch (result) { @@ -506,51 +486,29 @@ NWC24Err NWC24iConvertFromInternalEncoding(u8* dst, u32* dstSize, const u16* src *srcSize = inputBytes >> 1; *dstSize = outputBytes + 1; } - if (result == ENC_ERR_NO_MAP_RULE) { - goto invalidCharacter; + switch (result) { + case ENC_OK: + result = NWC24_OK; + break; + case ENC_ERR_INVALID_PARAM: + result = NWC24_ERR_INVALID_VALUE; + break; + case ENC_ERR_NO_BUF_LEFT: + result = NWC24_ERR_OVERFLOW; + break; + case ENC_ERR_NO_MAP_RULE: + case ENC_ERR_INVALID_FORMAT: + result = NWC24_ERR_INVALID_CHAR; + break; + case ENC_ERR_UNKNOWN_ENCODING: + case ENC_ERR_UNSUPPORTED: + case ENC_ERR_NOT_LOADED: + result = NWC24_ERR_NOT_SUPPORTED; + break; + default: + result = NWC24_ERR_FATAL; + break; } - if (result < ENC_ERR_NO_MAP_RULE) { - if (result == ENC_ERR_INVALID_FORMAT) { - goto invalidCharacter; - } - if (result >= ENC_ERR_INVALID_FORMAT) { - goto invalidValue; - } - if (result >= ENC_ERR_NOT_LOADED) { - goto notSupported; - } - goto fatal; - } - if (result == ENC_OK) { - goto success; - } - if (result >= ENC_OK) { - goto fatal; - } - goto overflow; - -success: - result = ENC_OK; - goto done; - -invalidValue: - result = NWC24_ERR_INVALID_VALUE; - goto done; - -overflow: - result = NWC24_ERR_OVERFLOW; - goto done; - -invalidCharacter: - result = NWC24_ERR_INVALID_CHAR; - goto done; - -notSupported: - result = NWC24_ERR_NOT_SUPPORTED; - goto done; - -fatal: - result = NWC24_ERR_FATAL; done: return result; @@ -572,20 +530,20 @@ NWC24Err NWC24iDetectEncodingToSend(char* charset, u32 charsetSize, const u16* s startIndex = 0; lastIndex = -1; switch (region) { - case 0: + case NWC24_ENCODING_REGION_JPN: names = JapaneseCharsets; numNames = 3; break; - case 1: - case 2: + case NWC24_ENCODING_REGION_USA: + case NWC24_ENCODING_REGION_EUR: names = WesternCharsets; numNames = 8; break; - case 3: + case NWC24_ENCODING_REGION_KOR: names = KoreanCharsets; numNames = 3; break; - case 4: + case NWC24_ENCODING_REGION_CHN: names = ChineseCharsets; numNames = 2; break; @@ -642,7 +600,7 @@ NWC24Err NWC24iDetectBreakPoint(u32* breakPoint, NWC24Charset charset, const u8* if ((breakPoint == NULL) || (text == NULL)) { return NWC24_ERR_INVALID_VALUE; } - if (charset == 0) { + if (charset == NWC24_US_ASCII) { byteEncoding = TRUE; } else if (charset == NWC24_UTF_8) { byteEncoding = FALSE; @@ -797,7 +755,7 @@ NWC24Err NWC24iSetMsgSubjectQP(NWC24MsgObj* msg, const u16* subject, u32 subject charsetLength = (0x40 - strlen(charsetName)) / 3; total = outputLength - 1; workHalf = secondSize; - for (; sourceOffset < subjectLength;) { + while (sourceOffset < subjectLength) { if (workHalf - total < 3) { result = NWC24_ERR_OVERFLOW; goto done; @@ -808,6 +766,7 @@ NWC24Err NWC24iSetMsgSubjectQP(NWC24MsgObj* msg, const u16* subject, u32 subject NWC24iDetectBreakPoint(&lineLength, charset, work + sourceOffset, subjectLength - sourceOffset, charsetLength); result = NWC24EncodeWord(second + total, workHalf - total, &outputLength, charsetName, 0x40, 'Q', work + sourceOffset, lineLength); + /* MWCC needs this success-only switch's extra branch. */ switch (result) { case NWC24_OK: break; @@ -829,6 +788,7 @@ done: NWC24Err NWC24iSetMsgSubjectBase64(NWC24MsgObj* msg, const u16* subject, u32 subjectSize, NWC24EncodingRegion region, u16 alternative, u8* work, u32 workSize, NWC24Charset charset, char* charsetName) { + /* MWCC needs a const input alias to preserve the conversion-call registers. */ const u8* encodedInput = work; u8* second; u32 secondSize; @@ -852,6 +812,7 @@ NWC24Err NWC24iSetMsgSubjectBase64(NWC24MsgObj* msg, const u16* subject, u32 sub subjectLength = subjectSize; result = NWC24iConvertFromInternalEncoding(work, &workHalf, subject, &subjectLength, charsetName, 0x40, region, alternative); if (result != NWC24_OK) { + /* MWCC needs the success-only switches to retain their extra branches. */ switch (result) { case NWC24_ERR_OVERFLOW: break; default: goto done; @@ -867,7 +828,7 @@ NWC24Err NWC24iSetMsgSubjectBase64(NWC24MsgObj* msg, const u16* subject, u32 sub charsetLength = strlen(charsetName); lineLength = (((0x3E - charsetLength) * 3) >> 2) + 1; total = outputLength - 1; - for (; sourceOffset < subjectSize;) { + while (sourceOffset < subjectSize) { subjectLength = subjectSize - sourceOffset; workHalf = lineLength; if (secondSize - total < 3) { diff --git a/libs/RevoEX/src/wd/WDScan.c b/libs/RevoEX/src/wd/WDScan.c index eff3e0db..8f4272a5 100644 --- a/libs/RevoEX/src/wd/WDScan.c +++ b/libs/RevoEX/src/wd/WDScan.c @@ -16,6 +16,7 @@ const u8 scWpaOui0 = 0; const u8 scWpaOui1 = 0x50; const u8 scWpaOui2 = 0xF2; const u8 scWpaOuiPad = 0; +/* MWCC places the WPA search bytes in .sdata. */ #pragma push #pragma section sconst_type ".sdata" const u8 scWpaFindOui0 = 0; @@ -28,6 +29,7 @@ const u8 scWpaFindOuiPad3 = 0; const u8 scWpaFindOuiPad4 = 0; #pragma pop +/* MWCC must load the OUI bytes from memory instead of folding their values. */ #define scRsnOui0 (*((volatile const u8*)&scRsnOui0)) #define scRsnOui1 (*((volatile const u8*)&scRsnOui1)) #define scRsnOui2 (*((volatile const u8*)&scRsnOui2)) @@ -96,68 +98,58 @@ static inline s32 GetResultNCD(s32 result) { s32 WDCheckEnableChannel(u16* enableChannel) { s32 id; + s32 result; + s32 infoResult; if (enableChannel != NULL) { *enableChannel = 0; } id = NCDLockWirelessDriver(); - if (id <= 0) { - goto ncd_err; - } else { - s32 result = WD_Startup(3); - s32 result2; + if (id > 0) { + result = WD_Startup(3); if (result == WD_INTERNAL_ERR_OK) { WD_Info info; - result2 = WD_GetInfo(&info); - if (result2 == WD_INTERNAL_ERR_OK && enableChannel != NULL) { + infoResult = WD_GetInfo(&info); + if (infoResult == WD_INTERNAL_ERR_OK && enableChannel != NULL) { *enableChannel = info.enableChannel; } WAIT_FOR_OPERATION(WD_Cleanup()); } WAIT_FOR_OPERATION(NCDUnlockWirelessDriver(id)); - goto wd_err; - - ncd_err: + } else { return GetResultNCD(id); - - wd_err: - if (result == WD_ERR_OK) { - return GetResultWD(result2); - } else { - return GetResultWD(result); - } + } + if (result == WD_ERR_OK) { + return GetResultWD(infoResult); + } else { + return GetResultWD(result); } } s32 WDScanOnce(u8* scanBuffer, u32 scanBufferLen, WDScanParam* param) { s32 id; + s32 result; + s32 scanResult; id = NCDLockWirelessDriver(); - if (id <= 0) { - goto ncd_err; - } else { - s32 result = WD_Startup(3); - s32 result2; + if (id > 0) { + result = WD_Startup(3); if (result == WD_INTERNAL_ERR_OK) { memset(scanBuffer, 0, scanBufferLen); - result2 = WD_Scan(param, scanBuffer, scanBufferLen); + scanResult = WD_Scan(param, scanBuffer, scanBufferLen); WAIT_FOR_OPERATION(WD_Cleanup()); } WAIT_FOR_OPERATION(NCDUnlockWirelessDriver(id)); - goto wd_err; - - ncd_err: + } else { return GetResultNCD(id); - - wd_err: - if (result == WD_ERR_OK) { - return GetResultWD(result2); - } else { - return GetResultWD(result); - } + } + if (result == WD_ERR_OK) { + return GetResultWD(scanResult); + } else { + return GetResultWD(result); } } @@ -175,93 +167,55 @@ s32 WDGetPrivacyMode(WDBssDesc* bssDesc) { data[2] = scRsnOui2; memcpy(readIE, ieData, sizeof(WDVendorInfoElement) + 2); if (memcmp(&readIE[2], data, WD_VENDOR_LENGTH) == 0) { - if ((s32)readIE[5] == 3) { - goto privacy_second; + switch (readIE[5]) { + case 1: + return WD_PRIVACY_MODE_DS_COMMUNICATION; + case 2: + return WD_PRIVACY_MODE_7; + case 3: + break; + case 4: + return WD_PRIVACY_MODE_5; + case 5: + return WD_PRIVACY_MODE_2; + default: + break; } - if ((s32)readIE[5] >= 3) { - goto privacy_rsn_high; - } - if ((s32)readIE[5] == 1) { - goto privacy_rsn_mode1; - } - if ((s32)readIE[5] >= 1) { - goto privacy_rsn_mode7; - } - goto privacy_second; - privacy_rsn_high: - if ((s32)readIE[5] == 5) { - goto privacy_rsn_mode2; - } - if ((s32)readIE[5] >= 5) { - goto privacy_second; - } - goto privacy_rsn_mode5; } } - goto privacy_second; -privacy_rsn_mode1: - return WD_PRIVACY_MODE_DS_COMMUNICATION; -privacy_rsn_mode7: - return WD_PRIVACY_MODE_7; -privacy_rsn_mode5: - return WD_PRIVACY_MODE_5; -privacy_rsn_mode2: - return WD_PRIVACY_MODE_2; - -privacy_second: { + { u8 data[WD_VENDOR_LENGTH]; u8 findData[WD_VENDOR_LENGTH]; findData[0] = scWpaFindOui0; findData[1] = scWpaFindOui1; findData[2] = scWpaFindOui2; - if (!WDiFindVendorSpecificIE(&ieData, &ieLength, bssDesc, 0xDD, findData, 1)) { - goto privacy_fallback; - } - data[0] = scWpaOui0; - data[1] = scWpaOui1; - data[2] = scWpaOui2; + if (WDiFindVendorSpecificIE(&ieData, &ieLength, bssDesc, 0xDD, findData, 1)) { + data[0] = scWpaOui0; + data[1] = scWpaOui1; + data[2] = scWpaOui2; - { memcpy(readIE, ieData, sizeof(WDVendorInfoElement)); - if (memcmp(&readIE[2], data, WD_VENDOR_LENGTH) != 0) { - goto privacy_fallback; + if (memcmp(&readIE[2], data, WD_VENDOR_LENGTH) == 0) { + switch (readIE[5]) { + case 1: + return WD_PRIVACY_MODE_DS_COMMUNICATION; + case 2: + return WD_PRIVACY_MODE_4; + case 3: + break; + case 4: + return WD_PRIVACY_MODE_6; + case 5: + return WD_PRIVACY_MODE_2; + default: + break; + } } - if ((s32)readIE[5] == 3) { - goto privacy_fallback; - } - if ((s32)readIE[5] >= 3) { - goto privacy_wpa_high; - } - if ((s32)readIE[5] == 1) { - goto privacy_wpa_mode1; - } - if ((s32)readIE[5] >= 1) { - goto privacy_wpa_mode4; - } - goto privacy_fallback; - privacy_wpa_high: - if ((s32)readIE[5] == 5) { - goto privacy_wpa_mode2; - } - if ((s32)readIE[5] >= 5) { - goto privacy_fallback; - } - goto privacy_wpa_mode6; } } -privacy_wpa_mode1: - return WD_PRIVACY_MODE_DS_COMMUNICATION; -privacy_wpa_mode4: - return WD_PRIVACY_MODE_4; -privacy_wpa_mode6: - return WD_PRIVACY_MODE_6; -privacy_wpa_mode2: - return WD_PRIVACY_MODE_2; - -privacy_fallback: if (bssDesc != NULL && (bssDesc->capabilities & 0x10) == 0x10) { result = WD_PRIVACY_MODE_8; } else { diff --git a/tools/decomp-assist/cleanup2-w4.attempts.md b/tools/decomp-assist/cleanup2-w4.attempts.md new file mode 100644 index 00000000..a47ed8ba --- /dev/null +++ b/tools/decomp-assist/cleanup2-w4.attempts.md @@ -0,0 +1,110 @@ +# cleanup2-w4 attempts + +Scope: NWC24MsgSubject.c, nup.cpp, nup_nhttp.cpp, WDScan.c. +Baseline: 85d653b0, clean branch agent/w1009/cleanup2-w4. +Read cleanup-common.md, including wave-2 goto/comma guidance, AGENTS.md, unslop, graphify, and writing-for-agents. +Initial full 43U build passed; DECOMPLETE_OK; DOL SHA1 26116613f624061ba99c8d1a299aaa6efa85670d. +All four units are Matching with every code/data section at 100%. +Keep common error/cleanup exits; test each structural cleanup separately and restore any byte-changing trial. +Earlier cleanup logs contain no attempts for these four files. + +## Trials + +- REVERT `nup.cpp`: remove __nupSetAuditState dont_inline pragmas. sections ['.data', '.text'], relocations ['.text'], functions ['__nupOp size 1844/1752', '__nupSetAuditState__FUc missing'] +- REVERT `nup.cpp`: remove __nupGetTmdView dont_inline pragmas. sections ['.text'], relocations ['.text'], functions ['__nupGetBootVersion__FP14NUPContextInfoP14ESTitleVersion size 752/652', '__nupGetTmdView__FUxPP9ESTmdView missing', '__nupOp size 1952/1752'] +- REVERT `WDScan.c`: replace nine volatile access macros with definition-level volatile const. sections ['.sdata', '.sbss', '.sbss2', '.text', '.sdata2'], relocations ['.text'], functions ['WDGetPrivacyMode size 468/460'] +- REVERT `WDScan.c`: WDCheckEnableChannel structured driver error returns. sections ['.text'], relocations ['.text'], functions ['WDCheckEnableChannel size 652/656'] +- REVERT `WDScan.c`: WDScanOnce structured driver error returns. sections ['.text'], relocations ['.text'], functions ['WDScanOnce size 644/648'] +- KEEP `nup.cpp`: NUP_Init split comma assignment into two statements. All allocated sections, function bytes, and relocations equal baseline. +- REVERT `nup.cpp`: __nupHasContent remove assignment within dereference. sections [], relocations ['.text'], functions [] +- REVERT `nup.cpp`: __nupHasInstalledContent remove assignment within dereference. sections [], relocations ['.text'], functions [] +- REVERT `nup.cpp`: NUP_Start remove unreachable status alternatives. sections ['.text'], relocations ['.text'], functions ['NUP_Start size 448/508'] +- REVERT `nup.cpp`: __nupCleanup remove redundant nested title null test. sections ['.text'], relocations ['.text'], functions ['__nupCleanup__FP14NUPContextInfo size 272/276'] +- REVERT `nup.cpp`: __nupGetBoot2Version use else for successful narrowing. sections [], relocations ['.text'], functions [] +- KEEP `nup.cpp`: remove redundant casts of typed tmdView pointers. All allocated sections, function bytes, and relocations equal baseline. +- REVERT `nup_nhttp.cpp`: __nupNhttpBufFull replace pointer switch with null check. sections ['.text'], relocations ['.text'], functions ['__nupNhttpBufFull size 384/388'] +- REVERT `nup_nhttp.cpp`: __nupNhttpOp remove goto immediately before cleanup label. sections [], relocations ['.text'], functions [] +- REVERT `WDScan.c`: WDCheckEnableChannel structured success branch before NCD failure return. sections ['.text'], relocations ['.text'], functions ['WDCheckEnableChannel size 652/656'] +- REVERT `WDScan.c`: WDScanOnce structured success branch before NCD failure return. sections ['.text'], relocations ['.text'], functions ['WDScanOnce size 644/648'] + +Relocation comparison correction: MWCC renumbers internal string symbols when tokens change. Compare defined relocation symbols by section and offset, and undefined symbols by name; revisit the four trials whose only difference was an internal relocation symbol name. + +- KEEP `nup.cpp`: __nupHasContent remove assignment within dereference. All allocated sections, function bytes, and relocations equal baseline. +- KEEP `nup.cpp`: __nupHasInstalledContent remove assignment within dereference. All allocated sections, function bytes, and relocations equal baseline. +- REVERT `nup.cpp`: NUP_Start remove unreachable status alternatives. sections ['.text'], relocations ['.text'], functions ['NUP_Start size 448/508'] +- REVERT `nup.cpp`: __nupCleanup remove redundant nested title null test. sections ['.text'], relocations ['.text'], functions ['__nupCleanup__FP14NUPContextInfo size 272/276'] +- KEEP `nup.cpp`: __nupGetBoot2Version use else for successful narrowing. All allocated sections, function bytes, and relocations equal baseline. +- REVERT `nup_nhttp.cpp`: __nupNhttpBufFull replace pointer switch with null check. sections ['.text'], relocations ['.text'], functions ['__nupNhttpBufFull size 384/388'] +- KEEP `nup_nhttp.cpp`: __nupNhttpOp remove goto immediately before cleanup label. All allocated sections, function bytes, and relocations equal baseline. +- REVERT `WDScan.c`: WDCheckEnableChannel structured success branch before NCD failure return. sections ['.text'], relocations ['.text'], functions ['WDCheckEnableChannel size 652/656'] +- REVERT `WDScan.c`: WDScanOnce structured success branch before NCD failure return. sections ['.text'], relocations ['.text'], functions ['WDScanOnce size 644/648'] +- REVERT `NWC24MsgSubject.c`: NWC24iConvertToInternalEncoding replace error dispatch gotos with structured conditions. sections ['.text'], relocations ['.text'], functions ['NWC24iConvertToInternalEncoding size 392/388'] +- REVERT `NWC24MsgSubject.c`: NWC24iConvertToInternalEncoding replace error dispatch gotos with enum switch. sections ['.text'], relocations [], functions ['NWC24iConvertToInternalEncoding diffs 7/97'] +- REVERT `NWC24MsgSubject.c`: NWC24iConvertFromInternalEncoding replace error dispatch gotos with structured conditions. sections ['.text'], relocations ['.text'], functions ['NWC24iConvertFromInternalEncoding size 404/400'] +- REVERT `NWC24MsgSubject.c`: NWC24iConvertFromInternalEncoding replace error dispatch gotos with enum switch. sections ['.text'], relocations [], functions ['NWC24iConvertFromInternalEncoding diffs 7/100'] +- REVERT `NWC24MsgSubject.c`: NWC24iConvertToInternalEncoding separate encoding setup assignments from condition. sections ['.text'], relocations [], functions ['NWC24iConvertToInternalEncoding diffs 4/97'] +- REVERT `NWC24MsgSubject.c`: NWC24iConvertFromInternalEncoding separate encoding setup assignments from condition. sections ['.text'], relocations [], functions ['NWC24iConvertFromInternalEncoding diffs 4/100'] +- KEEP `NWC24MsgSubject.c`: use existing encoding-region enum names. All allocated sections, function bytes, and relocations equal baseline. +- KEEP `WDScan.c`: WDGetPrivacyMode structure RSN cipher dispatch as switch. All allocated sections, function bytes, and relocations equal baseline. +- KEEP `WDScan.c`: WDGetPrivacyMode structure WPA cipher dispatch and fallback as switch. All allocated sections, function bytes, and relocations equal baseline. +- REVERT `WDScan.c`: remove OUI volatile access macros and use plain constants. sections ['.text'], relocations ['.text'], functions ['WDGetPrivacyMode size 468/460'] +- KEEP `WDScan.c`: WDCheckEnableChannel place NCD failure else before shared WD result dispatch. All allocated sections, function bytes, and relocations equal baseline. +- KEEP `WDScan.c`: WDScanOnce place NCD failure else before shared WD result dispatch. All allocated sections, function bytes, and relocations equal baseline. +- REVERT `nup_nhttp.cpp`: __nupNhttpOp split header parsing assignments from loop condition. sections ['.text'], relocations ['.text'], functions ['__nupNhttpOp__FPc14NHTTPReqMethodPcPUcUlUlPFPvUl_vPvPFPUcUlUlPv_lPv diffs 84/348'] +- REVERT `nup.cpp`: __nupFindTag separate tag searches from null tests. sections ['.text'], relocations ['.text'], functions ['__nupParseServerInfo__FP14NUPContextInfoPcPcUx size 1984/1808'] +- REVERT `nup.cpp`: __nupParseServerInfo split counting loop assignments. sections ['.text'], relocations ['.text'], functions ['__nupParseServerInfo__FP14NUPContextInfoPcPcUx diffs 39/452'] +- REVERT `nup.cpp`: __nupParseServerInfo split title parsing loop assignments. sections ['.text'], relocations ['.text'], functions ['__nupParseServerInfo__FP14NUPContextInfoPcPcUx diffs 86/452'] +- KEEP `NWC24MsgSubject.c`: NWC24iConvertToInternalEncoding enum switch with original result-block order. All allocated sections, function bytes, and relocations equal baseline. +- KEEP `NWC24MsgSubject.c`: NWC24iConvertFromInternalEncoding enum switch with original result-block order. All allocated sections, function bytes, and relocations equal baseline. +- REVERT `NWC24MsgSubject.c`: NWC24SetMsgSubjectPublic simplify success-only switch to error guard. sections ['.text'], relocations ['.text'], functions ['NWC24SetMsgSubjectPublic size 452/456'] +- REVERT `NWC24MsgSubject.c`: NWC24SetMsgSubjectAndTextPublic simplify success-only switch to error guard. sections ['.text'], relocations ['.text'], functions ['NWC24SetMsgSubjectAndTextPublic size 748/760'] +- REVERT `NWC24MsgSubject.c`: NWC24iConvertToInternalEncoding simplify success-only switch to error guard. sections ['.text'], relocations ['.text'], functions ['NWC24iConvertToInternalEncoding size 384/388'] +- REVERT `NWC24MsgSubject.c`: NWC24iConvertFromInternalEncoding simplify success-only switch to error guard. sections ['.text'], relocations ['.text'], functions ['NWC24iConvertFromInternalEncoding size 396/400'] +- REVERT `NWC24MsgSubject.c`: NWC24iSetMsgSubjectQP simplify success-only switch to error guard. sections ['.text'], relocations ['.text'], functions ['NWC24iSetMsgSubjectQP size 572/576'] +- REVERT `NWC24MsgSubject.c`: NWC24iSetMsgSubjectBase64 simplify success-only switch to error guard. sections ['.text'], relocations ['.text'], functions ['NWC24iSetMsgSubjectBase64 size 536/544'] +- REVERT `NWC24MsgSubject.c`: combine while-loop cleanup with removal of the input cast. MWCC rejects conversion from const unsigned char pointer to unsigned char pointer because NWC24EncodeWord takes mutable input. Restored; retested the loop alone below. + +- KEEP `NWC24MsgSubject.c`: NWC24iSetMsgSubjectQP use while loop. All allocated sections, function bytes, and relocations equal baseline. +- KEEP `NWC24MsgSubject.c`: NWC24iSetMsgSubjectBase64 use while loop. All allocated sections, function bytes, and relocations equal baseline. +- REVERT `NWC24MsgSubject.c`: NWC24iSetMsgSubjectBase64 remove unnecessary const qualification and casts. sections ['.text'], relocations [], functions ['NWC24iSetMsgSubjectBase64 diffs 5/136'] +- REVERT `nup_nhttp.cpp`: __nupNhttpOpString remove NO_INLINE forward declaration. sections ['.text'], relocations ['.text'], functions ['__nupHttpGetFull__FPcPPUcPUlUlPFPvUl_vPv size 220/76', '__nupHttpPostFull__FPcPcPcPPUcPUlUlPFPvUl_vPv size 284/172', '__nupNhttpOpString__FPPUcPUlPc14NHTTPReqMethodPcPUcUlUlPFPvUl_vPv missing'] +- KEEP `WDScan.c`: WDCheckEnableChannel rename result2 to infoResult. All allocated sections, function bytes, and relocations equal baseline. +- KEEP `WDScan.c`: WDScanOnce rename result2 to scanResult. All allocated sections, function bytes, and relocations equal baseline. +- KEEP `NWC24MsgSubject.c`: NWC24iGetDefaultCharset replace case exit gotos with break. All allocated sections, function bytes, and relocations equal baseline. +- KEEP `nup.cpp`: remove parentheses left by typed tmdView cast cleanup. All allocated sections, function bytes, and relocations equal baseline. +- KEEP `NWC24MsgSubject.c`: use existing charset and transfer-encoding enum names. All allocated sections, function bytes, and relocations equal baseline. +- REVERT `WDScan.c`: remove WPA small-data section pragma. sections ['.sdata2', '.sdata'], relocations ['.text'], functions [] +- KEEP `WDScan.c`: WDGetPrivacyMode remove redundant signed casts in cipher switches. All allocated sections, function bytes, and relocations equal baseline. + +## Final changes and retained requirements + +- NWC24MsgSubject.c: replaced both ENC error-dispatch ladders with enum switches in the original result-block order, replaced default-charset case gotos with breaks, replaced two empty-clause for loops with while loops, and used existing region/charset/transfer-encoding enums. Common error exits stay. Success-only switches, short-circuit ENC setup, and the const Base64 input alias stay because their alternatives change instructions; each has a one-line compiler note. +- nup.cpp: removed the initializer comma expression and both pointer-assignment expressions, removed redundant typed-pointer casts, and used an else branch for boot-version narrowing. Both dont_inline regions stay because removal inlines the helpers and changes their callers. Tag searches stay in short-circuit conditions; standalone statements change register allocation. The title null check and negative-status alternatives stay because removal shrinks the object. Retained requirements have one-line compiler notes. +- nup_nhttp.cpp: removed the jump immediately before the cleanup label. Common cleanup gotos stay. The buffer-allocation pointer switch, header-condition assignments, and NO_INLINE declaration stay because removal changes instruction counts or caller allocation; each has a one-line compiler note. +- WDScan.c: replaced driver-error jumps with structured branches and both privacy-mode ladders with switches; renamed operation result locals and removed redundant switch casts. All gotos removed. The OUI access macros and WPA .sdata pragma stay because changing volatility or placement changes instructions or relocations; both have one-line compiler notes. + +Object verification compares every allocated section and function against the initial exact object, with defined relocation symbols normalized to section/offset and undefined symbols compared by name. Final objects equal that baseline. + +## Gate retry + +The first final gate built successfully, kept the DOL hash, found all 49 functions instruction-exact, all owned sections at 100%, and 0 regressions. Its forbidden-pattern scanner treated the phrase "register allocation" in three block comments as a register-keyword source addition. Reworded only those comments to "instruction order" and reran the required gate. + +## Final verification + +Final gate command used all four owned units with --quick, as cleanup-common.md requests. +- Full 43U build: passed. +- NWC24MsgSubject: 12/12 instruction-exact functions; code 5352/5352; data 232/232. +- nup: 23/23 instruction-exact functions; code 10764/10764; data 1720/1720. +- nup_nhttp: 9/9 instruction-exact functions; code 2588/2588; data 144/144. +- WDScan: 5/5 instruction-exact functions; code 2180/2180; data 16/16. +- Every owned section: 100%; all pools identical; 0 regressions; 0 forbidden additions; 0 readability warnings. +- Focused ctxdiff checks: conversion helpers 97/97 and 100/100, default charset 75/75, NUP_Init 34/34, HTTP operation 348/348, driver helpers 164/164 and 162/162, privacy mode 115/115; every check reports diffs 0. +- Gotos removed: NWC24MsgSubject 31, nup_nhttp 1, WDScan 23; nup keeps common error exits. +- Refreshed build/43U/report.json; DECOMPLETE_OK. +- DOL SHA1: 26116613f624061ba99c8d1a299aaa6efa85670d. +- git diff --check: passed. + +GATE PASS + +Source commits: 72d86af3, c0446e2b, 12b1f54a, 0c2ba030. +Compiler-note wording fixes: 87b8b348, 465f5d83.