1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-05 19:51:45 +00:00

Skeleton out framework for patching package2.

This commit is contained in:
Michael Scire 2018-04-11 18:19:01 -06:00
parent 3c24bfdb79
commit a0d2642bb1
3 changed files with 88 additions and 0 deletions

View file

@ -1,6 +1,7 @@
#include "utils.h" #include "utils.h"
#include "nxboot.h" #include "nxboot.h"
#include "key_derivation.h" #include "key_derivation.h"
#include "package2.h"
#include "loader.h" #include "loader.h"
#include "splash_screen.h" #include "splash_screen.h"
#include "exocfg.h" #include "exocfg.h"
@ -58,6 +59,9 @@ void nxboot_main(void) {
/* Derive keydata. */ /* Derive keydata. */
derive_nx_keydata(MAILBOX_EXOSPHERE_CONFIGURATION->target_firmware); derive_nx_keydata(MAILBOX_EXOSPHERE_CONFIGURATION->target_firmware);
/* Patch package2, adding thermosphere + custom KIPs. */
package2_patch((void *)loader_ctx->package2_loadfile.load_address);
/* Boot up Exosphere. */ /* Boot up Exosphere. */
MAILBOX_NX_BOOTLOADER_IS_SECMON_AWAKE = 0; MAILBOX_NX_BOOTLOADER_IS_SECMON_AWAKE = 0;
if (MAILBOX_EXOSPHERE_CONFIGURATION->target_firmware <= EXOSPHERE_TARGET_FIRMWARE_400) { if (MAILBOX_EXOSPHERE_CONFIGURATION->target_firmware <= EXOSPHERE_TARGET_FIRMWARE_400) {

View file

@ -0,0 +1,47 @@
#include "utils.h"
#include "package2.h"
#include "se.h"
void package2_decrypt(void *package2_address);
void package2_add_thermosphere_section(void *package2_address);
void package2_patch_kernel(void *package2_address);
void package2_patch_ini1(void *package2_address);
void package2_fixup_header_and_section_hashes(void *package2_address);
void package2_patch(void *package2_address) {
/* First things first: Decrypt (TODO: Relocate?) Package2. */
package2_decrypt(package2_address);
/* Modify Package2 to add an additional thermosphere section. */
package2_add_thermosphere_section(package2_address);
/* Perform any patches we want to the NX kernel. */
package2_patch_kernel(package2_address);
/* Perform any patches we want to the INI1 (This is where our built-in sysmodules will be added.) */
package2_patch_ini1(package2_address);
/* Fix all necessary data in the header to accomodate for the new patches. */
package2_fixup_header_and_section_hashes(package2_address);
}
void package2_decrypt(void *package2_address) {
/* TODO */
}
void package2_add_thermosphere_section(void *package2_address) {
/* TODO */
}
void package2_patch_kernel(void *package2_address) {
/* TODO */
}
void package2_patch_ini1(void *package2_address) {
/* TODO */
}
void package2_fixup_header_and_section_hashes(void *package2_address) {
/* TODO */
}

View file

@ -0,0 +1,37 @@
#ifndef FUSEE_PACKAGE2_H
#define FUSEE_PACKAGE2_H
/* This is a library for patching Package2 prior to handoff to Exosphere. */
#define MAGIC_PK21 (0x31324B50)
#define PACKAGE2_SIZE_MAX 0x7FC000
#define PACKAGE2_SECTION_MAX 0x3
typedef struct {
union {
uint8_t ctr[0x10];
uint32_t ctr_dwords[0x4];
};
uint8_t section_ctrs[4][0x10];
uint32_t magic;
uint32_t entrypoint;
uint32_t _0x58;
uint8_t version_max; /* Must be > TZ value. */
uint8_t version_min; /* Must be < TZ value. */
uint16_t _0x5E;
uint32_t section_sizes[4];
uint32_t section_offsets[4];
uint8_t section_hashes[4][0x20];
} package2_meta_t;
typedef struct {
uint8_t signature[0x100];
union {
package2_meta_t metadata;
uint8_t encrypted_header[0x100];
};
} package2_header_t;
void package2_patch(void *package2_address);
#endif