1
0
Fork 0
mirror of https://github.com/Scandal-UK/Incognito_RCM.git synced 2024-11-08 05:01:45 +00:00

Fixed issue with backups

This commit is contained in:
Dan Ware 2020-12-23 13:58:36 +00:00
parent 35d58f0694
commit 4722199e17
3 changed files with 51 additions and 48 deletions

View file

@ -355,9 +355,12 @@ bool dump_keys()
emummc_storage_set_mmc_partition(&storage, EMMC_GPP); emummc_storage_set_mmc_partition(&storage, EMMC_GPP);
// Parse eMMC GPT. // Parse eMMC GPT.
LIST_INIT(gpt);
nx_emmc_gpt_parse(&gpt, &storage); nx_emmc_gpt_parse(&gpt, &storage);
se_aes_key_set(8, bis_key[0] + 0x00, 0x10);
se_aes_key_set(9, bis_key[0] + 0x10, 0x10);
// Find PRODINFO partition. // Find PRODINFO partition.
prodinfo_part = nx_emmc_part_find(&gpt, "PRODINFO"); prodinfo_part = nx_emmc_part_find(&gpt, "PRODINFO");
if (!prodinfo_part) if (!prodinfo_part)
@ -366,10 +369,8 @@ bool dump_keys()
return false; return false;
} }
se_aes_key_set(8, bis_key[0] + 0x00, 0x10);
se_aes_key_set(9, bis_key[0] + 0x10, 0x10);
gfx_printf("%kGot keys!\n%kValidate...", COLOR_GREEN, COLOR_YELLOW); gfx_printf("%kGot keys!\n%kValidate...", COLOR_GREEN, COLOR_YELLOW);
const char magic[4] = "CAL0"; const char magic[4] = "CAL0";
char buffer[4]; char buffer[4];
readData((u8 *)buffer, 0, 4, NULL); readData((u8 *)buffer, 0, 4, NULL);

View file

