[HOS] Fix pk2 decr after running 2nd time on 7.x+

This could happen after a pkg1/2 dump or a failed hos launch.

The 2nd time a dump or launch would be attempted, it would fail.
This commit is contained in:
ctcaer@gmail.com 2019-04-23 03:38:35 +03:00
parent 91606334c4
commit 6aa1bdd1c6
2 changed files with 11 additions and 6 deletions

View file

@ -91,7 +91,7 @@ void dump_packages12()
kb = pkg1_id->kb; kb = pkg1_id->kb;
if (!h_cfg.se_keygen_done || kb == KB_FIRMWARE_VERSION_620) if (!h_cfg.se_keygen_done)
{ {
tsec_ctxt.fw = (void *)pkg1 + pkg1_id->tsec_off; tsec_ctxt.fw = (void *)pkg1 + pkg1_id->tsec_off;
tsec_ctxt.pkg1 = (void *)pkg1; tsec_ctxt.pkg1 = (void *)pkg1;
@ -119,8 +119,8 @@ void dump_packages12()
// Decrypt. // Decrypt.
keygen(keyblob, kb, &tsec_ctxt); keygen(keyblob, kb, &tsec_ctxt);
if (kb <= KB_FIRMWARE_VERSION_600)
h_cfg.se_keygen_done = 1; h_cfg.se_keygen_done = 1;
free(keyblob); free(keyblob);
} }
@ -188,6 +188,11 @@ void dump_packages12()
pkg2_size_aligned / NX_EMMC_BLOCKSIZE, pkg2); pkg2_size_aligned / NX_EMMC_BLOCKSIZE, pkg2);
// Decrypt package2 and parse KIP1 blobs in INI1 section. // Decrypt package2 and parse KIP1 blobs in INI1 section.
pkg2_hdr_t *pkg2_hdr = pkg2_decrypt(pkg2); pkg2_hdr_t *pkg2_hdr = pkg2_decrypt(pkg2);
if (!pkg2_hdr)
{
gfx_printf("Pkg2 decryption failed!\n");
goto out;
}
// Display info. // Display info.
u32 kernel_crc32 = crc32c(pkg2_hdr->data, pkg2_hdr->sec_size[PKG2_SEC_KERNEL]); u32 kernel_crc32 = crc32c(pkg2_hdr->data, pkg2_hdr->sec_size[PKG2_SEC_KERNEL]);

View file

@ -415,7 +415,7 @@ int hos_launch(ini_sec_t *cfg)
gfx_printf("Loaded pkg1 & keyblob\n"); gfx_printf("Loaded pkg1 & keyblob\n");
// Generate keys. // Generate keys.
if (!h_cfg.se_keygen_done || ctxt.pkg1_id->kb == KB_FIRMWARE_VERSION_620) if (!h_cfg.se_keygen_done)
{ {
tsec_ctxt.fw = (u8 *)ctxt.pkg1 + ctxt.pkg1_id->tsec_off; tsec_ctxt.fw = (u8 *)ctxt.pkg1 + ctxt.pkg1_id->tsec_off;
tsec_ctxt.pkg1 = ctxt.pkg1; tsec_ctxt.pkg1 = ctxt.pkg1;
@ -431,8 +431,8 @@ int hos_launch(ini_sec_t *cfg)
if (!keygen(ctxt.keyblob, ctxt.pkg1_id->kb, &tsec_ctxt)) if (!keygen(ctxt.keyblob, ctxt.pkg1_id->kb, &tsec_ctxt))
return 0; return 0;
DPRINTF("Generated keys\n"); DPRINTF("Generated keys\n");
if (ctxt.pkg1_id->kb <= KB_FIRMWARE_VERSION_600)
h_cfg.se_keygen_done = 1; h_cfg.se_keygen_done = 1;
} }
// Decrypt and unpack package1 if we require parts of it. // Decrypt and unpack package1 if we require parts of it.