Compare commits

...

1 Commits

Author SHA1 Message Date
coah
b9eaa4fea5 CDBRecord 26/29, CDBIntArray 13/13, NWC24Download (worker 231065dc) 2026-09-30 05:15:41 +00:00
9 changed files with 1607 additions and 547 deletions

View File

@@ -53,9 +53,9 @@ Progress
<!-- progress:start -->
| Decompiled | Matched | Linked | Data |
|:---:|:---:|:---:|:---:|
| 87.88% | 77.62% | 56.92% | 88.23% |
| 88.20% | 77.88% | 56.92% | 88.24% |
units 752/1027 complete, functions 11324/12563 matched.
units 752/1027 complete, functions 11369/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
<!-- progress:end -->

View File

@@ -4,19 +4,32 @@
#include <private/cdb/CDBAttr.h>
#include <private/cdb/CDBBridge.h>
#include <revolution/types.h>
#ifdef CDB_RECORD_IMPLEMENTATION
#include <revolution/os.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
typedef struct _CDBRecordFile {
#ifdef CDB_RECORD_IMPLEMENTATION
OSMutex mutex;
BOOL used;
#else
u8 unk_0x00[0x1C - 0x00];
#endif
int unk_0x1C;
CDBAttr attr; // 0x20
CDBBridgeFile bridgeFile; // 0x42C
u8 unk_0x434[0x438 - 0x434];
CDBRecordKey key; // 0x438
#ifdef CDB_RECORD_IMPLEMENTATION
u32 database;
u8 reserved[0x480 - 0x46C];
#else
u8 unk_0x468[0x480 - 0x468];
#endif
} CDBRecordFile;
enum {

View File

@@ -86,10 +86,26 @@ CDBErr CDBRecordClose(CDBRecord* record);
CDBErr CDBRecordGetDataSize(CDBRecord* record, u32* recordSize);
CDBErr CDBRecordGetId(CDBRecord* record, CDBId* id);
#ifdef CDB_RECORD_IMPLEMENTATION
void CDBRecordGetCalendarTimeForce(CDBRecord* record, int* year, int* month, int* day, int* hour, int* min, int* sec);
#else
CDBErr CDBRecordGetCalendarTimeForce(CDBRecord* record, int* year, int* month, int* day, int* hour, int* min, int* sec);
#endif
#ifdef CDB_RECORD_IMPLEMENTATION
void CDBRecordGetKeyForce(CDBRecord* record, CDBRecordKey* recordKey);
#else
CDBErr CDBRecordGetKeyForce(CDBRecord* record, CDBRecordKey* recordKey);
#endif
#ifdef CDB_RECORD_IMPLEMENTATION
void CDBRecordGetTypeForce(CDBRecord* record, char* type);
#else
CDBErr CDBRecordGetTypeForce(CDBRecord* record, char* type);
#endif
#ifdef CDB_RECORD_IMPLEMENTATION
void CDBRecordGetGameCodeForce(CDBRecord* record, char* gcStr);
#else
CDBErr CDBRecordGetGameCodeForce(CDBRecord* record, char* gcStr);
#endif
CDBErr CDBRecordRemove(CDBRecord* record);

View File

@@ -0,0 +1,211 @@
#include <revolution/types.h>
#include <string.h>
typedef struct {
int* values;
int capacity;
int size;
int direction;
} CDBIntArray;
void CDBIntCopy(int* destination, const int* value) {
*destination = *value;
}
int CDBIntCompare(const int* left, const int* right) {
if (*left < *right) {
return -1;
}
return *left != *right;
}
void CDBIntArrayInit(CDBIntArray* array, int* values, int capacity) {
array->size = 0;
array->direction = 1;
array->capacity = capacity;
array->values = values;
}
void CDBIntArraySetReverse(CDBIntArray* array) {
array->direction = -1;
}
int CDBIntArraySize(CDBIntArray* array) {
return array->size;
}
int* CDBIntArrayAt(CDBIntArray* array, int index) {
return array->values + index;
}
BOOL CDBIntArrayEmpty(CDBIntArray* array) {
return array->size == 0;
}
BOOL CDBIntArrayFull(CDBIntArray* array) {
return array->capacity <= array->size;
}
int* CDBIntArrayEnd(CDBIntArray* array) {
return array->values + array->size;
}
#pragma dont_inline on
int CDBIntArrayDicInsertR(CDBIntArray* array, int* value, int first, int last) {
int index;
int result;
if (first == last || first == last - 1) {
result = ((*(value) < *(array->values + first)) ? -1 : (*(value) != *(array->values + first)));
if (result < 0) {
return first;
}
result = ((*(value) < *(array->values + last)) ? -1 : (*(value) != *(array->values + last)));
index = last;
if (result >= 0) {
index = last + 1;
}
return index;
}
index = first + (last - first) / 2;
result = ((*(value) < *(array->values + index)) ? -1 : (*(value) != *(array->values + index)));
if (result < 0) {
return CDBIntArrayDicInsertR(array, value, first, index);
}
if (result > 0) {
return CDBIntArrayDicInsertR(array, value, index, last);
}
return index;
}
int* CDBIntArrayDicInsert(CDBIntArray* array, int* value) {
int size = array->size;
int index;
int moveCount;
int* record;
int number;
int stored;
if (size == 0) {
if (size < array->capacity) {
record = array->values + size;
*record = *value;
array->size++;
}
return value;
}
if (array->capacity <= size) {
if (array->direction == 1) {
if (size != 0) {
record = array->values + (size - 1);
} else {
record = array->values;
}
number = *value;
stored = *record;
if ((stored < number ? -1 : stored != number) < 0) {
return record;
}
array->size--;
index = CDBIntArrayDicInsertR(array, value, 0, array->size - 1);
moveCount = (array->size - index) * sizeof(int);
if (array->capacity <= array->size) {
moveCount -= sizeof(int);
}
if (moveCount > 0) {
memmove((array->values + (index + 1)), (array->values + index), moveCount);
}
*(array->values + index) = *value;
if (array->size < array->capacity) {
array->size++;
}
return (array->values + index);
}
record = array->values;
number = *value;
if ((number < *record ? -1 : number != *record) < 0) {
return record;
}
array->size--;
if (array->size >= 0 && array->capacity - 1 >= 0) {
memmove(array->values, array->values + 1, array->size * sizeof(int));
}
index = CDBIntArrayDicInsertR(array, value, 0, array->size - 1);
moveCount = (array->size - index) * sizeof(int);
if (array->capacity <= array->size) {
moveCount -= sizeof(int);
}
if (moveCount > 0) {
memmove((array->values + (index + 1)), (array->values + index), moveCount);
}
*(array->values + index) = *value;
if (array->size < array->capacity) {
array->size++;
}
return (array->values + index);
}
index = CDBIntArrayDicInsertR(array, value, 0, size - 1);
moveCount = (array->size - index) * sizeof(int);
if (array->capacity <= array->size) {
moveCount -= sizeof(int);
}
if (moveCount > 0) {
memmove((array->values + (index + 1)), (array->values + index), moveCount);
}
*(array->values + index) = *value;
if (array->size < array->capacity) {
array->size++;
}
return (array->values + index);
}
int CDBIntArrayDicFindR(CDBIntArray* array, int* value, int first, int last) {
int index;
int result;
if (first == last || first == last - 1) {
result = ((*(value) < *(array->values + first)) ? -1 : (*(value) != *(array->values + first)));
if (result == 0) {
return first;
}
result = ((*(value) < *(array->values + last)) ? -1 : (*(value) != *(array->values + last)));
return result != 0 ? -1 : last;
}
index = first + (last - first) / 2;
result = ((*(value) < *(array->values + index)) ? -1 : (*(value) != *(array->values + index)));
if (result < 0) {
return CDBIntArrayDicFindR(array, value, first, index);
}
if (result > 0) {
return CDBIntArrayDicFindR(array, value, index, last);
}
return index;
}
#pragma dont_inline reset
int* CDBIntArrayDicFind(CDBIntArray* array, int* value) {
int size = array->size;
int index;
if (size == 0) {
return array->values + size;
}
index = CDBIntArrayDicFindR(array, value, 0, size - 1);
if (index != -1) {
return array->values + index;
}
return array->values + array->size;
}

View File

@@ -0,0 +1,953 @@
#define CDB_RECORD_IMPLEMENTATION
#include <private/cdb.h>
#include <revolution/cdb.h>
#include <revolution/net/NETDigest.h>
#include <revolution/os.h>
#include <stddef.h>
#include <string.h>
typedef struct {
u8 state[0xC010];
u32 openFlags;
} CDBRecordDatabaseState;
typedef struct {
u8 buf[0xD0];
} NETHMACContext;
typedef struct {
u8 buf[0x120];
} NETAESContext;
extern CDBErr CDBCryptBufAllocate(CDBCryptBuf** cryptBuf);
extern CDBErr CDBCryptBufFree(CDBCryptBuf** cryptBuf);
extern void CDBLock(void);
extern void CDBUnlock(void);
extern BOOL CDBRecordBelongedDBOpenedAsRW(CDBRecord* record);
extern void CDBGetWiiIdKey(char* wiiIdKey);
extern void CDBCopyWiiIdKey(char* wiiIdKey1, char* wiiIdKey2);
extern void CDBGetDeviceKey(char* devKey);
extern BOOL CDBFSIsExistFile(const char* fileName, CDBLocation location);
extern const void* NETGetSHA1Interface(void);
extern void NETHMACInit(NETHMACContext* context, const void* interface, const void* key, u32 keyLength);
extern void NETHMACUpdate(NETHMACContext* context, const void* data, u32 length);
extern void NETHMACGetDigest(NETHMACContext* context, void* digest);
extern BOOL NETAESCreate(NETAESContext* context, const void* key, u32 keyLength, const void* iv);
extern void NETAESDelete(NETAESContext* context);
extern BOOL NETAESEncrypt(NETAESContext* context, void* dst, const void* src, u32 length);
extern BOOL NETAESDecrypt(NETAESContext* context, void* dst, const void* src, u32 length);
static u8 s_cdbCryptBuffer[0x40] ALIGN32;
static u8 s_cdbCryptBufferResult[0x40] ALIGN32;
static const u8 s_cdbCryptKey[0x10] = {0};
CDBErr CDBRecordOpen_(CDBRecord* record);
CDBErr CDBRecordOpenReadOnly_(CDBRecord* record);
CDBErr CDBRecordClose_(CDBRecord* record);
CDBErr CDBRecordWrite_(CDBRecord* record, void* buffer, u32 size);
CDBErr CDBRecordRemove_(CDBRecord* record);
CDBErr CDBRecordBackupToSD_(CDBRecord* record);
CDBErr CDBRecordUpdateModifiedDate(CDBRecord* record);
CDBErr CDBRecordEncrypt(CDBRecord* record, void* buffer, CDBRecordKey* key, u32 size, u32* encryptedSize);
CDBErr CDBRecordDecrypt(CDBRecord* record, void* buffer, u32 size, u32* dataSize, CDBRecordKey* key);
void CDBRecordInstanceInit(CDBRecordFile* recordFile, CDBRecord* record, int type) {
OSLockMutex((OSMutex*)recordFile);
recordFile->used = 1;
OSUnlockMutex((OSMutex*)recordFile);
recordFile->unk_0x1C = type;
recordFile->database = record->unk_0x00;
CDBAttrInit(&recordFile->attr);
CDBRecordKeyCopy(&recordFile->key, &record->key);
}
BOOL CDBRecordInstanceIsUsed(CDBRecordFile* recordFile) {
BOOL used;
OSLockMutex((OSMutex*)recordFile);
used = recordFile->used;
OSUnlockMutex((OSMutex*)recordFile);
return used;
}
void CDBRecordInitDescriptor(CDBRecord* record, CDBDatabase* database, CDBRecordKey* key) {
CDBLock();
record->unk_0x00 = (u32)database;
CDBRecordKeyCopy(&record->key, key);
record->cryptBuf = NULL;
record->file = NULL;
CDBUnlock();
}
CDBErr CDBRecordCreateAtOnce(CDBRecord* record, CDBDatabase* database, const char* desc, char* fileType, CDBDate epoch, int gameCode, u16 makerCode,
void* buffer, u32 size) {
CDBRecordKey key;
CDBAttr attr;
CDBErr err;
if (strlen(fileType) >= 6) {
return CDB_ERROR_19;
}
if (size < CDB_RECORD_BUFFER_SIZE) {
return CDB_ERROR_20;
}
CDBRecordKeyInit(&key, epoch, gameCode, makerCode, 0, fileType, CDB_FS_LOCATION_NAND);
CDBLock();
record->unk_0x00 = (u32)database;
CDBRecordKeyCopy(&record->key, &key);
record->cryptBuf = NULL;
record->file = NULL;
CDBUnlock();
err = CDBAttrCreateOnNAND(&attr, desc, epoch);
if (err != CDB_ERROR_OK) {
return err;
}
err = CDBAttrSetModifiedCount(&attr, 1);
if (err != CDB_ERROR_OK) {
return err;
}
memcpy(buffer, &attr, CDB_RECORD_BUFFER_SIZE);
return CDBRecordFileCreateAtOnce(record, buffer, size);
}
CDBErr CDBRecordOpen(CDBRecord* record) {
CDBErr err;
CDBLock();
err = CDBRecordOpen_(record);
CDBUnlock();
return err;
}
CDBErr CDBRecordOpen_(CDBRecord* record) {
char fullPath[256];
CDBCryptBuf* cryptBuf;
CDBErr err;
CDBDatabase* database;
CDBRecordDatabaseState* instance;
database = (CDBDatabase*)record->unk_0x00;
instance = database->instance;
record->cryptBuf = NULL;
if (instance == NULL) {
CDBReportError("(CDB) error : can't open the record; the database is closed\n");
return CDB_ERROR_27;
}
if ((instance->openFlags & 2) == 0) {
CDBReportError("can't open the record; the database is READONLY\n");
return CDB_ERROR_26;
}
CDBConvKeyToFullPath(&record->key, fullPath);
err = CDBRecordFileOpen(record, fullPath, CDB_RECORD_ALLOC_RW);
if (err != CDB_ERROR_OK) {
return err;
}
err = CDBRecordFileReadAttrBuf(record);
if (err != CDB_ERROR_OK) {
return err;
}
if (record->key.location == CDB_FS_LOCATION_SD) {
err = CDBCryptBufAllocate((CDBCryptBuf**)&record->cryptBuf);
if (err != CDB_ERROR_OK) {
return err;
}
cryptBuf = (CDBCryptBuf*)record->cryptBuf;
if (record == NULL || !CDBRecordKeyIsValid(&record->key)) {
err = CDB_ERROR_1;
} else {
if (record->key.location == CDB_FS_LOCATION_SD) {
goto open_location_ok;
}
err = CDB_ERROR_2;
goto open_result_ready;
open_location_ok:
if (CDBFSSDIsMounted()) {
err = CDBRecordDecrypt(record, cryptBuf, 0x3EC00, &cryptBuf->unk_0x3EC00, NULL);
} else {
err = CDB_ERROR_SD_IS_NOT_MOUNTED;
}
}
open_result_ready:
if (err != CDB_ERROR_OK) {
CDBCryptBufFree((CDBCryptBuf**)&record->cryptBuf);
return err;
}
cryptBuf->unk_0x3EC04 = sizeof(CDBAttrBuf);
}
return CDB_ERROR_OK;
}
CDBErr CDBRecordOpenReadOnly(CDBRecord* record) {
CDBErr err;
CDBLock();
err = CDBRecordOpenReadOnly_(record);
CDBUnlock();
return err;
}
CDBErr CDBRecordOpenReadOnly_(CDBRecord* record) {
char fullPath[260];
CDBErr err;
CDBErr result;
CDBCryptBuf* cryptBuf;
record->cryptBuf = NULL;
if (!CDBRecordKeyIsValid(&record->key)) {
CDBReportError("invalid key\n");
return CDB_ERROR_5;
}
CDBConvKeyToFullPath(&record->key, fullPath);
err = CDBRecordFileOpen(record, fullPath, CDB_RECORD_ALLOC_READ);
if (err != CDB_ERROR_OK) {
return err;
}
err = CDBRecordFileReadAttrBuf(record);
if (err != CDB_ERROR_OK) {
return err;
}
if (record->key.location == CDB_FS_LOCATION_SD) {
err = CDBCryptBufAllocate((CDBCryptBuf**)&record->cryptBuf);
if (err != CDB_ERROR_OK) {
return err;
}
cryptBuf = (CDBCryptBuf*)record->cryptBuf;
if (record == NULL || !CDBRecordKeyIsValid(&record->key)) {
result = CDB_ERROR_1;
} else {
if (record->key.location == CDB_FS_LOCATION_SD) {
goto location_ok;
}
result = CDB_ERROR_2;
goto result_ready;
location_ok:
if (CDBFSSDIsMounted()) {
result = CDBRecordDecrypt(record, cryptBuf, 0x3EC00, &cryptBuf->unk_0x3EC00, NULL);
} else {
result = CDB_ERROR_SD_IS_NOT_MOUNTED;
}
}
result_ready:
if (result != CDB_ERROR_OK) {
CDBCryptBufFree((CDBCryptBuf**)&record->cryptBuf);
return result;
}
cryptBuf->unk_0x3EC04 = sizeof(CDBAttrBuf);
}
return CDB_ERROR_OK;
}
CDBErr CDBRecordClose(CDBRecord* record) {
CDBErr err;
CDBLock();
err = CDBRecordClose_(record);
CDBUnlock();
return err;
}
CDBErr CDBRecordClose_(CDBRecord* record) {
CDBRecordFile* recordFile;
CDBErr err;
recordFile = record->file;
if (record->cryptBuf != NULL) {
err = CDBCryptBufFree((CDBCryptBuf**)&record->cryptBuf);
if (err != CDB_ERROR_OK) {
return err;
}
}
if (recordFile == NULL) {
return CDB_ERROR_27;
}
err = CDBRecordFileWriteAttrBuf(record);
if (err != CDB_ERROR_OK && err != CDB_ERROR_SD_EJECTED && err != CDB_ERROR_VF_ERROR) {
return err;
}
err = CDBRecordFileClose(record);
if (err != CDB_ERROR_OK) {
return err;
}
if (record->key.location == CDB_FS_LOCATION_NAND) {
err = CDBVFSync();
if (err != CDB_ERROR_OK) {
return err;
}
}
return CDB_ERROR_OK;
}
CDBErr CDBRecordWrite(CDBRecord* record, void* buffer, u32 size) {
CDBErr err;
CDBLock();
err = CDBRecordWrite_(record, buffer, size);
CDBUnlock();
return err;
}
CDBErr CDBRecordWrite_(CDBRecord* record, void* buffer, u32 size) {
CDBRecordFile* recordFile;
CDBDatabase* database;
CDBErr err;
CDBErr result;
CDBRecordDatabaseState* instance;
database = (CDBDatabase*)record->unk_0x00;
instance = database->instance;
recordFile = record->file;
if (record->key.location == CDB_FS_LOCATION_SD) {
return CDB_ERROR_ACCESS_DENIED;
}
if ((instance->openFlags & 2) == 0) {
CDBReportError("can't write data in the record; the database is opened as READONLY\n");
return CDB_ERROR_26;
}
if (!CDBRecordBelongedDBOpenedAsRW(record)) {
CDBReportError("can't write data in the record; permission denied\n");
return CDB_ERROR_ACCESS_DENIED;
}
if (recordFile == NULL) {
CDBReportError("can't write data in the record; the record is closed\n");
return CDB_ERROR_27;
}
if ((recordFile->unk_0x1C & 2) == 0) {
CDBReportError("can't write data in the record; the record is opened as READONLY\n");
return CDB_ERROR_27;
}
err = CDBRecordFileWriteData(record, buffer, size);
if (err != CDB_ERROR_OK) {
return err;
}
err = CDBRecordUpdateModifiedDate(record);
result = CDB_ERROR_OK;
if (err != CDB_ERROR_OK) {
result = err;
}
return result;
}
CDBErr CDBRecordRead(CDBRecord* record, void* buffer, u32 size, u32* readSize) {
CDBErr err;
CDBLock();
if (record->file == NULL) {
CDBReportError("can't read data in the record; the record is closed\n");
err = CDB_ERROR_27;
} else {
err = CDBRecordFileReadData(record, buffer, size, readSize);
}
CDBUnlock();
return err;
}
CDBErr CDBRecordSeek(CDBRecord* record, s32 offset, CDBSeek seek) {
CDBErr err;
CDBLock();
if (record->file == NULL) {
err = CDB_ERROR_27;
} else {
switch (seek) {
case CDB_SEEK_CUR: {
err = CDBRecordFileSeekData(record, offset, CDB_SEEK_CUR);
break;
}
case CDB_SEEK_BEGIN: {
err = CDBRecordFileSeekData(record, offset, CDB_SEEK_BEGIN);
break;
}
case CDB_SEEK_END: {
err = CDBRecordFileSeekData(record, offset, CDB_SEEK_END);
break;
}
default:
err = CDB_ERROR_1;
break;
}
}
CDBUnlock();
return err;
}
CDBErr CDBRecordGetDataSize(CDBRecord* record, u32* size) {
CDBErr err;
CDBLock();
if (record->file == NULL) {
CDBReportError("can't get data size of the record ; the record is closed\n");
err = CDB_ERROR_27;
} else {
err = CDBRecordFileGetDataSize(record, size);
}
CDBUnlock();
return err;
}
CDBErr CDBRecordRemove(CDBRecord* record) {
CDBErr err;
CDBLock();
err = CDBRecordRemove_(record);
CDBUnlock();
return err;
}
CDBErr CDBRecordRemove_(CDBRecord* record) {
CDBErr err;
CDBErr result;
if (record->file != NULL) {
CDBReportError("can't remove the record ; the record is opened\n");
return CDB_ERROR_28;
}
if (!CDBRecordBelongedDBOpenedAsRW(record)) {
CDBReportError("can't remove the record ; permission denied\n");
return CDB_ERROR_ACCESS_DENIED;
}
err = CDBRecordFileDelete(record);
if (err != CDB_ERROR_OK) {
return err;
}
err = CDBVFSync();
result = CDB_ERROR_OK;
if (err != CDB_ERROR_OK) {
result = err;
}
return result;
}
void CDBRecordGetTypeForce(CDBRecord* record, char* type) {
CDBLock();
CDBConvKeyStrToType(record->key.keyString, type);
CDBUnlock();
}
void CDBRecordGetGameCodeForce(CDBRecord* record, char* gameCode) {
u32 value;
CDBLock();
CDBConvKeyStrToGameCode(record->key.keyString, &value);
CDBConvGCValueToGCStr(value, gameCode);
CDBUnlock();
}
void CDBRecordGetKeyForce(CDBRecord* record, CDBRecordKey* key) {
CDBLock();
CDBRecordKeyCopy(key, &record->key);
CDBUnlock();
}
void CDBRecordGetCalendarTimeForce(CDBRecord* record, int* year, int* month, int* day, int* hour, int* min, int* sec) {
char epochString[64];
CDBDate epoch;
CDBLock();
CDBConvKeyStrToEpochStr(record->key.keyString, epochString);
CDBConvEpochStrToEpochValue(epochString, &epoch);
CDBConvEpochValueToDate(epoch, year, month, day, hour, min, sec);
CDBUnlock();
}
CDBErr CDBRecordGetId(CDBRecord* record, CDBId* id) {
CDBErr err = CDB_ERROR_OK;
CDBRecordFile* recordFile;
char epochString[64];
CDBLock();
recordFile = record->file;
if (recordFile == NULL) {
CDBReportError("can't get CDBId of the record ; the record is closed\n");
err = CDB_ERROR_27;
goto get_id_done;
} else {
CDBLock();
if (record->file == NULL) {
CDBReportError("can't get CDBId of the record ; the record is closed\n");
err = CDB_ERROR_27;
} else {
CDBLock();
CDBConvKeyStrToEpochStr(record->key.keyString, epochString);
CDBConvEpochStrToEpochValue(epochString, &id->num);
CDBUnlock();
err = CDB_ERROR_OK;
}
CDBUnlock();
}
switch (err) {
case CDB_ERROR_OK:
err = CDBAttrGetIDNumber(&recordFile->attr, (CDBId*)&id->modifiedCount);
err = CDB_ERROR_OK;
break;
default:
goto get_id_done;
}
get_id_done:
CDBUnlock();
return err;
}
BOOL CDBRecordIsExistFile(CDBRecord* record) {
char fullPath[256];
CDBConvKeyToFullPath(&record->key, fullPath);
return CDBFSIsExistFile(fullPath, record->key.location);
}
CDBErr CDBRecordUpdateModifiedDate(CDBRecord* record) {
s64 ticks;
u32 modifiedDate;
u32 modifiedCount;
CDBRecordFile* recordFile;
CDBErr err;
ticks = OSGetTime();
modifiedDate = ticks / (OS_BUS_CLOCK / 4);
recordFile = record->file;
if ((((CDBRecordDatabaseState*)((CDBDatabase*)record->unk_0x00)->instance)->openFlags & 2) == 0) {
CDBReportError("can't set modified time of the record; the database is opened as READONLY\n");
return CDB_ERROR_26;
}
if (recordFile == NULL) {
CDBReportError("can't set modified time of the record ; the record is closed\n");
return CDB_ERROR_27;
}
err = CDBAttrSetModifiedDate(&recordFile->attr, modifiedDate);
if (err != CDB_ERROR_OK) {
return err;
}
err = CDBAttrGetModifiedCount(&recordFile->attr, &modifiedCount);
if (err != CDB_ERROR_OK) {
return err;
}
modifiedCount++;
err = CDBAttrSetModifiedCount(&recordFile->attr, modifiedCount);
if (err != CDB_ERROR_OK) {
return err;
}
return CDB_ERROR_OK;
}
CDBErr CDBRecordBackupToSD(CDBRecord* record) {
CDBErr err;
CDBLock();
err = CDBRecordBackupToSD_(record);
CDBUnlock();
return err;
}
CDBErr CDBRecordBackupToSD_(CDBRecord* record) {
CDBRecordFile* recordFile;
CDBCryptBuf* cryptBuf;
CDBRecord localRecord;
CDBErr err;
u32 encryptedSize;
localRecord.cryptBuf = NULL;
recordFile = NULL;
if (record == NULL || !CDBRecordKeyIsValid(&record->key)) {
return CDB_ERROR_1;
}
if (record->key.location != CDB_FS_LOCATION_NAND) {
return CDB_ERROR_2;
}
if (!CDBFSSDIsMounted()) {
return CDB_ERROR_SD_IS_NOT_MOUNTED;
}
err = CDBCryptBufAllocate((CDBCryptBuf**)&localRecord.cryptBuf);
if (err != CDB_ERROR_OK) {
CDBLock();
CDBRecordClose_(&localRecord);
CDBUnlock();
return err;
}
cryptBuf = localRecord.cryptBuf;
CDBRecordKeyCopy(&localRecord.key, &record->key);
localRecord.file = NULL;
localRecord.key.location = CDB_FS_LOCATION_SD;
localRecord.unk_0x00 = record->unk_0x00;
err = CDBRecordFileCreateBlank(&localRecord);
if (err != CDB_ERROR_OK) {
CDBLock();
CDBRecordClose_(&localRecord);
CDBUnlock();
return err;
}
err = CDBRecordEncrypt(record, cryptBuf, &localRecord.key, 0x3EC00, &encryptedSize);
if (err != CDB_ERROR_OK) {
CDBLock();
CDBRecordClose_(&localRecord);
CDBUnlock();
CDBRecordFileDelete(&localRecord);
return err;
}
err = CDBRecordFileDump(&localRecord, cryptBuf, encryptedSize);
if (err != CDB_ERROR_OK) {
CDBLock();
CDBRecordClose_(&localRecord);
CDBUnlock();
return err;
}
CDBLock();
err = CDBRecordClose_(record);
CDBUnlock();
if (err != CDB_ERROR_OK) {
CDBLock();
CDBRecordClose_(&localRecord);
CDBUnlock();
return err;
}
CDBLock();
err = CDBRecordRemove_(record);
CDBUnlock();
if (err != CDB_ERROR_OK) {
CDBLock();
CDBRecordClose_(&localRecord);
CDBUnlock();
return err;
}
CDBLock();
recordFile = localRecord.file;
CDBRecordKeyCopy(&record->key, &localRecord.key);
record->unk_0x00 = localRecord.unk_0x00;
record->file = localRecord.file;
record->cryptBuf = localRecord.cryptBuf;
CDBRecordKeyCopy(&recordFile->key, &localRecord.key);
CDBUnlock();
return CDB_ERROR_OK;
}
CDBErr CDBCryptBuffer(void* buffer, u32 size, void* iv, u32* processedSize, BOOL encrypt) {
NETAESContext context ATTRIBUTE_ALIGN(64);
u32 offset;
u32 length;
if (processedSize) {
*processedSize = 0;
}
if (!NETAESCreate(&context, s_cdbCryptKey, 16, iv)) {
CDBReportError("NETAESCreate\n");
return CDB_ERROR_14;
}
offset = 0;
while (offset < size) {
if (processedSize) {
*processedSize += 64;
}
if (offset + 64 < size) {
length = 64;
} else {
length = size - offset;
memset(s_cdbCryptBuffer, 0, 64);
}
memcpy(s_cdbCryptBuffer, (u8*)buffer + offset, length);
if (encrypt) {
if (!NETAESEncrypt(&context, s_cdbCryptBufferResult, s_cdbCryptBuffer, 64)) {
CDBReportError("NETAESEncrypt\n");
NETAESDelete(&context);
return CDB_ERROR_14;
}
} else {
if (!NETAESDecrypt(&context, s_cdbCryptBufferResult, s_cdbCryptBuffer, 64)) {
CDBReportError("NETAESDecrypt\n");
NETAESDelete(&context);
return CDB_ERROR_14;
}
}
memcpy((u8*)buffer + offset, s_cdbCryptBufferResult, 64);
offset += 64;
}
NETAESDelete(&context);
return CDB_ERROR_OK;
}
CDBErr CDBRecordEncrypt(CDBRecord* record, void* buffer, CDBRecordKey* key, u32 size, u32* encryptedSize) {
CDBRecordFile* recordFile;
CDBErr err;
u32 fileSize;
u32 dataSize;
u32 cryptSize;
int fileOffset;
u8 iv[0x10];
u8 wiiIdKey[0x40] ATTRIBUTE_ALIGN(64);
u8 digest[0x14] ATTRIBUTE_ALIGN(64);
CDBAttrSignature signature ATTRIBUTE_ALIGN(64);
NETHMACContext hmac ATTRIBUTE_ALIGN(64);
recordFile = record->file;
memset(wiiIdKey, 0, sizeof(wiiIdKey));
memset(&signature, 0, sizeof(signature));
memset(buffer, 0, size);
if ((s32)recordFile == 0) {
return CDB_ERROR_27;
}
if (recordFile->unk_0x1C == 1) {
return CDB_ERROR_26;
}
if ((s32)buffer == 0) {
return CDB_ERROR_1;
}
{
CDBErr result;
CDBRecordFile* tempFile;
tempFile = record->file;
if ((s32)tempFile == 0) {
result = CDB_ERROR_27;
} else if (tempFile->unk_0x1C == 1) {
result = CDB_ERROR_26;
} else {
CDBAttrSetWiiId(&tempFile->attr, CDBGetWiiId());
result = CDB_ERROR_OK;
}
if (result != CDB_ERROR_OK) {
return CDB_ERROR_OK;
}
}
{
CDBErr result;
if ((s32)record->file == 0) {
result = CDB_ERROR_27;
} else if (((CDBRecordFile*)record->file)->unk_0x1C == 1) {
result = CDB_ERROR_26;
} else {
CDBAttrInitIV(&((CDBRecordFile*)record->file)->attr);
result = CDB_ERROR_OK;
}
if (result != CDB_ERROR_OK) {
return CDB_ERROR_OK;
}
}
{
CDBErr result;
if ((s32)record->file == 0) {
result = CDB_ERROR_27;
} else if (((CDBRecordFile*)record->file)->unk_0x1C == 1) {
result = CDB_ERROR_26;
} else {
CDBAttrSetKeyStr(&((CDBRecordFile*)record->file)->attr, key);
result = CDB_ERROR_OK;
}
if (result != CDB_ERROR_OK) {
return CDB_ERROR_OK;
}
}
CDBLock();
if ((s32)record->file == 0) {
CDBReportError("can't get file size of the record ; the record is closed\n");
err = CDB_ERROR_27;
} else {
err = CDBRecordFileGetFileSize(record, &fileSize);
}
CDBUnlock();
CDBAttrSetFileSize(&recordFile->attr, fileSize);
if (err != CDB_ERROR_OK) {
return CDB_ERROR_OK;
}
CDBLock();
if ((s32)record->file == 0) {
CDBReportError("can't get data size of the record ; the record is closed\n");
err = CDB_ERROR_27;
} else {
err = CDBRecordFileGetDataSize(record, &dataSize);
}
CDBUnlock();
if (err != CDB_ERROR_OK) {
return CDB_ERROR_OK;
}
if (size < dataSize + CDB_RECORD_BUFFER_SIZE) {
return CDB_ERROR_20;
}
memcpy(buffer, &recordFile->attr, CDB_RECORD_BUFFER_SIZE);
CDBLock();
if ((s32)record->file == 0) {
err = CDB_ERROR_27;
} else {
fileOffset = CDBRecordFileTellData(record);
if (fileOffset < 0) {
err = CDB_ERROR_CANNOT_OPEN_FILE;
} else {
err = CDB_ERROR_OK;
}
}
CDBUnlock();
if (err != CDB_ERROR_OK) {
return CDB_ERROR_OK;
}
CDBLock();
if ((s32)record->file == 0) {
err = CDB_ERROR_27;
} else {
err = CDBRecordFileSeekData(record, 0, CDB_SEEK_BEGIN);
}
CDBUnlock();
if (err != CDB_ERROR_OK) {
return CDB_ERROR_OK;
}
CDBLock();
if ((s32)record->file == 0) {
CDBReportError("can't read data in the record; the record is closed\n");
err = CDB_ERROR_27;
} else {
err = CDBRecordFileReadData(record, (u8*)buffer + CDB_RECORD_BUFFER_SIZE, size - CDB_RECORD_BUFFER_SIZE, &dataSize);
}
CDBUnlock();
if (err != CDB_ERROR_OK) {
return CDB_ERROR_OK;
}
CDBLock();
if ((s32)record->file == 0) {
err = CDB_ERROR_27;
} else {
err = CDBRecordFileSeekData(record, fileOffset, CDB_SEEK_BEGIN);
}
CDBUnlock();
if (err != CDB_ERROR_OK) {
return CDB_ERROR_OK;
}
CDBAttrGetIV(&recordFile->attr, iv);
err = CDBCryptBuffer((u8*)buffer + CDB_RECORD_BUFFER_SIZE, dataSize, iv, &cryptSize, TRUE);
if (err != CDB_ERROR_OK) {
return err;
}
CDBGetWiiIdKey((char*)wiiIdKey);
CDBGetDeviceKey((char*)&wiiIdKey[12]);
CDBAttrClearSignature((CDBAttr*)buffer);
NETHMACInit(&hmac, NETGetSHA1Interface(), wiiIdKey, 0x40);
NETHMACUpdate(&hmac, buffer, cryptSize + CDB_RECORD_BUFFER_SIZE);
NETHMACGetDigest(&hmac, digest);
memcpy(((CDBAttrBuf*)buffer)->signature.sha1Hmac, digest, sizeof(digest));
if (encryptedSize != 0) {
*encryptedSize = cryptSize + CDB_RECORD_BUFFER_SIZE;
}
return CDB_ERROR_OK;
}
CDBErr CDBRecordDecrypt(CDBRecord* record, void* buffer, u32 size, u32* dataSize, CDBRecordKey* key) {
CDBErr status;
int fileOffset;
CDBRecordFile* recordFile;
u32 fileDataSize;
u32 fileSize;
u8 iv[16];
CDBRecordKey comparisonKey;
u8 digest[20] ATTRIBUTE_ALIGN(64);
u8 wiiIdKey[64] ATTRIBUTE_ALIGN(16);
NETHMACContext hmac;
CDBAttrSignature signature;
recordFile = record->file;
memset(wiiIdKey, 0, sizeof(wiiIdKey));
memset(&signature, 0, sizeof(signature));
memset(buffer, 0, size);
if ((s32)recordFile == 0) {
return CDB_ERROR_27;
}
if ((s32)buffer == 0) {
return CDB_ERROR_1;
}
{
CDBLock();
if ((s32)record->file == 0) {
CDBReportError("can't get data size of the record ; the record is closed\n");
status = CDB_ERROR_27;
} else {
status = CDBRecordFileGetDataSize(record, &fileDataSize);
}
CDBUnlock();
if (status != CDB_ERROR_OK) {
return CDB_ERROR_OK;
}
}
if (size < fileDataSize + CDB_RECORD_BUFFER_SIZE) {
if (fileDataSize > 0x3E800) {
return CDB_ERROR_32;
}
return CDB_ERROR_20;
}
if ((fileDataSize & 0x3F) != 0) {
return CDB_ERROR_32;
}
{
CDBErr err;
err = CDBRecordFileReadAttrBuf(record);
if (err != CDB_ERROR_OK) {
return CDB_ERROR_32;
}
}
memcpy(buffer, &recordFile->attr, CDB_RECORD_BUFFER_SIZE);
{
CDBErr err;
int offset;
if ((s32)record->file == 0) {
err = CDB_ERROR_27;
} else {
offset = CDBRecordFileTellDataFile(record);
if (offset < 0) {
err = CDB_ERROR_CANNOT_OPEN_FILE;
} else {
fileOffset = offset;
err = CDB_ERROR_OK;
}
}
if (err != CDB_ERROR_OK) {
return err;
}
}
{
CDBErr err;
if ((s32)record->file == 0) {
err = CDB_ERROR_27;
} else {
err = CDBRecordFileSeekDataFile(record, 0, CDB_SEEK_BEGIN);
}
if (err != CDB_ERROR_OK) {
return err;
}
}
{
CDBErr err;
err = CDBRecordFileReadDataFile(record, (u8*)buffer + CDB_RECORD_BUFFER_SIZE, size - CDB_RECORD_BUFFER_SIZE, &fileDataSize);
if (err != CDB_ERROR_OK) {
return err;
}
}
{
CDBErr err;
if ((s32)record->file == 0) {
err = CDB_ERROR_27;
} else {
err = CDBRecordFileSeekDataFile(record, fileOffset, CDB_SEEK_BEGIN);
}
if (err != CDB_ERROR_OK) {
return err;
}
}
CDBAttrGetSignature((CDBAttr*)buffer, &signature);
CDBAttrClearSignature((CDBAttr*)buffer);
if ((s32)key == 0) {
CDBGetWiiIdKey((char*)wiiIdKey);
} else {
CDBCopyWiiIdKey((char*)wiiIdKey, (char*)key);
}
CDBGetDeviceKey((char*)&wiiIdKey[12]);
status = fileDataSize + CDB_RECORD_BUFFER_SIZE;
NETHMACInit(&hmac, NETGetSHA1Interface(), wiiIdKey, 0x40);
NETHMACUpdate(&hmac, buffer, status);
NETHMACGetDigest(&hmac, digest);
if (memcmp(digest, signature.sha1Hmac, 0x14) != 0) {
return CDB_ERROR_32;
}
CDBAttrGetKeyStr((CDBAttr*)buffer, comparisonKey.keyString);
if (CDBRecordKeyCompareByDate(&comparisonKey, &record->key) != 0) {
if (CDBIsPrintDebugMessage(3)) {
CDBReport_(3);
OSReport("CDBRecordPrivateChangeOwner\n");
}
return CDB_ERROR_32;
}
CDBAttrGetIV(&recordFile->attr, iv);
{
CDBErr err;
err = CDBCryptBuffer((u8*)buffer + CDB_RECORD_BUFFER_SIZE, fileDataSize, iv, NULL, FALSE);
if (err != CDB_ERROR_OK) {
return err;
}
}
if (dataSize != 0) {
CDBAttrGetFileSize((CDBAttr*)buffer, &fileSize);
*dataSize = fileSize;
}
return CDB_ERROR_OK;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,29 @@
# CDBIntArray attempts
Baseline 0/13, 0/1556 code. No data sections.
Started with scalar copies, ordered comparison, array descriptors and recursive dictionary operations. Explicit full test operand order and unequal return match the nine basic methods. Initial recursive auto-inlining expanded searches to 412 instructions; disabling recursive inlining and using direct scalar comparisons restores tail calls. Adapted the existing sibling record-key array implementation, using the same capacity and reverse-direction behavior. The same ordinary dont_inline pragma as that sibling preserves the recursive searches. No helper retained solely for emission.
CDBIntArrayDicInsertR | return right index plus comparison | (93.548386, -5) | src 0xf8 base 0xf8 insns 62/62
CDBIntArrayDicInsertR | explicit values in comparisons | (98.30645, -9999) | src 0xfc base 0xf8 insns 63/62
CDBIntArrayDicInsertR | middle first local declaration | (98.30645, -9999) | src 0xfc base 0xf8 insns 63/62
CDBIntArrayDicFindR | direct array indexing | (94.19355, -9999) | src 0xfc base 0xf8 insns 63/62
CDBIntArrayDicFindR | inverted leaf comparison | (100.0, -2) | src 0xf8 base 0xf8 insns 62/62
CDBIntArrayDicFindR | comparison first declaration | (94.19355, -9999) | src 0xfc base 0xf8 insns 63/62
CDBIntArrayDicInsertR | leaf early return | (98.30645, -9999) | src 0xfc base 0xf8 insns 63/62
CDBIntArrayDicInsertR | leaf result conditional expression | (93.548386, -3) | src 0xf8 base 0xf8 insns 62/62
CDBIntArrayDicInsertR | comparison variable before index | (93.548386, -3) | src 0xf8 base 0xf8 insns 62/62
CDBIntArrayDicFindR | leaf positive branch first | (94.19355, -9999) | src 0xfc base 0xf8 insns 63/62
CDBIntArrayDicFindR | leaf conditional expression | (100.0, 0) | src 0xf8 base 0xf8 insns 62/62
CDBIntArrayDicInsert | direct scalar copies | (99.60317, -16) | src 0x2f4 base 0x2f4 insns 189/189
CDBIntArrayDicInsert | record pointer before scalar temporaries | (94.89418, -9999) | src 0x300 base 0x2f4 insns 192/189
CDBIntArrayDicInsert | signed move byte counts | (94.89418, -9999) | src 0x300 base 0x2f4 insns 192/189
CDBIntArrayDicInsertR | separate result index | (100.0, 0) | src 0xf8 base 0xf8 insns 62/62
CDBIntArrayDicInsert | local value loaded before ordered comparisons | (99.78836, -5) | src 0x2f4 base 0x2f4 insns 189/189
CDBIntArrayDicInsert | record local first declaration | (99.60317, -14) | src 0x2f4 base 0x2f4 insns 189/189
CDBIntArrayDicInsert | comparison expression evaluates stored value first | (99.49735, -16) | src 0x2f4 base 0x2f4 insns 189/189
CDBIntArrayDicInsert | stored element captured after incoming value | (100.0, 0) | src 0x2f4 base 0x2f4 insns 189/189
Recursion trials additionally included recursive calls, goto iteration, source-level ordered comparisons and separate leaf return index. Find tried empty end return, found-first branch and shared result before adopting the sibling method; it now matches.
Final: all 13 functions instruction-exact, 1556/1556 code bytes, no data sections. Full gate and pool pass.

View File

@@ -0,0 +1,31 @@
# CDBRecord attempts
Baseline: 0/29 exact, 0/7076 code bytes.
Reconstructed descriptor, instance, cryptographic, and file operations using the target instructions and existing declarations. Named mutex, used flag, database and open flags replace opaque offsets; the header layout is gated by CDB_RECORD_IMPLEMENTATION.
The pool first diverges at string 8: the original contains diagnostics for file-size, reduction, setters, duplication and owner-change functions absent from this extracted object. No unused string objects or artificial padding were retained. BSS buffers and zero AES key match (144 bytes); the 2496-byte data section remains partial.
CDBCryptBuffer | for loop offset progression | (99.97479, -3) | src 0x1dc base 0x1dc insns 119/119
CDBCryptBuffer | remaining-length comparison | (92.411766, -9999) | src 0x1d8 base 0x1dc insns 118/119
CDBCryptBuffer | named input chunk pointer | (96.40336, -9999) | src 0x1e0 base 0x1dc insns 120/119
CDBRecordEncrypt | integer null tests | (96.20422, -68) | src 0x470 base 0x470 insns 284/284
CDBRecordEncrypt | signature and hmac declaration order | (90.60564, -9999) | src 0x494 base 0x470 insns 293/284
CDBRecordEncrypt | single file temporary for setters | (90.60564, -9999) | src 0x494 base 0x470 insns 293/284
CDBRecordDecrypt | 64-byte hash key alignment | (86.073395, -9999) | src 0x384 base 0x368 insns 225/218
CDBRecordDecrypt | integer null tests | (90.348625, -9999) | src 0x370 base 0x368 insns 220/218
CDBRecordDecrypt | signature before digest declaration | (86.0367, -9999) | src 0x384 base 0x368 insns 225/218
CDBRecordDecrypt | signature and hmac alignment | (99.89449, -23) | src 0x368 base 0x368 insns 218/218
CDBRecordDecrypt | 64-byte key alignment with signature | (99.89449, -23) | src 0x368 base 0x368 insns 218/218
CDBRecordDecrypt | reverse file and status declaration lifetime | (99.68807, -32) | src 0x368 base 0x368 insns 218/218
CDBRecordDecrypt | swap digest and key-string lifetimes | (99.944954, -12) | src 0x368 base 0x368 insns 218/218
CDBRecordDecrypt | 16-byte key string alignment | (99.94954, -11) | src 0x368 base 0x368 insns 218/218
CDBRecordDecrypt | unaligned key string | (99.94954, -11) | src 0x368 base 0x368 insns 218/218
CDBRecordDecrypt | complete record key | (99.96789, -7) | src 0x368 base 0x368 insns 218/218
Additional Encrypt attempt: moved error status to the outer scope, 97.19014%, 283/284 instructions.
Additional Decrypt correction: restored 0x3E800 size limit, actual seek/read error returns, level-3 owner warning, output-size local; 218/218 instructions. Natural buffer alignment and declaration order reach 99.96789%, seven stack-address differences.
Remaining: CDBCryptBuffer 99.97479%, 119/119 instructions, three pool offsets; CDBRecordEncrypt 97.19014%, register allocation and one instruction; CDBRecordDecrypt 99.96789%, stack placement.
The four forced field accessors end with CDBUnlock and do not produce a CDBErr result. Their void declarations are gated by CDB_RECORD_IMPLEMENTATION, preserving all other translation units and avoiding fall-through non-void definitions.

View File

@@ -0,0 +1,131 @@
# NWC24Download attempts
Baseline 7/30 instruction-exact, 472/12496 code bytes, 80/80 data bytes.
Pool checked before code tuning: identical (3 strings). Header, title ownership and group permission checks were reconstructed as readable inline helpers; SetDlId, SetDlPriority and GetDlAppId now match. The initializer retains its observed task-list calls. Seek/write/clear helpers restore task and header normalization, close-result propagation, and entry ownership metadata (application ID, not task flags). StoreDlTask and DeleteDlTask now match, with original explicit call boundaries preserved by the repository NO_INLINE macro.
Closest functions were tried first. Each remaining function has at least three distinct compiled source attempts below. Header-helper extraction, declaration lifetime and keeping call boundaries were measured independently, with only improvements retained. Register-only survivors were left after additional scoped-local and branch-form attempts.
NWC24GetDlTask | named destination alias | (99.728264, -5) | src 0x170 base 0x170 insns 92/92
NWC24GetDlTask | task identifier alias before destination | (99.728264, -5) | src 0x170 base 0x170 insns 92/92
NWC24GetDlTask | operation status before read status | (99.728264, -5) | src 0x170 base 0x170 insns 92/92
NWC24GetDlAppId | taskId local declared after header | (99.0, -7) | src 0x8c base 0x8c insns 35/35
NWC24GetDlAppId | task pointer declared after header | (99.0, -7) | src 0x8c base 0x8c insns 35/35
NWC24GetDlAppId | common exit after output | (99.0, -7) | src 0x8c base 0x8c insns 35/35
NWC24SetDlId | work declaration before header | (98.875, -8) | src 0xa0 base 0xa0 insns 40/40
NWC24SetDlId | reuse initial work in refreshed header | (98.875, -8) | src 0xa0 base 0xa0 insns 40/40
NWC24SetDlId | header declared before task identifier | (98.5, -11) | src 0xa0 base 0xa0 insns 40/40
NWC24iLoadDlHeader | scoped write header pointer | (97.9, -4) | src 0x190 base 0x190 insns 100/100
NWC24iLoadDlHeader | seek and read shared operation result | (96.15, -9999) | src 0x194 base 0x190 insns 101/100
NWC24iLoadDlHeader | read status conditional branch | (95.05, -9999) | src 0x198 base 0x190 insns 102/100
NWC24iInitDlTaskList | separate success and version checks | (51.29032, -9999) | src 0xb8 base 0x7c insns 46/31
NWC24iInitDlTaskList | success test nested before version | (51.29032, -9999) | src 0xb8 base 0x7c insns 46/31
NWC24iInitDlTaskList | common final result | (51.129032, -9999) | src 0xb8 base 0x7c insns 46/31
NWC24iInitDlTaskList | preserve task list calls | (100.0, 0) | src 0x7c base 0x7c insns 31/31
NWC24iLoadDlHeader | shared seek-read status with scoped write pointer | (97.25, -16) | src 0x190 base 0x190 insns 100/100
NWC24iLoadDlHeader | seek-read operation local | (97.25, -16) | src 0x190 base 0x190 insns 100/100
NWC24iLoadDlHeader | inline seek-read operation | (96.25, -9999) | src 0x194 base 0x190 insns 101/100
NWC24SetDlPriority | shared inline validation with owner and group predicates | (100.0, 0) | src 0x108 base 0x108 insns 66/66
NWC24SetDlInterval | shared inline validation with owner and group predicates | (99.89796, -3) | src 0x24c base 0x24c insns 147/147
NWC24SetDlUrl | shared inline validation with owner and group predicates | (99.95413, -1) | src 0x1b4 base 0x1b4 insns 109/109
NWC24SetDlFlags | shared inline validation with owner and group predicates | (98.9011, -9999) | src 0x168 base 0x16c insns 90/91
NWC24GetDlAppId | shared inline validation with owner and group predicates | (100.0, 0) | src 0x8c base 0x8c insns 35/35
NWC24SetDlId | shared inline validation with owner and group predicates | (100.0, 0) | src 0xa0 base 0xa0 insns 40/40
NWC24SetDlInterval | separate final identifier lifetime | (99.89796, -3) | src 0x24c base 0x24c insns 147/147
NWC24SetDlInterval | refresh validation helper | (99.89796, -3) | src 0x24c base 0x24c insns 147/147
NWC24SetDlInterval | timestamp temporary declaration first | (99.89796, -3) | src 0x24c base 0x24c insns 147/147
NWC24SetDlFlags | separate reserved flag categories | (95.43956, -4) | src 0x16c base 0x16c insns 91/91
NWC24SetDlFlags | type checks with two cases | (94.83517, -9999) | src 0x15c base 0x16c insns 87/91
NWC24SetDlFlags | write flags from common exit | (93.95605, -9999) | src 0x178 base 0x16c insns 94/91
NWC24SetDlUrl | length error to common URL check | (98.99083, -9999) | src 0x1b0 base 0x1b4 insns 108/109
NWC24SetDlUrl | length guard around schemes | (98.99083, -9999) | src 0x1b0 base 0x1b4 insns 108/109
NWC24SetDlUrl | ownership pointer after result variable | (99.95413, -1) | src 0x1b4 base 0x1b4 insns 109/109
NWC24InitDlTask | cached-header inline helper lifetime | (89.36806, -9999) | src 0x234 base 0x240 insns 141/144
NWC24InitDlTask | scalar and pointer declaration order | (89.36806, -9999) | src 0x234 base 0x240 insns 141/144
NWC24InitDlTask | preserve calls to earlier functions | (89.36806, -9999) | src 0x234 base 0x240 insns 141/144
NWC24DeleteDlTask | cached-header inline helper lifetime | (85.75238, -9999) | src 0x18c base 0x1a4 insns 99/105
NWC24DeleteDlTask | scalar and pointer declaration order | (85.419044, -9999) | src 0x18c base 0x1a4 insns 99/105
NWC24DeleteDlTask | preserve calls to earlier functions | (85.419044, -9999) | src 0x18c base 0x1a4 insns 99/105
NWC24IterateDlTaskEx | scalar and pointer declaration order | (85.06896, -9999) | src 0x234 base 0x244 insns 141/145
NWC24IterateDlTaskEx | preserve calls to earlier functions | (85.06896, -9999) | src 0x234 base 0x244 insns 141/145
NWC24IterateDlTask | cached-header inline helper lifetime | (80.79747, -9999) | src 0x128 base 0x13c insns 74/79
NWC24IterateDlTask | scalar and pointer declaration order | (81.177216, -9999) | src 0x128 base 0x13c insns 74/79
NWC24IterateDlTask | preserve calls to earlier functions | (80.79747, -9999) | src 0x128 base 0x13c insns 74/79
NWC24ManageDlTaskListForMenu | cached-header inline helper lifetime | (73.45395, -9999) | src 0x20c base 0x260 insns 131/152
NWC24ManageDlTaskListForMenu | scalar and pointer declaration order | (73.585526, -9999) | src 0x20c base 0x260 insns 131/152
NWC24ManageDlTaskListForMenu | preserve calls to earlier functions | (73.585526, -9999) | src 0x20c base 0x260 insns 131/152
NWC24PurgeOldestDlTask | cached-header inline helper lifetime | (72.3125, -9999) | src 0x25c base 0x2c0 insns 151/176
NWC24PurgeOldestDlTask | scalar and pointer declaration order | (72.22727, -9999) | src 0x25c base 0x2c0 insns 151/176
NWC24PurgeOldestDlTask | preserve calls to earlier functions | (72.22727, -9999) | src 0x25c base 0x2c0 insns 151/176
DeleteDlTask | scalar and pointer declaration order | (69.92921, -9999) | src 0x16c base 0x1c4 insns 91/113
DeleteDlTask | preserve calls to earlier functions | (69.92921, -9999) | src 0x16c base 0x1c4 insns 91/113
NWC24iCreateDlTaskList | cached-header inline helper lifetime | (69.01504, -9999) | src 0x1e0 base 0x214 insns 120/133
NWC24iCreateDlTaskList | scalar and pointer declaration order | (69.2406, -9999) | src 0x1e0 base 0x214 insns 120/133
NWC24iCreateDlTaskList | preserve calls to earlier functions | (69.01504, -9999) | src 0x1e0 base 0x214 insns 120/133
StoreDlTask | cached-header inline helper lifetime | (68.196075, -9999) | src 0x154 base 0x198 insns 85/102
StoreDlTask | scalar and pointer declaration order | (68.245094, -9999) | src 0x154 base 0x198 insns 85/102
StoreDlTask | preserve calls to earlier functions | (68.245094, -9999) | src 0x154 base 0x198 insns 85/102
NWC24AddDlTask | cached-header inline helper lifetime | (67.14685, -9999) | src 0x1c4 base 0x23c insns 113/143
NWC24AddDlTask | scalar and pointer declaration order | (65.44056, -9999) | src 0x1cc base 0x23c insns 115/143
NWC24AddDlTask | preserve calls to earlier functions | (67.46154, -9999) | src 0x1c4 base 0x23c insns 113/143
AddTaskInternal | cached-header inline helper lifetime | (63.670822, -9999) | src 0x5d0 base 0x644 insns 372/401
AddTaskInternal | scalar and pointer declaration order | (63.658356, -9999) | src 0x5d0 base 0x644 insns 372/401
AddTaskInternal | preserve calls to earlier functions | (63.658356, -9999) | src 0x5d0 base 0x644 insns 372/401
NWC24UpdateDlTask | cached-header inline helper lifetime | (62.225296, -9999) | src 0x408 base 0x3f4 insns 258/253
NWC24UpdateDlTask | scalar and pointer declaration order | (62.343872, -9999) | src 0x408 base 0x3f4 insns 258/253
NWC24UpdateDlTask | preserve calls to earlier functions | (62.225296, -9999) | src 0x408 base 0x3f4 insns 258/253
NWC24ExtendDlTaskList | cached-header inline helper lifetime | (61.992702, -9999) | src 0x1e4 base 0x224 insns 121/137
NWC24ExtendDlTaskList | scalar and pointer declaration order | (61.91971, -9999) | src 0x1e4 base 0x224 insns 121/137
NWC24ExtendDlTaskList | preserve calls to earlier functions | (61.992702, -9999) | src 0x1e4 base 0x224 insns 121/137
NWC24iCheckDlHeaderConsistency | cached-header inline helper lifetime | (53.9717, -9999) | src 0x270 base 0x350 insns 156/212
NWC24iCheckDlHeaderConsistency | scalar and pointer declaration order | (53.853775, -9999) | src 0x270 base 0x350 insns 156/212
NWC24iCheckDlHeaderConsistency | preserve calls to earlier functions | (53.853775, -9999) | src 0x270 base 0x350 insns 156/212
StoreDlTask | full-width cached count in seek helper | (99.70588, -5) | src 0x198 base 0x198 insns 102/102
StoreDlTask | direct count fields in seek helper | (100.0, 0) | src 0x198 base 0x198 insns 102/102
StoreDlTask | id comparison first in seek helper | (95.78432, -7) | src 0x198 base 0x198 insns 102/102
DeleteDlTask | identifier before cached task declaration | (99.823006, -4) | src 0x1c4 base 0x1c4 insns 113/113
DeleteDlTask | result before cached task declaration | (99.42478, -12) | src 0x1c4 base 0x1c4 insns 113/113
DeleteDlTask | separate header reset identifier | (99.42478, -12) | src 0x1c4 base 0x1c4 insns 113/113
NWC24IterateDlTaskEx | descending expression signed sort mode | (85.06896, -9999) | src 0x234 base 0x244 insns 141/145
NWC24IterateDlTaskEx | iteration result next step in for clause | (85.06896, -9999) | src 0x234 base 0x244 insns 141/145
NWC24IterateDlTaskEx | callback value before candidate booleans | (85.06896, -9999) | src 0x234 base 0x244 insns 141/145
DeleteDlTask | clear helper scopes for task and identifier | (100.0, 0) | src 0x1c4 base 0x1c4 insns 113/113
NWC24iCreateDlTaskList | shared clear/write helpers and original close-result propagation | (99.62406, -10) | src 0x214 base 0x214 insns 133/133
NWC24ExtendDlTaskList | shared clear/write helpers and original close-result propagation | (97.62774, -9999) | src 0x230 base 0x224 insns 140/137
NWC24iCreateDlTaskList | header lifetime scoped to initialization | (99.62406, -10) | src 0x214 base 0x214 insns 133/133
NWC24iCreateDlTaskList | header declaration after task id | (99.62406, -10) | src 0x214 base 0x214 insns 133/133
NWC24iCreateDlTaskList | header after error result | (99.62406, -10) | src 0x214 base 0x214 insns 133/133
NWC24ExtendDlTaskList | iteration failure to close block | (99.85401, -4) | src 0x224 base 0x224 insns 137/137
NWC24ExtendDlTaskList | close status declaration before open status | (91.30657, -9999) | src 0x220 base 0x224 insns 136/137
NWC24ExtendDlTaskList | open result scoped away from iteration | (96.86131, -9999) | src 0x234 base 0x224 insns 141/137
NWC24iCreateDlTaskList | header-format initializer helper | (99.62406, -10) | src 0x214 base 0x214 insns 133/133
NWC24ExtendDlTaskList | separate final return status | (91.277374, -9999) | src 0x1f8 base 0x224 insns 126/137
NWC24ExtendDlTaskList | loop identifier separate scope | (99.85401, -4) | src 0x224 base 0x224 insns 137/137
NWC24ExtendDlTaskList | header pointer declaration after close status | (99.85401, -4) | src 0x224 base 0x224 insns 137/137
NWC24UpdateDlTask | shared ownership and validation helpers | (68.19763, -9999) | src 0x420 base 0x3f4 insns 264/253
NWC24DeleteDlTask | shared ownership and validation helpers | (0, -9999) | [1/1] MWCC build/43U/src/libs/RevoEX/src/nwc24/NWC24Download.o
AddTaskInternal | shared ownership and validation helpers | (66.2394, -9999) | src 0x5e4 base 0x644 insns 377/401
Additional Store/Delete trials: reconstructed file helpers (91.27451%, 105/102; 91.28319%,109/113), captured entry pointer and reloaded original identifier (99.70588%,102/102;99.159294%,113/113), widened seek count (Store100%), scoped clear helper (Delete100%). Explicit NO_INLINE declarations prevent these functions from being auto-inlined into Update/AddTaskInternal; all 30 functions were remeasured after these changes.
Remaining:
NWC24InitDlTask 89.36806%: validation, branch shape and instruction count; src 0x234 base 0x240 insns 141/144.
NWC24SetDlInterval 99.89796%: register allocation; src 0x24c base 0x24c insns 147/147.
NWC24SetDlUrl 99.95413%: one error branch destination; src 0x1b4 base 0x1b4 insns 109/109.
NWC24SetDlFlags 98.9011%: validation, branch shape and instruction count; src 0x168 base 0x16c insns 90/91.
NWC24IterateDlTask 81.177216%: validation, branch shape and instruction count; src 0x128 base 0x13c insns 74/79.
NWC24IterateDlTaskEx 85.06896%: validation, branch shape and instruction count; src 0x234 base 0x244 insns 141/145.
NWC24UpdateDlTask 68.19763%: validation, branch shape and instruction count; src 0x420 base 0x3f4 insns 264/253.
NWC24DeleteDlTask 85.75238%: validation, branch shape and instruction count; src 0x18c base 0x1a4 insns 99/105.
NWC24AddDlTask 67.46154%: validation, branch shape and instruction count; src 0x1c4 base 0x23c insns 113/143.
NWC24GetDlTask 99.728264%: register allocation; src 0x170 base 0x170 insns 92/92.
NWC24PurgeOldestDlTask 72.3125%: validation, branch shape and instruction count; src 0x25c base 0x2c0 insns 151/176.
NWC24ManageDlTaskListForMenu 73.585526%: validation, branch shape and instruction count; src 0x20c base 0x260 insns 131/152.
NWC24ExtendDlTaskList 99.85401%: register allocation; src 0x224 base 0x224 insns 137/137.
NWC24iCheckDlHeaderConsistency 53.9717%: validation, branch shape and instruction count; src 0x270 base 0x350 insns 156/212.
NWC24iCreateDlTaskList 99.62406%: register allocation; src 0x214 base 0x214 insns 133/133.
NWC24iLoadDlHeader 97.9%: seek/read error join (four instructions differ); src 0x190 base 0x190 insns 100/100.
AddTaskInternal 66.2394%: validation, branch shape and instruction count; src 0x5e4 base 0x644 insns 377/401.
Final object: {'fuzzy_match_percent': 83.35883, 'total_code': '12496', 'matched_code': '2020', 'matched_code_percent': 16.165173, 'total_data': '80', 'matched_data': '80', 'matched_data_percent': 100.0, 'total_functions': 30, 'matched_functions': 13, 'matched_functions_percent': 43.333332, 'total_units': 1}