Updated file type detection routines

... now also detects aeskeydb.bin & legacy slop0x??Key?.bin files
This commit is contained in:
d0k3 2017-04-17 23:38:30 +02:00
parent 60e2479b16
commit 679d90dea7
7 changed files with 19 additions and 10 deletions

View File

@ -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

View File

@ -2,6 +2,8 @@
#include "common.h"
#define KEYDB_NAME "aeskeydb.bin"
#define KEYS_UNKNOWN 0
#define KEYS_RETAIL 1
#define KEYS_DEVKIT 2

View File

@ -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)) {

View File

@ -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)

View File

@ -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];

View File

@ -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;

View File

@ -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);