@ -26,11 +26,11 @@ static inline void _gf256_mul_x_le(void *block)
pdata[0x0] ^= 0x87; pdata[0x0] ^= 0x87;
} }
static int _nx_aes_xts_crypt_sec(u32 tweak_ks, u32 crypt_ks, u32 enc, u8 *tweak, bool regen_tweak, u32 tweak_exp, u32 sec, void *dst, const void *src, u32 sec_size) static inline int _emmc_xts(u32 ks1, u32 ks2, u32 enc, u8 *tweak, bool regen_tweak, u32 tweak_exp, u64 sec, void *dst, void *src, u32 secsize)
{ {
u32 *pdst = (u32 *)dst; int res = 0;
u32 *psrc = (u32 *)src; u8 *pdst = (u8 *)dst;
u32 *ptweak = (u32 *)tweak; u8 *psrc = (u8 *)src;
if (regen_tweak) if (regen_tweak)
{ {
@ -39,43 +39,43 @@ static int _nx_aes_xts_crypt_sec(u32 tweak_ks, u32 crypt_ks, u32 enc, u8 *tweak,
tweak[i] = sec & 0xFF; tweak[i] = sec & 0xFF;
sec >>= 8; sec >>= 8;
} }
if (!se_aes_crypt_block_ecb(tweak_ks, 1, tweak, tweak)) if (!se_aes_crypt_block_ecb(ks1, 1, tweak, tweak))
return 0; goto out;
} }
// tweak_exp allows us to use a saved tweak to reduce _gf256_mul_x_le calls. for (u32 i = 0; i < tweak_exp * 0x20; i++)
for (u32 i = 0; i < (tweak_exp << 5); i++)
_gf256_mul_x_le(tweak); _gf256_mul_x_le(tweak);
u8 orig_tweak[0x10]; u8 temptweak[0x10];
memcpy(orig_tweak, tweak, 0x10); memcpy(temptweak, tweak, 0x10);
//We are assuming a 0x10-aligned sector size in this implementation. //We are assuming a 0x10-aligned sector size in this implementation.
for (u32 i = 0; i < (sec_size >> 4); i++) for (u32 i = 0; i < secsize / 0x10; i++)
{ {
for (u32 j = 0; j < 4; j++) for (u32 j = 0; j < 0x10; j++)
pdst[j] = psrc[j] ^ ptweak[j]; pdst[j] = psrc[j] ^ tweak[j];
_gf256_mul_x_le(tweak); _gf256_mul_x_le(tweak);
psrc += 4; psrc += 0x10;
pdst += 4; pdst += 0x10;
} }
if (!se_aes_crypt_ecb(crypt_ks, enc, dst, sec_size, dst, sec_size)) se_aes_crypt_ecb(ks2, enc, dst, secsize, src, secsize);
return 0;
pdst = (u32 *)dst; pdst = (u8 *)dst;
ptweak = (u32 *)orig_tweak;
for (u32 i = 0; i < (sec_size >> 4); i++) memcpy(tweak, temptweak, 0x10);
for (u32 i = 0; i < secsize / 0x10; i++)
{ {
for (u32 j = 0; j < 4; j++) for (u32 j = 0; j < 0x10; j++)
pdst[j] = pdst[j] ^ ptweak[j]; pdst[j] = pdst[j] ^ tweak[j];
_gf256_mul_x_le(tweak);
_gf256_mul_x_le(orig_tweak); pdst += 0x10;
pdst += 4;
} }
return 1; res = 1;
out:;
return res;
} }
// replacement for nx_emmc_part_write in storage/nx_emmc, which uses sdmmc_storage_write // replacement for nx_emmc_part_write in storage/nx_emmc, which uses sdmmc_storage_write
@ -100,7 +100,7 @@ bool prodinfo_read(
u32 tweak_exp = 0; u32 tweak_exp = 0;
bool regen_tweak = true; bool regen_tweak = true;
if (nx_emmc_part_read(&emmc_storage, prodinfo_part, sector, count, buff)) if (nx_emmc_part_read(&storage, prodinfo_part, sector, count, buff))
{ {
if (prev_cluster != sector / 0x20) if (prev_cluster != sector / 0x20)
{ // sector in different cluster than last read { // sector in different cluster than last read
@ -118,7 +118,7 @@ bool prodinfo_read(
} }
// fatfs will never pull more than a cluster // fatfs will never pull more than a cluster
result = _nx_aes_xts_crypt_sec(9, 8, 0, tweak, regen_tweak, tweak_exp, prev_cluster, buff, buff, count * 0x200); result = _emmc_xts(9, 8, 0, tweak, regen_tweak, tweak_exp, prev_cluster, buff, buff, count * 0x200);
prev_sector = sector + count - 1; prev_sector = sector + count - 1;
return result; return result;
@ -155,10 +155,10 @@ bool prodinfo_write(
} }
// fatfs will never pull more than a cluster // fatfs will never pull more than a cluster
if(!_nx_aes_xts_crypt_sec(9, 8, 1, tweak, regen_tweak, tweak_exp, prev_cluster, buff, buff, count * 0x200)){ if(!_emmc_xts(9, 8, 1, tweak, regen_tweak, tweak_exp, prev_cluster, buff, buff, count * 0x200)){
return false; return false;
} }
if (nx_emummc_part_write(&emmc_storage, prodinfo_part, sector, count, buff)) if (nx_emummc_part_write(&storage, prodinfo_part, sector, count, buff))
{ {
prev_sector = sector + count - 1; prev_sector = sector + count - 1;
return true; return true;

View file

@ -390,6 +390,8 @@ out:
void backup_sysnand() void backup_sysnand()
{ {
gfx_printf("\n%kBacking-up sysnand", COLOR_YELLOW);
h_cfg.emummc_force_disable = true; h_cfg.emummc_force_disable = true;
b_cfg.extra_cfg &= ~EXTRA_CFG_DUMP_EMUMMC; b_cfg.extra_cfg &= ~EXTRA_CFG_DUMP_EMUMMC;
if (!dump_keys()) if (!dump_keys())