diff --git a/source/crypto/keydb.c b/source/crypto/keydb.c index de8ce6f..8735482 100644 --- a/source/crypto/keydb.c +++ b/source/crypto/keydb.c @@ -198,8 +198,8 @@ u32 LoadKeyFromFile(u8* key, u32 keyslot, char type, char* id) FIL fp; char path[64]; UINT btr; - snprintf(path, 64, "%s/slot0x%02lXKey%s.bin", base[i], keyslot, - (id) ? id : (type == 'X') ? "X" : (type == 'Y') ? "Y" : ""); + snprintf(path, 64, "%s/slot0x%02lXKey%s%s.bin", base[i], keyslot, + (type == 'X') ? "X" : (type == 'Y') ? "Y" : (type == 'I') ? "IV" : "", (id) ? id : ""); if (f_open(&fp, path, FA_READ | FA_OPEN_EXISTING) != FR_OK) continue; if ((f_read(&fp, key, 16, &btr) == FR_OK) && (btr == 16)) found = true; diff --git a/source/game/keydbutil.c b/source/game/keydbutil.c index 1bd2abe..2cb436e 100644 --- a/source/game/keydbutil.c +++ b/source/game/keydbutil.c @@ -93,21 +93,26 @@ u32 BuildKeyDb(const char* path, bool dump) { } else if (filetype & BIN_LEGKEY) { // legacy key file AesKeyInfo key; unsigned int keyslot = 0xFF; - char typestr[16] = { 0 }; + char typestr[32] = { 0 }; char* name_in = strrchr(path_in, '/'); memset(&key, 0, sizeof(AesKeyInfo)); key.type = 'N'; if (!name_in || (strnlen(++name_in, 32) > 24)) return 1; // safety if ((sscanf(name_in, "slot0x%02XKey%s", &keyslot, typestr) != 2) && (sscanf(name_in, "slot0x%02Xkey%s", &keyslot, typestr) != 2)) return 1; - char* dot = strrchr(typestr, '.'); - if (!dot) return 1; - *dot = '\0'; - if ((typestr[1] == '\0') && ((*typestr == 'X') || (*typestr == 'Y'))) key.type = *typestr; - else if ((typestr[2] == '\0') && (typestr[0] == 'I') && (typestr[1] == 'V')) key.type = 'I'; - else strncpy(key.id, typestr, 10); + char* ext = strchr(typestr, '.'); + if (!ext) return 1; + *(ext++) = '\0'; + if ((*typestr == 'X') || (*typestr == 'Y')) { + key.type = *typestr; + strncpy(key.id, typestr + 1, 10); + } else if ((typestr[0] == 'I') && (typestr[1] == 'V')) { + key.type = 'I'; + strncpy(key.id, typestr + 2, 10); + } else strncpy(key.id, typestr, 10); key.slot = keyslot; - key.keyUnitType = 0; + key.keyUnitType = (strncasecmp(ext, "ret.bin", 10) == 0) ? KEYS_RETAIL : + (strncasecmp(ext, "dev.bin", 10) == 0) ? KEYS_DEVKIT : 0; if ((fvx_qread(path_in, key.key, 0, 16, &br) != FR_OK) || (br != 16)) return 1; if (AddKeyToDb(key_info, &key) != 0) return 1; } diff --git a/source/virtual/vkeydb.c b/source/virtual/vkeydb.c index b600492..f0a3fc1 100644 --- a/source/virtual/vkeydb.c +++ b/source/virtual/vkeydb.c @@ -41,10 +41,9 @@ bool ReadVKeyDbDir(VirtualFile* vfile, VirtualDir* vdir) { char typestr[16] = { 0 }; char* unitext = (key_entry->keyUnitType == KEYS_DEVKIT) ? ".dev" : - (key_entry->keyUnitType == KEYS_RETAIL) ? ".ret" : ""; - if (*(key_entry->id)) snprintf(typestr, 10, key_entry->id); - else if (key_entry->type == 'I') snprintf(typestr, 10, "IV"); - else if (key_entry->type != 'N') *typestr = key_entry->type; + (key_entry->keyUnitType == KEYS_RETAIL) ? ".ret" : ""; + snprintf(typestr, 12 + 1, "%s%.10s", (key_entry->type == 'I') ? "IV" : + (key_entry->type == 'X') ? "X" : (key_entry->type == 'Y') ? "Y" : "", key_entry->id); memset(vfile, 0, sizeof(VirtualFile)); snprintf(vfile->name, 32, NAME_LEGKEY, keyslot, typestr, unitext);