mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 05:32:47 +00:00
Allow forced initialization of aeskeydb.bin files
This commit is contained in:
parent
69c89409c7
commit
5ec488937e
@ -218,7 +218,7 @@ u32 LoadKeyFromFile(void* key, u32 keyslot, char type, char* id)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 InitKeyDb( void )
|
u32 InitKeyDb(const char* path)
|
||||||
{
|
{
|
||||||
// use this to quickly initialize all applicable keys in aeskeydb.bin
|
// use this to quickly initialize all applicable keys in aeskeydb.bin
|
||||||
static const u64 keyslot_whitelist = (1ull<<0x02)|(1ull<<0x03)|(1ull<<0x05)|(1ull<<0x18)|(1ull<<0x19)|(1ull<<0x1A)|(1ull<<0x1B)|
|
static const u64 keyslot_whitelist = (1ull<<0x02)|(1ull<<0x03)|(1ull<<0x05)|(1ull<<0x18)|(1ull<<0x19)|(1ull<<0x1A)|(1ull<<0x1B)|
|
||||||
@ -226,7 +226,7 @@ u32 InitKeyDb( void )
|
|||||||
|
|
||||||
// try to load aeskeydb.bin file
|
// try to load aeskeydb.bin file
|
||||||
AesKeyInfo* keydb = (AesKeyInfo*) (void*) TEMP_BUFFER;
|
AesKeyInfo* keydb = (AesKeyInfo*) (void*) TEMP_BUFFER;
|
||||||
u32 nkeys = LoadKeyDb(NULL, keydb, TEMP_BUFFER_SIZE);
|
u32 nkeys = LoadKeyDb(path, keydb, TEMP_BUFFER_SIZE);
|
||||||
if (!nkeys) return 1;
|
if (!nkeys) return 1;
|
||||||
|
|
||||||
// apply all applicable keys
|
// apply all applicable keys
|
||||||
@ -234,7 +234,7 @@ u32 InitKeyDb( void )
|
|||||||
AesKeyInfo* info = &(keydb[i]);
|
AesKeyInfo* info = &(keydb[i]);
|
||||||
if ((info->slot >= 0x40) || ((info->type != 'X') && (info->type != 'Y') && (info->type != 'N') && (info->type != 'I')))
|
if ((info->slot >= 0x40) || ((info->type != 'X') && (info->type != 'Y') && (info->type != 'N') && (info->type != 'I')))
|
||||||
return 1; // looks faulty, better stop right here
|
return 1; // looks faulty, better stop right here
|
||||||
if (!((1ull<<info->slot)&keyslot_whitelist)) continue; // not in keyslot whitelist
|
if (!path && !((1ull<<info->slot)&keyslot_whitelist)) continue; // not in keyslot whitelist
|
||||||
if ((info->type == 'I') || (*(info->id)) || (info->keyUnitType && (info->keyUnitType != GetUnitKeysType())) ||
|
if ((info->type == 'I') || (*(info->id)) || (info->keyUnitType && (info->keyUnitType != GetUnitKeysType())) ||
|
||||||
(CheckKeySlot(info->slot, info->type) == 0)) continue; // most likely valid, but not applicable or already set
|
(CheckKeySlot(info->slot, info->type) == 0)) continue; // most likely valid, but not applicable or already set
|
||||||
if (info->isEncrypted) CryptAesKeyInfo(info); // decrypt key
|
if (info->isEncrypted) CryptAesKeyInfo(info); // decrypt key
|
||||||
|
@ -21,4 +21,4 @@ typedef struct {
|
|||||||
u32 GetUnitKeysType(void);
|
u32 GetUnitKeysType(void);
|
||||||
void CryptAesKeyInfo(AesKeyInfo* info);
|
void CryptAesKeyInfo(AesKeyInfo* info);
|
||||||
u32 LoadKeyFromFile(void* key, u32 keyslot, char type, char* id);
|
u32 LoadKeyFromFile(void* key, u32 keyslot, char type, char* id);
|
||||||
u32 InitKeyDb(void);
|
u32 InitKeyDb(const char* path);
|
||||||
|
@ -18,12 +18,11 @@
|
|||||||
#define SYS_FIRM (1UL<<13)
|
#define SYS_FIRM (1UL<<13)
|
||||||
#define SYS_TICKDB (1UL<<14)
|
#define SYS_TICKDB (1UL<<14)
|
||||||
#define BIN_NCCHNFO (1UL<<15)
|
#define BIN_NCCHNFO (1UL<<15)
|
||||||
#define BIN_LAUNCH (1UL<<16)
|
#define BIN_TIKDB (1UL<<16)
|
||||||
#define BIN_TIKDB (1UL<<17)
|
#define BIN_KEYDB (1UL<<17)
|
||||||
#define BIN_KEYDB (1UL<<18)
|
#define BIN_LEGKEY (1UL<<18)
|
||||||
#define BIN_LEGKEY (1UL<<19)
|
#define TXT_SCRIPT (1UL<<19)
|
||||||
#define TXT_SCRIPT (1UL<<20)
|
#define TXT_GENERIC (1UL<<20)
|
||||||
#define TXT_GENERIC (1UL<<21)
|
|
||||||
#define TYPE_BASE 0x00FFFFFF // 24 bit reserved for base types
|
#define TYPE_BASE 0x00FFFFFF // 24 bit reserved for base types
|
||||||
|
|
||||||
#define FLAG_ENC (1UL<<28)
|
#define FLAG_ENC (1UL<<28)
|
||||||
@ -47,8 +46,8 @@
|
|||||||
#define FTYPE_RESTORABLE(tp) (tp&(IMG_NAND))
|
#define FTYPE_RESTORABLE(tp) (tp&(IMG_NAND))
|
||||||
#define FTYPE_EBACKUP(tp) (tp&(IMG_NAND))
|
#define FTYPE_EBACKUP(tp) (tp&(IMG_NAND))
|
||||||
#define FTYPE_XORPAD(tp) (tp&(BIN_NCCHNFO))
|
#define FTYPE_XORPAD(tp) (tp&(BIN_NCCHNFO))
|
||||||
|
#define FTYPE_KEYINIT(tp) (tp&(BIN_KEYDB))
|
||||||
#define FTYPE_SCRIPT(tp) (tp&(TXT_SCRIPT))
|
#define FTYPE_SCRIPT(tp) (tp&(TXT_SCRIPT))
|
||||||
#define FTYPE_PAYLOAD(tp) (tp&(BIN_LAUNCH))
|
|
||||||
#define FTYPE_BOOTABLE(tp) (tp&(SYS_FIRM))
|
#define FTYPE_BOOTABLE(tp) (tp&(SYS_FIRM))
|
||||||
|
|
||||||
u32 IdentifyFileType(const char* path);
|
u32 IdentifyFileType(const char* path);
|
||||||
|
@ -904,11 +904,12 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, DirStruct* cur
|
|||||||
bool restorable = (FTYPE_RESTORABLE(filetype) && IS_A9LH && !(drvtype & DRV_SYSNAND));
|
bool restorable = (FTYPE_RESTORABLE(filetype) && IS_A9LH && !(drvtype & DRV_SYSNAND));
|
||||||
bool ebackupable = (FTYPE_EBACKUP(filetype));
|
bool ebackupable = (FTYPE_EBACKUP(filetype));
|
||||||
bool xorpadable = (FTYPE_XORPAD(filetype));
|
bool xorpadable = (FTYPE_XORPAD(filetype));
|
||||||
|
bool keyinitable = (FTYPE_KEYINIT(filetype));
|
||||||
bool scriptable = (FTYPE_SCRIPT(filetype));
|
bool scriptable = (FTYPE_SCRIPT(filetype));
|
||||||
bool bootable = (FTYPE_BOOTABLE(filetype) && !(drvtype & DRV_VIRTUAL));
|
bool bootable = (FTYPE_BOOTABLE(filetype) && !(drvtype & DRV_VIRTUAL));
|
||||||
bool special_opt = mountable || verificable || decryptable || encryptable || cia_buildable || cia_buildable_legit || cxi_dumpable ||
|
bool special_opt = mountable || verificable || decryptable || encryptable || cia_buildable || cia_buildable_legit || cxi_dumpable ||
|
||||||
tik_buildable || key_buildable || titleinfo || renamable || transferable || hsinjectable || restorable || xorpadable ||
|
tik_buildable || key_buildable || titleinfo || renamable || transferable || hsinjectable || restorable || xorpadable ||
|
||||||
ebackupable || bootable || scriptable;
|
ebackupable || keyinitable || bootable || scriptable;
|
||||||
|
|
||||||
char pathstr[32+1];
|
char pathstr[32+1];
|
||||||
TruncateString(pathstr, curr_entry->path, 32, 8);
|
TruncateString(pathstr, curr_entry->path, 32, 8);
|
||||||
@ -1063,6 +1064,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, DirStruct* cur
|
|||||||
int rename = (renamable) ? ++n_opt : -1;
|
int rename = (renamable) ? ++n_opt : -1;
|
||||||
int xorpad = (xorpadable) ? ++n_opt : -1;
|
int xorpad = (xorpadable) ? ++n_opt : -1;
|
||||||
int xorpad_inplace = (xorpadable) ? ++n_opt : -1;
|
int xorpad_inplace = (xorpadable) ? ++n_opt : -1;
|
||||||
|
int keyinit = (keyinitable) ? ++n_opt : -1;
|
||||||
int boot = (bootable) ? ++n_opt : -1;
|
int boot = (bootable) ? ++n_opt : -1;
|
||||||
int script = (scriptable) ? ++n_opt : -1;
|
int script = (scriptable) ? ++n_opt : -1;
|
||||||
if (mount > 0) optionstr[mount-1] = "Mount image to drive";
|
if (mount > 0) optionstr[mount-1] = "Mount image to drive";
|
||||||
@ -1083,6 +1085,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, DirStruct* cur
|
|||||||
if (rename > 0) optionstr[rename-1] = "Rename file";
|
if (rename > 0) optionstr[rename-1] = "Rename file";
|
||||||
if (xorpad > 0) optionstr[xorpad-1] = "Build XORpads (SD output)";
|
if (xorpad > 0) optionstr[xorpad-1] = "Build XORpads (SD output)";
|
||||||
if (xorpad_inplace > 0) optionstr[xorpad_inplace-1] = "Build XORpads (inplace)";
|
if (xorpad_inplace > 0) optionstr[xorpad_inplace-1] = "Build XORpads (inplace)";
|
||||||
|
if (keyinit > 0) optionstr[keyinit-1] = "Init " KEYDB_NAME;
|
||||||
if (boot > 0) optionstr[boot-1] = "Boot FIRM";
|
if (boot > 0) optionstr[boot-1] = "Boot FIRM";
|
||||||
if (script > 0) optionstr[script-1] = "Execute GM9 script";
|
if (script > 0) optionstr[script-1] = "Execute GM9 script";
|
||||||
|
|
||||||
@ -1417,6 +1420,10 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, DirStruct* cur
|
|||||||
(success) ? "completed" : "failed!");
|
(success) ? "completed" : "failed!");
|
||||||
GetDirContents(current_dir, current_path);
|
GetDirContents(current_dir, current_path);
|
||||||
return 0;
|
return 0;
|
||||||
|
} else if ((user_select == keyinit)) {
|
||||||
|
if (ShowPrompt(true, "Warning: Keys are not verified.\nContinue on your own risk?"))
|
||||||
|
ShowPrompt(false, "%s\nAESkeydb init %s", pathstr, (InitKeyDb(curr_entry->path) == 0) ? "success" : "failed");
|
||||||
|
return 0;
|
||||||
} else if ((user_select == boot)) {
|
} else if ((user_select == boot)) {
|
||||||
size_t firm_size = FileGetSize(curr_entry->path);
|
size_t firm_size = FileGetSize(curr_entry->path);
|
||||||
if (firm_size > TEMP_BUFFER_SIZE) {
|
if (firm_size > TEMP_BUFFER_SIZE) {
|
||||||
|
@ -171,7 +171,7 @@ bool InitNandCrypto(bool init_full)
|
|||||||
LoadKeyFromFile(NULL, 0x24, 'Y', NULL);
|
LoadKeyFromFile(NULL, 0x24, 'Y', NULL);
|
||||||
|
|
||||||
// part #5: FULL INIT
|
// part #5: FULL INIT
|
||||||
if (init_full) InitKeyDb();
|
if (init_full) InitKeyDb(NULL);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user