diff --git a/source/crypto/keydb.c b/source/crypto/keydb.c index 1479e1f..92ce787 100644 --- a/source/crypto/keydb.c +++ b/source/crypto/keydb.c @@ -3,8 +3,6 @@ #include "sha.h" #include "ff.h" -#define KEYDB_NAME "aeskeydb.bin" - typedef struct { u8 slot; // keyslot, 0x00...0x39 char type; // type 'X' / 'Y' / 'N' for normalKey diff --git a/source/crypto/keydb.h b/source/crypto/keydb.h index 9592fe3..6bf27c0 100644 --- a/source/crypto/keydb.h +++ b/source/crypto/keydb.h @@ -2,6 +2,8 @@ #include "common.h" +#define KEYDB_NAME "aeskeydb.bin" + #define KEYS_UNKNOWN 0 #define KEYS_RETAIL 1 #define KEYS_DEVKIT 2 diff --git a/source/fs/filetype.c b/source/fs/filetype.c index cf4229c..0117f29 100644 --- a/source/fs/filetype.c +++ b/source/fs/filetype.c @@ -3,6 +3,7 @@ #include "fatmbr.h" #include "nand.h" #include "game.h" +#include "keydb.h" #include "chainload.h" u32 IdentifyFileType(const char* path) { @@ -95,11 +96,15 @@ u32 IdentifyFileType(const char* path) { return BIN_TIKDB | FLAG_ENC; // titlekey database / encrypted } else if (strncasecmp(fname, TIKDB_NAME_DEC, sizeof(TIKDB_NAME_DEC)) == 0) { return BIN_TIKDB; // titlekey database / decrypted - } else if ((strncasecmp(fname, "seeddb.bin", 11) == 0) || - (strncasecmp(fname, "aeskeydb.bin", 13) == 0) || - (strncasecmp(fname, "otp.bin", 8) == 0) || - (strncasecmp(fname, "secret_sector.bin", 18) == 0) || - (strncasecmp(fname, "sector0x96.bin", 15) == 0)) { + } else if (strncasecmp(fname, KEYDB_NAME, sizeof(KEYDB_NAME)) == 0) { + return BIN_KEYDB; // key database + } else if ((sscanf(fname, "slot%02lXKey", &id) == 1) && (strncasecmp(ext, "bin", 4) == 0) && (fsize = 16) && (id < 0x40)) { + return BIN_LEGKEY; // legacy key file + } else if ((strncasecmp(fname, OTP_NAME, sizeof(OTP_NAME)) == 0) || + (strncasecmp(fname, OTP_BIG_NAME, sizeof(OTP_BIG_NAME)) == 0) || + (strncasecmp(fname, SEEDDB_NAME, sizeof(SEEDDB_NAME)) == 0) || + (strncasecmp(fname, SECTOR_NAME, sizeof(SECTOR_NAME)) == 0) || + (strncasecmp(fname, SECRET_NAME, sizeof(SECRET_NAME)) == 0)) { return BIN_SUPPORT; // known support file (so launching is not offered) #if PAYLOAD_MAX_SIZE <= TEMP_BUFFER_SIZE } else if ((fsize <= PAYLOAD_MAX_SIZE) && ext && (strncasecmp(ext, "bin", 4) == 0)) { diff --git a/source/fs/filetype.h b/source/fs/filetype.h index 6438fda..e5a49bb 100644 --- a/source/fs/filetype.h +++ b/source/fs/filetype.h @@ -20,7 +20,9 @@ #define BIN_NCCHNFO (1UL<<15) #define BIN_LAUNCH (1UL<<16) #define BIN_TIKDB (1UL<<17) -#define BIN_SUPPORT (1UL<<18) +#define BIN_KEYDB (1UL<<18) +#define BIN_LEGKEY (1UL<<19) +#define BIN_SUPPORT (1UL<<20) #define TYPE_BASE 0x00FFFFFF // 24 bit reserved for base types #define FLAG_ENC (1UL<<28) diff --git a/source/nand/essentials.h b/source/nand/essentials.h index a61a674..6943e70 100644 --- a/source/nand/essentials.h +++ b/source/nand/essentials.h @@ -29,7 +29,7 @@ typedef struct { u8 cmac[0x10]; } __attribute__((packed)) MovableSed; -// /rw/sys/Secure_A (/_B) file +// /rw/sys/SecureInfo_A (/_B) file // see: http://3dbrew.org/wiki/Nandrw/sys/SecureInfo_A typedef struct { u8 signature[0x100]; diff --git a/source/nand/nand.c b/source/nand/nand.c index 9e08c53..ce7620e 100644 --- a/source/nand/nand.c +++ b/source/nand/nand.c @@ -128,7 +128,7 @@ bool InitNandCrypto(void) char path[64]; u8 otp[0x100]; for (u32 i = 0; i < 2 * (sizeof(base)/sizeof(char*)); i++) { - snprintf(path, 64, "%s/%s", base[i/2], (i%2) ? "otp0x108.bin" : "otp.bin"); + snprintf(path, 64, "%s/%s", base[i/2], (i%2) ? OTP_BIG_NAME : OTP_NAME); if (FileGetData(path, otp, 0x100, 0) == 0x100) { sha_quick(OtpSha256, otp, 0x90, SHA256_MODE); break; diff --git a/source/nand/nand.h b/source/nand/nand.h index bd5709a..136fab2 100644 --- a/source/nand/nand.h +++ b/source/nand/nand.h @@ -38,6 +38,8 @@ // filenames for sector 0x96 #define SECTOR_NAME "sector0x96.bin" #define SECRET_NAME "secret_sector.bin" +#define OTP_NAME "otp.bin" +#define OTP_BIG_NAME "otp0x108.bin" bool InitNandCrypto(void); bool CheckSlot0x05Crypto(void);