mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-22 20:06:40 +00:00
Simplify package1_get_encrypted_package1
This commit is contained in:
parent
34a658ce4c
commit
f84645e91f
1 changed files with 5 additions and 11 deletions
|
@ -86,25 +86,20 @@ size_t package1_get_tsec_fw(void **tsec_fw, const void *package1loader, size_t p
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t package1_get_encrypted_package1(package1_header_t **package1, uint8_t *ctr, const void *package1loader, size_t package1loader_size) {
|
size_t package1_get_encrypted_package1(package1_header_t **package1, uint8_t *ctr, const void *package1loader, size_t package1loader_size) {
|
||||||
const uint32_t *pos;
|
const uint8_t *crypt_hdr = (const uint8_t *)package1loader + 0x4000 - 0x20;
|
||||||
uintptr_t pk1l = (uintptr_t)package1loader;
|
|
||||||
|
|
||||||
if (package1loader_size < 0x4000) {
|
if (package1loader_size < 0x4000) {
|
||||||
return 0; /* Shouldn't happen, ever. */
|
return 0; /* Shouldn't happen, ever. */
|
||||||
}
|
}
|
||||||
|
|
||||||
for (pos = (const uint32_t *)pk1l; (uintptr_t)pos < pk1l + 0x3FF8 && (pos[0] != 0x70012000 || pos[2] != 0x40007000); pos++);
|
memcpy(ctr, crypt_hdr + 0x10, 0x10);
|
||||||
pos = (const uint32_t *)(pk1l + pos[1] - 0x40010000);
|
(*package1) = (package1_header_t *)(crypt_hdr + 0x20);
|
||||||
|
return *(uint32_t *)crypt_hdr;
|
||||||
memcpy(ctr, pos + 4, 0x10);
|
|
||||||
(*package1) = (package1_header_t *)(pos + 8);
|
|
||||||
return *pos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool package1_decrypt(package1_header_t *package1, size_t package1_size, const uint8_t *ctr) {
|
bool package1_decrypt(package1_header_t *package1, size_t package1_size, const uint8_t *ctr) {
|
||||||
uint8_t __attribute__((aligned(16))) ctrbuf[16];
|
uint8_t __attribute__((aligned(16))) ctrbuf[16];
|
||||||
memcpy(ctrbuf, ctr, 16);
|
memcpy(ctrbuf, ctr, 16);
|
||||||
se_aes_ctr_crypt(0xB, package1, package1_size, package1, package1_size, ctr, 16);
|
se_aes_ctr_crypt(0xB, package1, package1_size, package1, package1_size, ctrbuf, 16);
|
||||||
return memcmp(package1->magic, "PK11", 4) == 0;
|
return memcmp(package1->magic, "PK11", 4) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +114,6 @@ void *package1_get_warmboot_fw(const package1_header_t *package1) {
|
||||||
Nx-bootloader seems to always start by 0xE328F0C0 (msr cpsr_f, 0xc0).
|
Nx-bootloader seems to always start by 0xE328F0C0 (msr cpsr_f, 0xc0).
|
||||||
*/
|
*/
|
||||||
const uint32_t *data = (const uint32_t *)package1->data;
|
const uint32_t *data = (const uint32_t *)package1->data;
|
||||||
|
|
||||||
for (size_t i = 0; i < 3; i++) {
|
for (size_t i = 0; i < 3; i++) {
|
||||||
switch (*data) {
|
switch (*data) {
|
||||||
case 0xD5034FDFu:
|
case 0xD5034FDFu:
|
||||||
|
|
Loading…
Reference in a new issue