diff --git a/README.md b/README.md index ecd4f88f..93cae5b2 100644 --- a/README.md +++ b/README.md @@ -53,9 +53,9 @@ Progress | Decompiled | Matched | Linked | Data | |:---:|:---:|:---:|:---:| -| 87.35% | 77.13% | 56.92% | 88.21% | +| 87.60% | 77.28% | 56.92% | 88.22% | -units 752/1027 complete, functions 11293/12563 matched. +units 752/1027 complete, functions 11313/12563 matched. decompiled = code with a C/C++ implementation (objdiff fuzzy), matched = byte-exact code, linked = code actually linked into the DOL, data = byte-exact data diff --git a/libs/RevoEX/include/private/nwc24/NWC24MsgObj.h b/libs/RevoEX/include/private/nwc24/NWC24MsgObj.h index 6fffd004..017eee33 100644 --- a/libs/RevoEX/include/private/nwc24/NWC24MsgObj.h +++ b/libs/RevoEX/include/private/nwc24/NWC24MsgObj.h @@ -21,7 +21,9 @@ typedef struct NWC24MsgObjPrivate { u32 type; // 0x04 u32 length; // 0x08 u32 appId; // 0x0C -#if defined(NWC24_MBOX_CTRL) || defined(NWC24_MSG_COMMIT) +#ifdef NWC24_MSG_READ + u32 headerSize; +#elif defined(NWC24_MBOX_CTRL) || defined(NWC24_MSG_COMMIT) u32 unk_0x10; #else u8 unk_0x10[0x4]; diff --git a/libs/RevoEX/include/revolution/nwc24/NWC24MsgBoard.h b/libs/RevoEX/include/revolution/nwc24/NWC24MsgBoard.h index 51c649b7..ec77d9e4 100644 --- a/libs/RevoEX/include/revolution/nwc24/NWC24MsgBoard.h +++ b/libs/RevoEX/include/revolution/nwc24/NWC24MsgBoard.h @@ -104,7 +104,7 @@ NWC24Err NWC24ReadMsgMBOptOutFlag(const NWC24MsgObj* msg, BOOL* mbOptOutFlag, u3 NWC24Err NWC24ReadMsgFromAddr(const NWC24MsgObj* msg, char* addr, u32 addrLen); NWC24Err NWC24ReadMsgSubject(const NWC24MsgObj* msg, char* subject, u32 subjectLen); NWC24Err NWC24ReadMsgText(const NWC24MsgObj* msg, char* text, u32 textLen, NWC24Charset* charset, NWC24Encoding* encoding); -#ifdef NWC24_MSG_SUBJECT +#if defined(NWC24_MSG_SUBJECT) || defined(NWC24_MSG_READ) NWC24Err NWC24ReadMsgTextEx(const NWC24MsgObj* msg, char* text, u32 textLen, char* name, u32 nameLen); #else NWC24Err NWC24ReadMsgTextEx(const NWC24MsgObj* msg, char* text, u32 textLen, const char* name, u32 nameLen, NWC24Charset* charset, diff --git a/libs/RevoEX/src/nwc24/NWC24DateParser.c b/libs/RevoEX/src/nwc24/NWC24DateParser.c new file mode 100644 index 00000000..9b3ba0a1 --- /dev/null +++ b/libs/RevoEX/src/nwc24/NWC24DateParser.c @@ -0,0 +1,236 @@ +#include + +static const u8 DAYS_OF_MONTH[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +static const u16 DAYS_OF_YEAR[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; + +s32 ConvertDateToDays(u16 year, u8 month, u8 day); +void ConvertDaysToDate(u16* year, u8* month, u8* day, s32 days); + +static inline BOOL IsLeapYear(u16 year) { + BOOL leap = FALSE; + if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) + leap = TRUE; + return leap; +} + +NWC24Err NWC24iDateToMinutes(s32* minutes, const NWC24Date* date) { + s32 days; + s32 minutesInDay; + NWC24Err result; + u8 hour; + u8 minute; + + days = ConvertDateToDays(date->year, date->month, date->day); + if (days == -1) { + result = NWC24_ERR_FAILED; + } else { + hour = date->hour; + minute = date->min; + if (hour > 23 || minute > 59) { + minutesInDay = -1; + } else { + minutesInDay = minute + hour * 60; + } + if (minutesInDay == -1 || date->sec > 60) { + result = NWC24_ERR_FAILED; + } else { + result = NWC24_OK; + *minutes = minutesInDay + days * 1440; + } + } + + return result; +} + +NWC24Err NWC24iMinutesToDate(NWC24Date* date, s32 minutes) { + s32 days; + + if (minutes < 0) { + minutes = 0; + } + + days = minutes / 1440; + minutes %= 1440; + date->hour = minutes / 60; + date->min = minutes % 60; + ConvertDaysToDate(&date->year, &date->month, &date->day, days); + return NWC24_OK; +} + +NWC24Err NWC24iEpochSecondsToDate(NWC24Date* date, s64 seconds) { + s64 elapsedMinutes; + s32 minutes; + s32 days; + + if (seconds + 2208988800LL < 0) { + seconds = -2208988800LL; + } + + date->sec = (seconds + 2208988800LL) % 60; + elapsedMinutes = (seconds + 2208988800LL) / 60; + if ((s32)elapsedMinutes < 0) { + elapsedMinutes = 0; + } + minutes = elapsedMinutes; + + days = minutes / 1440; + minutes %= 1440; + date->hour = minutes / 60; + date->min = minutes % 60; + ConvertDaysToDate(&date->year, &date->month, &date->day, days); + return NWC24_OK; +} + +NWC24Err NWC24iMinutesToOSCalendarTime(OSCalendarTime* calendar, s32 minutes) { + s32 days; + NWC24Date date; + BOOL isLeapYear; + + if (minutes < 0) { + minutes = 0; + } + + days = minutes / 1440; + minutes %= 1440; + + date.hour = minutes / 60; + date.min = minutes % 60; + ConvertDaysToDate(&date.year, &date.month, &date.day, days); + isLeapYear = 0; + + calendar->year = date.year; + calendar->mon = date.month - 1; + calendar->mday = date.day; + calendar->hour = date.hour; + calendar->min = date.min; + calendar->sec = 0; + calendar->msec = 0; + calendar->usec = 0; + calendar->yday = date.day + DAYS_OF_YEAR[date.month - 1] - 1; + if (((date.year % 4 == 0 && date.year % 100 != 0) || date.year % 400 == 0)) { + isLeapYear = 1; + } + if (isLeapYear && date.month > 2) { + calendar->yday++; + } + calendar->wday = (days + 1) % 7; + return NWC24_OK; +} + +NWC24Err NWC24iDateToOSCalendarTime(OSCalendarTime* calendar, const NWC24Date* date) { + BOOL isLeapYear; + s32 days; + + isLeapYear = 0; + + calendar->year = date->year; + calendar->mon = date->month - 1; + calendar->mday = date->day; + calendar->hour = date->hour; + calendar->min = date->min; + calendar->sec = date->sec; + calendar->msec = 0; + calendar->usec = 0; + calendar->yday = date->day + DAYS_OF_YEAR[date->month - 1] - 1; + if (((date->year % 4 == 0 && date->year % 100 != 0) || date->year % 400 == 0)) { + isLeapYear = 1; + } + if (isLeapYear && date->month > 2) { + calendar->yday++; + } + + days = ConvertDateToDays(date->year, date->month, date->day); + calendar->wday = (days + 1) % 7; + return NWC24_OK; +} + +NWC24Err NWC24iIsValidDate(u16 year, u8 month, u8 day) { + return ConvertDateToDays(year, month, day) == -1 ? NWC24_ERR_INVALID_VALUE : NWC24_OK; +} + +s32 ConvertDateToDays(u16 year, u8 month, u8 day) { + s32 daysOfYear; + s32 yearOffset; + s32 centuryLeapDays; + s32 commonLeapDays; + BOOL isLeapYear; + + if (year < 1900 || month < 1 || month > 12) { + return -1; + } + + if (month == 2) { + isLeapYear = 0; + if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { + isLeapYear = 1; + } + if (isLeapYear) { + if (day < 1 || day > 29) { + return -1; + } + goto validDate; + } + } + if (day < 1 || DAYS_OF_MONTH[month - 1] < day) { + return -1; + } + +validDate: + daysOfYear = day - 1 + DAYS_OF_YEAR[month - 1]; + if (month >= 3) { + isLeapYear = 0; + if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { + isLeapYear = 1; + } + if (isLeapYear) { + daysOfYear++; + } + } + + yearOffset = year - 1900; + centuryLeapDays = (yearOffset + 299) / 400; + daysOfYear += yearOffset * 365; + daysOfYear += centuryLeapDays; + commonLeapDays = (yearOffset - 1) / 4 - (yearOffset - 1) / 100; + return daysOfYear + commonLeapDays; +} + +void ConvertDaysToDate(u16* year, u8* month, u8* day, s32 days) { + *year = 1900; + *month = 1; + *day = 1; + if (days < 0) { + return; + } + + for (;;) { + u16 currentYear = *year; + s32 previousDays = days; + BOOL leapYear = (currentYear % 4 == 0 && currentYear % 100 != 0) || currentYear % 400 == 0; + days -= 365 + (leapYear != FALSE); + if (days < 0) { + days = previousDays; + break; + } + *year = *year + 1; + } + + for (;;) { + s32 previousDays = days; + if (*month == 2) { + BOOL leapYear = IsLeapYear(*year); + if (leapYear) { + days -= 29; + } else { + days -= DAYS_OF_MONTH[*month - 1]; + } + } else { + days -= DAYS_OF_MONTH[*month - 1]; + } + if (days < 0) { + *day += previousDays; + return; + } + *month = *month + 1; + } +} diff --git a/libs/RevoEX/src/nwc24/NWC24MsgRead.c b/libs/RevoEX/src/nwc24/NWC24MsgRead.c new file mode 100644 index 00000000..1c986b54 --- /dev/null +++ b/libs/RevoEX/src/nwc24/NWC24MsgRead.c @@ -0,0 +1,599 @@ +#define NWC24_MSG_READ +#include + +NWC24Err NWC24iMBoxOpenStoredMsg(NWC24MBoxType type, u32 id, NWC24File* file); +NWC24Err NWC24iMBoxCloseMsg(NWC24File* file); +BOOL Mail_isdigit(int character); +static NWC24Err ReadMsgTextInternal(const NWC24MsgObj* msg, char* text, u32 capacity, char* charset, u32 charsetCapacity, NWC24Encoding* encoding); +NWC24Err ReadBase64Data(NWC24File* file, const NWC24Data* data, u8* output, u32 capacity, u32* outputSize); +NWC24Err ReadQPText(const NWC24MsgObjPrivate* msg, NWC24File* file, char* output, u32 capacity); + +static inline NWC24Err SelectMBox(const NWC24MsgObjPrivate* msg, NWC24MBoxType* type) { + if (msg->type & 0x10) + *type = NWC24_MBOX_TYPE_SEND; + else if (msg->type & 0x20) + *type = NWC24_MBOX_TYPE_RECV; + else + return NWC24_ERR_INVALID_VALUE; + return NWC24_OK; +} + +NWC24Err NWC24ReadMsgField(const NWC24MsgObj* msg, char* fieldName, u8* output, u32 capacity) { + const NWC24MsgObjPrivate* privateMsg = (const NWC24MsgObjPrivate*)msg; + NWC24File file; + NWC24FileStream stream; + char* field; + u32 offset; + u32 length; + NWC24MBoxType type; + NWC24Err result; + NWC24Err closeResult; + if (!NWC24IsMsgLibOpened() && !NWC24IsMsgLibOpenedByTool()) + return NWC24_ERR_LIB_NOT_OPENED; + if (!(privateMsg->type & 0x200)) + return NWC24_ERR_PROTECTED; + result = SelectMBox(privateMsg, &type); + switch (result) { + case NWC24_OK: + break; + default: + return result; + } + result = NWC24iMBoxOpenStoredMsg(type, privateMsg->msgId, &file); + switch (result) { + case NWC24_OK: + break; + default: + return result; + } + result = NWC24FStreamInit(&stream, &file, 0, privateMsg->length, NWC24WorkP->mainWork, 1024); + if (result == NWC24_OK) { + result = NWC24iSearchHeaderF(&stream, fieldName, privateMsg->headerSize, &offset, &length); + if (result == NWC24_OK) { + if (length > capacity) + result = NWC24_ERR_OVERFLOW; + else { + result = NWC24FStreamSeek(&stream, offset); + if (result == NWC24_OK) { + result = NWC24FStreamGetPtr(&stream, &field, length); + if (result == NWC24_OK) { + Mail_strncpy((char*)output, field, length); + output[length - 2] = 0; + } + } + } + } + } + closeResult = NWC24iMBoxCloseMsg(&file); + if (result == NWC24_OK) + result = closeResult; + return result; +} + +NWC24Err NWC24ReadMsgFaceData(const NWC24MsgObj* msg, u8* faceData) { + const NWC24MsgObjPrivate* privateMsg = (const NWC24MsgObjPrivate*)msg; + char* buffer; + u32 length; + NWC24Err result; + if ((privateMsg->type & 2) && !(privateMsg->type & 0x1000)) + return NWC24_ERR_NOT_FOUND; + buffer = NWC24WorkP->stringWork; + Mail_memset(buffer, 0, 1024); + result = NWC24ReadMsgField(msg, "x-wiiface", (u8*)buffer, 1024); + switch (result) { + default: + return result; + case NWC24_OK: + result = NWC24Base64Decode((u8*)buffer, STD_strnlen(buffer, 1024), faceData, 74, &length); + switch (result) { + default: + return result; + case NWC24_OK: + if (length != 74) + return NWC24_ERR_FORMAT; + return NWC24_OK; + } + } + return result; +} + +NWC24Err NWC24ReadMsgAltName(const NWC24MsgObj* msg, u16* name, u32 capacity) { + char* buffer = NWC24WorkP->stringWork; + u32 length; + NWC24Err result; + NWC24Err decodeResult; + Mail_memset(buffer, 0, 1024); + result = NWC24ReadMsgField(msg, "x-wii-altname:", (u8*)buffer, 1024); + switch (result) { + default: + return result; + case NWC24_OK: + decodeResult = NWC24Base64Decode((u8*)buffer, STD_strnlen(buffer, 1024), (u8*)name, capacity * 2, &length); + result = NWC24_OK; + if (decodeResult != NWC24_OK) + result = decodeResult; + } + return result; +} + +NWC24Err NWC24ReadMsgMBNoReply(const NWC24MsgObj* msg, BOOL* noReply) { + char* buffer; + NWC24Err result; + *noReply = FALSE; + buffer = NWC24WorkP->stringWork; + Mail_memset(buffer, 0, 1024); + result = NWC24ReadMsgField(msg, "x-wii-mb-noreply:", (u8*)buffer, 1024); + if (result == NWC24_OK) + *noReply = TRUE; + else if (result == NWC24_ERR_NOT_FOUND) + result = NWC24_OK; + return result; +} + +NWC24Err NWC24ReadMsgMBRegDate(const NWC24MsgObj* msg, u16* year, u8* month, u8* day) { + NWC24Err result; + u32 offset = 0; + u32 digits = 0; + u32 value = 0; + s32 digit; + char* buffer = NWC24WorkP->stringWork; + Mail_memset(buffer, 0, 1024); + result = NWC24ReadMsgField(msg, "x-wii-mb-regdate:", (u8*)buffer, 1023); + switch (result) { + default: + return result; + case NWC24_OK: + break; + } + while (*buffer == '\t' || *buffer == ' ') { + buffer++; + offset++; + } + for (; offset < 1024; offset++, digits++) { + digit = Util_xtoi(*buffer); + if (digit < 0) + break; + value = (value << 4) | digit; + buffer++; + } + if (digits != 4) + result = NWC24_ERR_FORMAT; + *year = ((value >> 9) & 127) + 2000; + *month = (value >> 5) & 15; + *day = value & 31; + return result; +} + +NWC24Err NWC24ReadMsgMBDelay(const NWC24MsgObj* msg, u8* delay) { + NWC24Err result; + u32 offset = 0; + u32 digits = 0; + u32 value = 0; + s32 digit; + char* buffer = NWC24WorkP->stringWork; + Mail_memset(buffer, 0, 1024); + result = NWC24ReadMsgField(msg, "x-wii-mb-delay:", (u8*)buffer, 1023); + switch (result) { + default: + return result; + case NWC24_OK: + break; + } + while (*buffer == '\t' || *buffer == ' ') { + buffer++; + offset++; + } + for (; offset < 1024; offset++, digits++) { + digit = Util_xtoi(*buffer); + if (digit < 0) + break; + value = (value << 4) | digit; + buffer++; + } + if (digits != 2) + result = NWC24_ERR_FORMAT; + *delay = value; + return result; +} + +NWC24Err NWC24ReadMsgMBUpdateSW(const NWC24MsgObj* msg, u32* update) { + NWC24Err result; + const NWC24MsgObjPrivate* privateMsg = (const NWC24MsgObjPrivate*)msg; + u32 value = 0; + char* buffer; + if (!(privateMsg->type & 0x1000)) { + *update = 0; + return NWC24_ERR_NOT_FOUND; + } + buffer = NWC24WorkP->stringWork; + Mail_memset(buffer, 0, 1024); + result = NWC24ReadMsgField(msg, "x-wii-mb-updatesw:", (u8*)buffer, 1023); + switch (result) { + default: + return result; + case NWC24_OK: + while (*buffer == '\t' || *buffer == ' ') + buffer++; + if (Mail_isdigit(*buffer)) + value = *buffer - '0'; + *update = value; + } + return result; +} + +NWC24Err NWC24ReadMsgMBOptOutFlag(const NWC24MsgObj* msg, BOOL* optOut, u32* appId) { + NWC24Err result; + u32 offset = 0; + u32 digits = 0; + u32 value = 0; + s32 digit; + char* buffer = NWC24WorkP->stringWork; + Mail_memset(buffer, 0, 1024); + *optOut = FALSE; + *appId = 0; + result = NWC24ReadMsgField(msg, "x-wii-mb-optout:", (u8*)buffer, 1023); + if (result == NWC24_ERR_NOT_FOUND) + return NWC24_OK; + switch (result) { + default: + return result; + case NWC24_OK: + while (*buffer == '\t' || *buffer == ' ') { + buffer++; + offset++; + } + if (*buffer == '1') + *optOut = TRUE; + { + char separator = buffer[1]; + buffer += 2; + if (separator != '-') + return NWC24_OK; + { + offset += 2; + for (; offset < 1024; offset++, digits++) { + digit = Util_xtoi(*buffer); + if (digit < 0) + break; + value = (value << 4) | digit; + buffer++; + } + if (digits != 8) + result = NWC24_ERR_FORMAT; + *appId = value; + } + } + } + return result; +} + +NWC24Err NWC24ReadMsgFromAddr(const NWC24MsgObj* msg, char* address, u32 capacity) { + const NWC24MsgObjPrivate* privateMsg = (const NWC24MsgObjPrivate*)msg; + NWC24MBoxType type; + NWC24File file; + NWC24FileStream stream; + char* buffer; + NWC24Err result, closeResult; + if (!NWC24IsMsgLibOpened() && !NWC24IsMsgLibOpenedByTool()) + return NWC24_ERR_LIB_NOT_OPENED; + if (!(privateMsg->type & 0x200)) + return NWC24_ERR_PROTECTED; + buffer = NWC24WorkP->stringWork; + Mail_memset(buffer, 0, 1024); + if (!(privateMsg->type & 2)) + return NWC24_ERR_NOT_SUPPORTED; + result = SelectMBox(privateMsg, &type); + switch (result) { + case NWC24_OK: + break; + default: + return result; + } + if (privateMsg->unk_0x30.size == 0) + return NWC24_ERR_NULL; + result = NWC24iMBoxOpenStoredMsg(type, privateMsg->msgId, &file); + switch (result) { + case NWC24_OK: + break; + default: + return result; + } + result = NWC24FStreamInit(&stream, &file, 0, privateMsg->length, buffer, 1024); + if (result == NWC24_OK) { + result = NWC24FStreamSeek(&stream, (u32)privateMsg->unk_0x30.ptr); + if (result == NWC24_OK) + result = NWC24iExtractAddrSpec(&stream, privateMsg->unk_0x30.size, 0, address, capacity); + } + closeResult = NWC24iMBoxCloseMsg(&file); + if (result != NWC24_OK) + closeResult = result; + return closeResult; + return result; +} + +NWC24Err NWC24ReadMsgSubject(const NWC24MsgObj* msg, char* subject, u32 capacity) { + const NWC24MsgObjPrivate* privateMsg = (const NWC24MsgObjPrivate*)msg; + NWC24MBoxType type; + NWC24File file; + u32 length; + NWC24Err result, closeResult; + if (!NWC24IsMsgLibOpened() && !NWC24IsMsgLibOpenedByTool()) + return NWC24_ERR_LIB_NOT_OPENED; + if (!(privateMsg->type & 0x200)) + return NWC24_ERR_PROTECTED; + result = SelectMBox(privateMsg, &type); + switch (result) { + case NWC24_OK: + break; + default: + return result; + } + length = privateMsg->subject.size; + if (length == 0) + return NWC24_ERR_NULL; + result = NWC24iMBoxOpenStoredMsg(type, privateMsg->msgId, &file); + switch (result) { + case NWC24_OK: + break; + default: + return result; + } + if (length > capacity - 1) + length = capacity - 1; + NWC24FSeek(&file, (u32)privateMsg->subject.ptr, NWC24_SEEK_BEG); + result = NWC24FRead(subject, length, &file); + if (result == NWC24_OK) { + subject[length] = 0; + if (privateMsg->subject.size > capacity - 1) + result = NWC24_ERR_OVERFLOW; + } + closeResult = NWC24iMBoxCloseMsg(&file); + if (result == NWC24_OK) + result = closeResult; + return result; +} + +NWC24Err NWC24ReadMsgText(const NWC24MsgObj* msg, char* text, u32 capacity, NWC24Charset* charset, NWC24Encoding* encoding) { + char* name = NWC24WorkP->stringWork + 32; + NWC24Err result = ReadMsgTextInternal(msg, text, capacity, name, 64, encoding); + if (result == NWC24_OK) + result = NWC24ParseCharsetStr(charset, name); + return result; +} + +NWC24Err NWC24ReadMsgTextEx(const NWC24MsgObj* msg, char* text, u32 capacity, char* charset, u32 charsetCapacity) { + u32 i; + NWC24Encoding encoding; + NWC24Err result = ReadMsgTextInternal(msg, text, capacity, charset, charsetCapacity, &encoding); + if (result == NWC24_OK) { + for (i = 0; i < charsetCapacity; i++) { + switch (*charset) { + case ' ': + case '\t': + case '\n': + case '\r': + case ';': + case '"': + *charset = 0; + break; + } + if (*charset == 0) + break; + charset++; + } + } + return result; +} + +static NWC24Err ReadMsgTextInternal(const NWC24MsgObj* msg, char* text, u32 capacity, char* charset, u32 charsetCapacity, NWC24Encoding* encoding) { + const NWC24MsgObjPrivate* privateMsg = (const NWC24MsgObjPrivate*)msg; + NWC24MBoxType type; + NWC24File file; + NWC24Err result, closeResult; + NWC24Err overflow = NWC24_OK; + u32 length; + u32 decodedSize; + char* buffer; + if (!NWC24IsMsgLibOpened() && !NWC24IsMsgLibOpenedByTool()) + return NWC24_ERR_LIB_NOT_OPENED; + if (!(privateMsg->type & 0x200)) + return NWC24_ERR_PROTECTED; + buffer = NWC24WorkP->stringWork; + *encoding = 0; + result = SelectMBox(privateMsg, &type); + switch (result) { + case NWC24_OK: + break; + default: + return result; + } + length = privateMsg->textSize; + if (length == 0) + length = privateMsg->text.size; + if (length == 0) + return NWC24_ERR_NULL; + if (length > capacity - 1) { + overflow = NWC24_ERR_OVERFLOW; + length = capacity - 1; + } + result = NWC24iMBoxOpenStoredMsg(type, privateMsg->msgId, &file); + switch (result) { + case NWC24_OK: + break; + default: + return result; + } + Mail_memset(charset, 0, charsetCapacity); + if (privateMsg->unk_0x50.size >= charsetCapacity) + result = NWC24_ERR_FORMAT; + else { + if (privateMsg->unk_0x50.size != 0) { + NWC24FSeek(&file, (u32)privateMsg->unk_0x50.ptr, NWC24_SEEK_BEG); + result = NWC24FRead(charset, privateMsg->unk_0x50.size, &file); + if (result != NWC24_OK) + goto close; + } + if (privateMsg->unk_0x58.size != 0 && privateMsg->unk_0x58.size < 32) { + Mail_memset(buffer, 0, 32); + NWC24FSeek(&file, (u32)privateMsg->unk_0x58.ptr, NWC24_SEEK_BEG); + result = NWC24FRead(buffer, privateMsg->unk_0x58.size, &file); + if (result != NWC24_OK) + goto close; + result = NWC24ParseEncodingStr(encoding, buffer); + if (result != NWC24_OK) + goto close; + } + NWC24FSeek(&file, (u32)privateMsg->text.ptr, NWC24_SEEK_BEG); + switch (*encoding) { + case 0: + case 1: + result = NWC24FRead(text, length, &file); + text[length] = 0; + break; + case 2: + decodedSize = 0; + result = ReadBase64Data(&file, &privateMsg->text, (u8*)text, length, &decodedSize); + if (result == NWC24_OK && decodedSize != privateMsg->textSize) + result = NWC24_ERR_FORMAT; + text[length] = 0; + break; + case 3: + result = ReadQPText(privateMsg, &file, text, length); + break; + default: + result = NWC24_ERR_NOT_SUPPORTED; + *text = 0; + break; + } + } +close: + closeResult = NWC24iMBoxCloseMsg(&file); + if (result == NWC24_OK) + result = closeResult; + if (result == NWC24_OK) + result = overflow; + return result; +} + +NWC24Err NWC24ReadMsgAttached(const NWC24MsgObj* msg, u32 index, u8* output, u32 capacity) { + const NWC24MsgObjPrivate* privateMsg = (const NWC24MsgObjPrivate*)msg; + NWC24File file; + NWC24MBoxType type; + u32 decodedSize; + NWC24Err result, closeResult; + if (!NWC24IsMsgLibOpened() && !NWC24IsMsgLibOpenedByTool()) + return NWC24_ERR_LIB_NOT_OPENED; + if (!(privateMsg->type & 0x200)) + return NWC24_ERR_PROTECTED; + if (index >= privateMsg->numAttached) + return NWC24_ERR_NOT_FOUND; + result = SelectMBox(privateMsg, &type); + switch (result) { + case NWC24_OK: + break; + default: + return result; + } + if (privateMsg->attached[index].size == 0 || privateMsg->attachedSize[index] == 0) + return NWC24_ERR_NULL; + result = NWC24iMBoxOpenStoredMsg(type, privateMsg->msgId, &file); + switch (result) { + case NWC24_OK: + break; + default: + return result; + } + decodedSize = 0; + result = ReadBase64Data(&file, &privateMsg->attached[index], output, capacity, &decodedSize); + if (result == NWC24_OK && decodedSize != privateMsg->attachedSize[index]) + result = NWC24_ERR_FORMAT; + closeResult = NWC24iMBoxCloseMsg(&file); + if (result == NWC24_OK) + result = closeResult; + return result; +} + +NWC24Err ReadBase64Data(NWC24File* file, const NWC24Data* data, u8* output, u32 capacity, u32* outputSize) { + int remaining = data->size; + int offset = (u32)data->ptr; + char* buffer = NWC24WorkP->mainWork; + u8* outPtr = output; + int total = 0; + int readSize; + int end; + char* cursor; + int i; + u32 decodedSize; + NWC24Err result = NWC24_OK; + BOOL finished = FALSE; + while (remaining > 0 && !finished) { + readSize = remaining > 1024 ? 1024 : remaining; + NWC24FSeek(file, offset, NWC24_SEEK_BEG); + result = NWC24FRead(buffer, readSize, file); + if (result != NWC24_OK) + break; + end = 0; + cursor = buffer; + for (i = 0; i < readSize; cursor++, i++) { + if (*cursor == '\r') + end = i; + if (*cursor == '=') { + end = i + 1; + finished = TRUE; + result = NWC24_OK; + break; + } + } + if (end == 0) + break; + result = NWC24Base64Decode((u8*)buffer, end, outPtr, capacity - total, &decodedSize); + if (result != NWC24_OK) + break; + offset += end; + remaining -= end; + total += decodedSize; + outPtr += decodedSize; + } + if (result == NWC24_OK) + *outputSize = total; + return result; +} + +NWC24Err ReadQPText(const NWC24MsgObjPrivate* msg, NWC24File* file, char* output, u32 capacity) { + int remaining = msg->text.size; + int offset = (u32)msg->text.ptr; + char* buffer = NWC24WorkP->mainWork; + char* cursor = output; + int readSize; + u32 total = 0; + u32 consumedSize; + u32 decodedSize; + NWC24Err result = NWC24_OK; + while (remaining > 0) { + readSize = remaining > 1024 ? 1024 : remaining; + NWC24FSeek(file, offset, NWC24_SEEK_BEG); + result = NWC24FRead(buffer, readSize, file); + if (result != NWC24_OK) + break; + consumedSize = readSize; + if (readSize == 1024) { + if (buffer[readSize - 1] == '=') + consumedSize = readSize - 1; + else if (buffer[readSize - 2] == '=') + consumedSize = readSize - 2; + } + result = NWC24DecodeQuotedPrintable(cursor, capacity - total, &decodedSize, (u8*)buffer, consumedSize, &consumedSize); + if (result != NWC24_OK && result != NWC24_ERR_OVERFLOW) + break; + total += decodedSize; + cursor += decodedSize; + if (result == NWC24_ERR_OVERFLOW) + break; + offset += consumedSize; + remaining -= consumedSize; + } + *cursor = 0; + if (result == NWC24_OK && total > msg->textSize) + result = NWC24_ERR_FORMAT; + return result; +} diff --git a/libs/RevoEX/src/nwc24/NWC24System.c b/libs/RevoEX/src/nwc24/NWC24System.c new file mode 100644 index 00000000..a8451981 --- /dev/null +++ b/libs/RevoEX/src/nwc24/NWC24System.c @@ -0,0 +1,112 @@ +#include +#include +#include +#include +#include + +static s32 nwc24ShtFd = -1; +static s32 nwc24ShtRetryRest = 0; +static OSShutdownFunctionInfo ShutdownFuncInfo; +BOOL NWC24Shutdown(BOOL final, u32 event); +NWC24Err NWC24iMBoxSetLastUIDL(NWC24MBoxType type, const char* uidl); + +NWC24Err NWC24EnableLedNotification(BOOL enable) { + u8 led = 0; + SCIdleModeInfo idleMode; + u32 status; + if (enable) { + do { + status = SCCheckStatus(); + if (status == 2) + return NWC24_ERR_FATAL; + } while (status == 1); + SCGetIdleMode(&idleMode); + led = idleMode.led; + } + __OSSetIdleLEDMode(led); + return NWC24_OK; +} + +NWC24Err NWC24iPrepareShutdown(void) { + NWC24Err result = NWC24_OK; + SCIdleModeInfo idleMode; + u32 status; + NWC24iRegister(); + ShutdownFuncInfo.func = NWC24Shutdown; + ShutdownFuncInfo.priority = 110; + OSRegisterShutdownFunction(&ShutdownFuncInfo); + if (nwc24ShtFd < 0) + result = NWC24OpenResourceManager("/dev/net/kd/request", &nwc24ShtFd, 1); + nwc24ShtRetryRest = 5; + do { + status = SCCheckStatus(); + if (status == 2) + goto ready; + } while (status == 1); + SCGetIdleMode(&idleMode); + __OSSetIdleLEDMode(idleMode.led); +ready: + if (OSGetAppType() == 0x40) + NWC24iSetScriptMode(1); + return result; +} + +static inline NWC24Err NWC24iRequestShutdown(u32 event, NWC24Err* result) { + static u32 shtBuffer[8] ALIGN32; + static u32 shtResult[8] ALIGN32; + shtBuffer[0] = event; + return NWC24IoctlResourceManagerAsync(nwc24ShtFd, NWC24_IOCTL_SHUTDOWN, shtBuffer, sizeof(shtBuffer), shtResult, sizeof(shtResult), (s32*)result); +} + +BOOL NWC24Shutdown(BOOL final, u32 event) { + static BOOL shuttingdown = FALSE; + static NWC24Err result = NWC24_OK; + if (final) + return TRUE; + if (shuttingdown) { + if (NWC24IsAsyncRequestPending()) + return FALSE; + if (result >= 0) + return TRUE; + if (nwc24ShtRetryRest > 0) { + shuttingdown = FALSE; + nwc24ShtRetryRest--; + } else + return TRUE; + } else if (NWC24iRequestShutdown(event, &result) >= 0) + shuttingdown = TRUE; + return FALSE; +} + +NWC24Err NWC24DoDailyTasks(void* work) { + NWC24Err result = NWC24_OK; + SCIdleModeInfo idleMode; + u32 status; + u32 restrictions; + u32 tick = OSGetTick(); + u32 randomValue = rand(); + if ((randomValue + tick) % 10 != 0) + return NWC24_OK; + if (NWC24IsMsgLibOpened()) + return NWC24_ERR_LIB_OPENED; + do { + status = SCCheckStatus(); + if (status == 2) + return NWC24_ERR_FATAL; + OSSleepTicks(OSMillisecondsToTicks((OSTime)100)); + } while (status != 0); + if (!SCGetIdleMode(&idleMode)) + return NWC24_ERR_NOT_FOUND; + restrictions = SCGetNetContentRestrictions() & 2; + if (idleMode.standby == 0) { + if (restrictions == 0) { + result = NWC24OpenLib(work); + if (result >= 0) { + result = NWC24iMBoxSetLastUIDL(NWC24_MBOX_TYPE_RECV, ""); + NWC24CloseLib(); + } + } else + result = NWC24AdjustUniversalTime(); + } + return result; +} diff --git a/tools/decomp-assist/NWC24DateParser.attempts.md b/tools/decomp-assist/NWC24DateParser.attempts.md new file mode 100644 index 00000000..9fcf44e7 --- /dev/null +++ b/tools/decomp-assist/NWC24DateParser.attempts.md @@ -0,0 +1,46 @@ +# NWC24DateParser matching attempts + +Baseline: no source; 0/8 exact functions, 0/2372 code, 0/40 data. +Initial readable C reference in /tmp was checked against target assembly. +Calendar fields reuse NWC24Date and OSCalendarTime. Month-length and +year-day tables follow original .rodata order, with all 40 bytes identical. +Epoch conversion adds 2208988800 seconds before clamping, as in the target. +The stack date workspace reproduces calendar conversion aliasing and offsets. + +## Source attempts + +NWC24iEpochSecondsToDate | clamp epoch after signed epoch offset addition | (100.0, 0) | src 0x13c base 0x13c insns 79/79 +NWC24iMinutesToOSCalendarTime | calendar conversion uses date structure workspace | (0, -9999) | [1/1] MWCC build/43U/src/libs/RevoEX/src/nwc24/NWC24DateParser.o +NWC24iMinutesToOSCalendarTime | workspace and byte leap flag | (0, -9999) | [1/1] MWCC build/43U/src/libs/RevoEX/src/nwc24/NWC24DateParser.o +NWC24iMinutesToOSCalendarTime | workspace with leap flag declared before date | (0, -9999) | [1/1] MWCC build/43U/src/libs/RevoEX/src/nwc24/NWC24DateParser.o +NWC24iDateToOSCalendarTime | explicit local year before leap flag | (96.588234, -19) | src 0x154 base 0x154 insns 85/85 +NWC24iDateToOSCalendarTime | byte leap flag | (99.17647, -13) | src 0x154 base 0x154 insns 85/85 +NWC24iDateToOSCalendarTime | leap flag initialized at declaration | (99.17647, -13) | src 0x154 base 0x154 insns 85/85 +ConvertDateToDays | shared non-leap day validation and leap-year predicate | (83.07079, -21) | src 0x1c4 base 0x1c4 insns 113/113 +ConvertDateToDays | signed leap flag with reordered annual sum | (83.07079, -21) | src 0x1c4 base 0x1c4 insns 113/113 +ConvertDateToDays | unsigned leap flag and shared validation | (83.07079, -21) | src 0x1c4 base 0x1c4 insns 113/113 +ConvertDaysToDate | subtract annual and monthly spans before testing remaining days | (79.32039, -9999) | src 0x178 base 0x19c insns 94/103 +ConvertDaysToDate | annual leap result stored in byte | (79.32039, -9999) | src 0x178 base 0x19c insns 94/103 +ConvertDaysToDate | cache signed current year | (79.32039, -9999) | src 0x178 base 0x19c insns 94/103 +NWC24iMinutesToOSCalendarTime | date structure workspace with named calendar fields | (100.0, 0) | src 0x1d8 base 0x1d8 insns 118/118 +ConvertDateToDays | subtract one from day before adding month prefix | (83.07079, -21) | src 0x1c4 base 0x1c4 insns 113/113 +ConvertDateToDays | annual sum before leap correction | (90.33628, -21) | src 0x1c4 base 0x1c4 insns 113/113 +ConvertDateToDays | annual base computed in named temporary | (90.33628, -21) | src 0x1c4 base 0x1c4 insns 113/113 +NWC24iMinutesToOSCalendarTime | shared leap-year predicate | (93.05085, -9999) | src 0x1e8 base 0x1d8 insns 122/118 +NWC24iDateToOSCalendarTime | shared leap-year predicate | (94.329414, -9999) | src 0x164 base 0x154 insns 89/85 +ConvertDateToDays | shared leap-year predicate | (90.33628, -21) | src 0x1c4 base 0x1c4 insns 113/113 +NWC24iDateToOSCalendarTime | cache year after leap flag initialization | (99.17647, -13) | src 0x154 base 0x154 insns 85/85 +NWC24iDateToOSCalendarTime | leap check through shared year helper | (94.329414, -9999) | src 0x164 base 0x154 insns 89/85 +NWC24iDateToOSCalendarTime | leap result assigned after calendar stores | (94.44706, -9999) | src 0x158 base 0x154 insns 86/85 +ConvertDateToDays | day offset prepared before month table access | (90.95575, -18) | src 0x1c4 base 0x1c4 insns 113/113 +ConvertDateToDays | annual day and leap counts use independent temporaries | (95.02655, -19) | src 0x1c4 base 0x1c4 insns 113/113 +ConvertDateToDays | annual days calculated before leap century count | (95.02655, -19) | src 0x1c4 base 0x1c4 insns 113/113 +ConvertDaysToDate | monthly leap flag materialized before subtraction | (86.35922, -9999) | src 0x1a8 base 0x19c insns 106/103 +ConvertDaysToDate | annual leap calculation uses year helper | (75.23301, -9999) | src 0x168 base 0x19c insns 90/103 +ConvertDaysToDate | monthly and annual named leap predicates | (82.31068, -9999) | src 0x198 base 0x19c insns 102/103 + +## Remaining functions + +NWC24iDateToOSCalendarTime, 99.17647%: 85/85 instructions; thirteen differences exchanging year and leap-flag registers. +ConvertDateToDays, 95.02655%: 113/113 instructions; nineteen differences in month-prefix addition and annual arithmetic scheduling. +ConvertDaysToDate, 86.35922%: 106/103 instructions; annual/monthly leap branches and register allocation differ. diff --git a/tools/decomp-assist/NWC24MsgRead.attempts.md b/tools/decomp-assist/NWC24MsgRead.attempts.md new file mode 100644 index 00000000..d848cbdc --- /dev/null +++ b/tools/decomp-assist/NWC24MsgRead.attempts.md @@ -0,0 +1,89 @@ +# NWC24MsgRead matching attempts + +Baseline: no source; 0/16 exact functions, 0/4660 code, 0/128 data. +All functions implemented in object order from target assembly and object-exported Ghidra. +Pool and .data are identical, using ordinary literals. The first implementation +used the older reference only for file-reading conventions; signatures and +behavior come from the target. Format errors use NWC24_ERR_FORMAT (-24). + +## Source attempts + +NWC24ReadMsgField | protection exit through common result label | (98.82353, -9999) | src 0x194 base 0x198 insns 101/102 +NWC24ReadMsgField | mailbox helper reads public message view | (98.92157, -9999) | src 0x194 base 0x198 insns 101/102 +NWC24ReadMsgField | protection test after type local snapshot | (98.92157, -9999) | src 0x194 base 0x198 insns 101/102 +NWC24ReadMsgFaceData | field and decoder success switches | (100.0, 0) | src 0xd4 base 0xd4 insns 53/53 +NWC24ReadMsgAltName | status switch and independent decoder result | (100.0, 0) | src 0xb8 base 0xb8 insns 46/46 +NWC24ReadMsgMBRegDate | work cursor declared after counts and explicit scan progress | (98.257576, -19) | src 0x108 base 0x108 insns 66/66 +NWC24ReadMsgMBRegDate | status declaration before cursor and scan counts | (99.545456, -3) | src 0x108 base 0x108 insns 66/66 +NWC24ReadMsgMBRegDate | advance byte cursor in hexadecimal conversion call | (95.22727, -24) | src 0x108 base 0x108 insns 66/66 +NWC24ReadMsgMBDelay | work cursor declared after counts and explicit scan progress | (98.18965, -17) | src 0xe8 base 0xe8 insns 58/58 +NWC24ReadMsgMBDelay | status declaration before cursor and scan counts | (99.48276, -3) | src 0xe8 base 0xe8 insns 58/58 +NWC24ReadMsgMBDelay | advance byte cursor in hexadecimal conversion call | (94.74138, -22) | src 0xe8 base 0xe8 insns 58/58 +NWC24ReadMsgTextEx | unsigned bounded charset scan | (100.0, 0) | src 0xb8 base 0xb8 insns 46/46 +NWC24ReadMsgMBRegDate | scan offset and input pointer in for increment | (99.69697, -2) | src 0x108 base 0x108 insns 66/66 +NWC24ReadMsgMBRegDate | scan offset and digit count in for increment | (99.545456, -3) | src 0x108 base 0x108 insns 66/66 +NWC24ReadMsgMBRegDate | scan index uses remaining count condition | (99.69697, -2) | src 0x108 base 0x108 insns 66/66 +NWC24ReadMsgMBDelay | scan offset and input pointer in for increment | (99.655174, -2) | src 0xe8 base 0xe8 insns 58/58 +NWC24ReadMsgMBDelay | scan offset and digit count in for increment | (99.48276, -3) | src 0xe8 base 0xe8 insns 58/58 +NWC24ReadMsgMBDelay | scan index uses remaining count condition | (99.655174, -2) | src 0xe8 base 0xe8 insns 58/58 +NWC24ReadMsgMBUpdateSW | initialize work buffer after flag validation and switch status | (95.53571, -14) | src 0xe0 base 0xe0 insns 56/56 +NWC24ReadMsgMBUpdateSW | work buffer declaration after result | (90.71429, -9999) | src 0xdc base 0xe0 insns 55/56 +NWC24ReadMsgMBUpdateSW | signed update digit | (89.01786, -9999) | src 0xdc base 0xe0 insns 55/56 +NWC24ReadMsgMBOptOutFlag | cursor lifetime and explicit separator case | (92.14286, -9999) | src 0x138 base 0x134 insns 78/77 +NWC24ReadMsgMBOptOutFlag | signed bounded hexadecimal scan counters | (90.58442, -9999) | src 0x138 base 0x134 insns 78/77 +NWC24ReadMsgMBOptOutFlag | app id accumulated before cursor advance | (92.14286, -9999) | src 0x138 base 0x134 insns 78/77 +NWC24ReadMsgFromAddr | preserve stream status when closing fails | (98.804344, -9999) | src 0x16c base 0x170 insns 91/92 +NWC24ReadMsgFromAddr | mailbox selection status via positive body | (97.5, -56) | src 0x170 base 0x170 insns 92/92 +NWC24ReadMsgFromAddr | close result declared before stream result | (97.5, -56) | src 0x170 base 0x170 insns 92/92 +NWC24ReadMsgSubject | read length initialized before mailbox selection | (96.14634, -9999) | src 0x144 base 0x148 insns 81/82 +NWC24ReadMsgSubject | signed file read length | (98.65854, -9999) | src 0x144 base 0x148 insns 81/82 +NWC24ReadMsgSubject | protection error stored in result | (98.65854, -9999) | src 0x144 base 0x148 insns 81/82 +NWC24ReadMsgMBRegDate | scan counter increments explicitly after shift temporary | (99.545456, -3) | src 0x108 base 0x108 insns 66/66 +NWC24ReadMsgMBRegDate | input cursor advanced through next-pointer temporary | (99.545456, -3) | src 0x108 base 0x108 insns 66/66 +NWC24ReadMsgMBRegDate | signed hex digit count | (98.78788, -3) | src 0x108 base 0x108 insns 66/66 +NWC24ReadMsgMBDelay | scan counter increments explicitly after shift temporary | (99.48276, -3) | src 0xe8 base 0xe8 insns 58/58 +NWC24ReadMsgMBDelay | input cursor advanced through next-pointer temporary | (99.48276, -3) | src 0xe8 base 0xe8 insns 58/58 +NWC24ReadMsgMBDelay | signed hex digit count | (98.62069, -3) | src 0xe8 base 0xe8 insns 58/58 +NWC24ReadMsgMBUpdateSW | result declared before working pointer | (97.41071, -7) | src 0xe0 base 0xe0 insns 56/56 +NWC24ReadMsgMBUpdateSW | message alias introduced after local result | (95.53571, -14) | src 0xe0 base 0xe0 insns 56/56 +NWC24ReadMsgMBUpdateSW | result first then digit then cursor | (100.0, 0) | src 0xe0 base 0xe0 insns 56/56 +ReadMsgTextInternal | separate encoding string and charset capacities | (93.735954, -9999) | src 0x2c0 base 0x2c8 insns 176/178 +ReadMsgTextInternal | decoded count declared before truncation status | (93.735954, -9999) | src 0x2c0 base 0x2c8 insns 176/178 +ReadMsgTextInternal | error status switches before closing | (91.88202, -9999) | src 0x2cc base 0x2c8 insns 179/178 +NWC24ReadMsgAttached | attachment index converted to signed array index | (96.04395, -9999) | src 0x164 base 0x16c insns 89/91 +NWC24ReadMsgAttached | decoded status declared before attachment length | (96.04395, -9999) | src 0x164 base 0x16c insns 89/91 +NWC24ReadMsgAttached | alias attachment descriptor with real data pointer | (93.17583, -9999) | src 0x164 base 0x16c insns 89/91 +ReadBase64Data | output cursor copied to explicit working pointer | (99.55696, -7) | src 0x13c base 0x13c insns 79/79 +ReadBase64Data | source scan index declared before cursor | (97.974686, -26) | src 0x13c base 0x13c insns 79/79 +ReadBase64Data | completion flag declared before status | (98.03797, -26) | src 0x13c base 0x13c insns 79/79 +ReadQPText | use actual read extent for partial escape check | (98.6375, -24) | src 0x140 base 0x140 insns 80/80 +ReadQPText | swap consumed and decoded count declarations | (98.725, -17) | src 0x140 base 0x140 insns 80/80 +ReadQPText | output cursor copied to explicit working pointer | (99.3875, -15) | src 0x140 base 0x140 insns 80/80 +ReadBase64Data | scan cursor declared before integer index | (99.620255, -4) | src 0x13c base 0x13c insns 79/79 +ReadBase64Data | initialize status before completion flag | (99.68355, -5) | src 0x13c base 0x13c insns 79/79 +ReadBase64Data | cursor-first scan and status-first initialization | (99.74683, -2) | src 0x13c base 0x13c insns 79/79 +ReadQPText | remaining and offset lifetimes declared in input order | (99.9125, -7) | src 0x140 base 0x140 insns 80/80 +ReadQPText | swap byte count slots | (99.475, -8) | src 0x140 base 0x140 insns 80/80 +ReadQPText | input-order offsets and byte count slots | (100.0, 0) | src 0x140 base 0x140 insns 80/80 +ReadBase64Data | cursor increment before index increment | (100.0, 0) | src 0x13c base 0x13c insns 79/79 +NWC24ReadMsgMBRegDate | digit count before cursor in for increment | (99.545456, -3) | src 0x108 base 0x108 insns 66/66 +NWC24ReadMsgMBRegDate | digit count in condition after consuming character | (100.0, 0) | src 0x108 base 0x108 insns 66/66 +NWC24ReadMsgMBDelay | digit count before cursor in for increment | (99.48276, -3) | src 0xe8 base 0xe8 insns 58/58 +NWC24ReadMsgMBDelay | digit count in condition after consuming character | (100.0, 0) | src 0xe8 base 0xe8 insns 58/58 +NWC24ReadMsgMBOptOutFlag | return absent app id before hexadecimal scan | (99.61039, -3) | src 0x134 base 0x134 insns 77/77 +NWC24ReadMsgMBOptOutFlag | explicit hexadecimal progress after reading each digit | (92.14286, -9999) | src 0x138 base 0x134 insns 78/77 +NWC24ReadMsgMBOptOutFlag | separator early exit plus scan progress | (99.61039, -3) | src 0x134 base 0x134 insns 77/77 +SelectMBox | mailbox selector with local error status | (2172, 96.739914) +SelectMBox | mailbox selector direct switch on status flags | (2172, 94.90558) +NWC24ReadMsgMBOptOutFlag | digit count in loop increment and cursor in body | (100.0, 0) | src 0x134 base 0x134 insns 77/77 + +## Remaining functions + +NWC24ReadMsgField, 98.92157%: 101/102 instructions; protected-type load is reused across inlined mailbox selection. +NWC24ReadMsgFromAddr, 98.804344%: 91/92 instructions; type-load reuse and close-result control flow differ. +NWC24ReadMsgSubject, 98.65854%: 81/82 instructions; inlined mailbox selection reuses the protected-type load. +NWC24ReadMsgAttached, 96.04395%: 89/91 instructions; attachment addressing and saved-register allocation differ. +ReadMsgTextInternal, 93.735954%: 176/178 instructions; type-load reuse, empty-length handling, and saved-register allocation differ. + +Shared-header changes are guarded by NWC24_MSG_READ, defined only by this unit. +No other unit output changes. diff --git a/tools/decomp-assist/NWC24System.attempts.md b/tools/decomp-assist/NWC24System.attempts.md new file mode 100644 index 00000000..f6e23bdc --- /dev/null +++ b/tools/decomp-assist/NWC24System.attempts.md @@ -0,0 +1,15 @@ +# NWC24System matching attempts + +Baseline: no source; 0/4 exact functions, 0/808 code, 0/192 data. +The SDK shutdown reference was adapted to this target using its assembly +and object-exported Ghidra output. LED state uses SCIdleModeInfo; IPC +shutdown input/output arrays use required 32-byte alignment. The inline +shutdown request retains its own function-name literal through the IPC macro. +All functions, .data, .sdata, .bss, and .sbss match. Unit remains NonMatching. + +## Source attempts + +NWC24DoDailyTasks | random value before tick in sampling sum | (99.875, -1) | src 0x140 base 0x140 insns 80/80 +NWC24DoDailyTasks | unsigned random value retained in sampling temporary | (100.0, 0) | src 0x140 base 0x140 insns 80/80 + +No remaining non-matching functions.