This commit is contained in:
d0k3 2019-11-04 23:44:11 +01:00
parent cfae228bcf
commit da412226be
2 changed files with 13 additions and 7 deletions

View File

@ -173,14 +173,17 @@ u32 SetupSecretKey(u32 keynum) {
if (keynum >= 0x200/0x10)
return 1; // safety
// try to load full secret sector or key from file
if (!(got_keys & (0x1<<keynum))) {
// try to load full secret sector
if (!got_keys) {
ReadNandSectors(sector, 0x96, 1, 0x11, NAND_SYSNAND);
if (ValidateSecretSector(sector) == 0) {
if (ValidateSecretSector(sector) == 0)
got_keys = 0xFFFFFFFF; // => got them all
} else if ((keynum < 2) && (LoadKeyFromFile(key, 0x11, 'N', (keynum == 0) ? "95" : "96"))) {
got_keys |= (0x1<<keynum); // got at least this one
}
}
// try to load key from file
if (!(got_keys & (0x1<<keynum)) && (keynum < 2)) {
if (LoadKeyFromFile(key, 0x11, 'N', (keynum == 0) ? "95" : "96") == 0)
got_keys |= (0x1<<keynum); // got at least this key
}
// setup the key

View File

@ -1037,7 +1037,8 @@ u32 DecryptFirmFile(const char* orig, const char* dest) {
void* firm_buffer = (void*) malloc(FIRM_MAX_SIZE);
if (!firm_buffer) return 1;
// load the whole FIRM into memory & decrypt it
// load the whole FIRM into memory & decrypt it
ShowProgress(0, 2, dest);
u32 firm_size = fvx_qsize(orig);
if ((firm_size > FIRM_MAX_SIZE) || (fvx_qread(orig, firm_buffer, 0, firm_size, NULL) != FR_OK) ||
(DecryptFirmFull(firm_buffer, firm_size) != 0)) {
@ -1050,11 +1051,13 @@ u32 DecryptFirmFile(const char* orig, const char* dest) {
memcpy(firm->dec_magic, dec_magic, sizeof(dec_magic));
// write decrypted FIRM to the destination file
ShowProgress(1, 2, dest);
if (fvx_qwrite(dest, firm_buffer, 0, firm_size, NULL) != FR_OK) {
free(firm_buffer);
return 1;
}
ShowProgress(2, 2, dest);
free(firm_buffer);
return 0;
}