fusee: Hook up kip/kernel patch support (needs testing).

This commit is contained in:
Michael Scire 2018-10-16 16:17:30 -07:00
parent b78a3f7065
commit 472059134a
4 changed files with 27 additions and 7 deletions

View file

@ -18,6 +18,7 @@
#include "utils.h" #include "utils.h"
#include "se.h" #include "se.h"
#include "kernel_patches.h" #include "kernel_patches.h"
#include "ips.h"
#define MAKE_BRANCH(a, o) 0x14000000 | ((((o) - (a)) >> 2) & 0x3FFFFFF) #define MAKE_BRANCH(a, o) 0x14000000 | ((((o) - (a)) >> 2) & 0x3FFFFFF)
@ -510,9 +511,13 @@ const kernel_info_t *get_kernel_info(void *kernel, size_t size) {
return NULL; return NULL;
} }
void package2_patch_kernel(void *_kernel, size_t size) { void package2_patch_kernel(void *_kernel, size_t size, bool is_sd_kernel) {
const kernel_info_t *kernel_info = get_kernel_info(_kernel, size); const kernel_info_t *kernel_info = get_kernel_info(_kernel, size);
if (kernel_info == NULL) {
/* Apply IPS patches. */
apply_kernel_ips_patches(_kernel, size);
if (kernel_info == NULL && !is_sd_kernel) {
/* Should this be fatal? */ /* Should this be fatal? */
fatal_error("kernel_patcher: unable to identify kernel!\n"); fatal_error("kernel_patcher: unable to identify kernel!\n");
} }

View file

@ -19,6 +19,6 @@
#include "utils.h" #include "utils.h"
void package2_patch_kernel(void *kernel, size_t kernel_size); void package2_patch_kernel(void *kernel, size_t kernel_size, bool is_sd_kernel);
#endif #endif

View file

@ -23,6 +23,7 @@
#include "kernel_patches.h" #include "kernel_patches.h"
#include "kip.h" #include "kip.h"
#include "se.h" #include "se.h"
#include "fs_utils.h"
#define u8 uint8_t #define u8 uint8_t
#define u32 uint32_t #define u32 uint32_t
@ -47,6 +48,7 @@ void package2_rebuild_and_copy(package2_header_t *package2, uint32_t target_firm
size_t rebuilt_package2_size; size_t rebuilt_package2_size;
void *kernel; void *kernel;
size_t kernel_size; size_t kernel_size;
bool is_sd_kernel = false;
void *thermosphere; void *thermosphere;
size_t thermosphere_size; size_t thermosphere_size;
ini1_header_t *orig_ini1, *rebuilt_ini1; ini1_header_t *orig_ini1, *rebuilt_ini1;
@ -79,11 +81,12 @@ void package2_rebuild_and_copy(package2_header_t *package2, uint32_t target_firm
fatal_error("Error: failed to read atmosphere/kernel.bin!\n"); fatal_error("Error: failed to read atmosphere/kernel.bin!\n");
} }
kernel_size = sd_kernel_size; kernel_size = sd_kernel_size;
is_sd_kernel = true;
} }
} }
/* Perform any patches we want to the NX kernel. */ /* Perform any patches we want to the NX kernel. */
package2_patch_kernel(kernel, kernel_size); package2_patch_kernel(kernel, kernel_size, is_sd_kernel);
print(SCREEN_LOG_LEVEL_DEBUG, "Rebuilding the INI1 section...\n"); print(SCREEN_LOG_LEVEL_DEBUG, "Rebuilding the INI1 section...\n");
package2_get_src_section((void *)&orig_ini1, package2, PACKAGE2_SECTION_INI1); package2_get_src_section((void *)&orig_ini1, package2, PACKAGE2_SECTION_INI1);

View file

@ -23,6 +23,7 @@
#include "package2.h" #include "package2.h"
#include "stratosphere.h" #include "stratosphere.h"
#include "fs_utils.h" #include "fs_utils.h"
#include "ips.h"
#include "lib/log.h" #include "lib/log.h"
#define u8 uint8_t #define u8 uint8_t
@ -300,9 +301,20 @@ ini1_header_t *stratosphere_merge_inis(ini1_header_t **inis, size_t num_inis) {
if (current_kip_size > remaining_size) { if (current_kip_size > remaining_size) {
fatal_error("Not enough space for all the KIP1s!\n"); fatal_error("Not enough space for all the KIP1s!\n");
} }
memcpy(current_dst_kip, current_kip, current_kip_size);
remaining_size -= current_kip_size; kip1_header_t *patched_kip = apply_kip_ips_patches(current_kip, current_kip_size);
current_dst_kip += current_kip_size; if (patched_kip != NULL) {
size_t patched_kip_size = kip1_get_size_from_header(patched_kip);
memcpy(current_dst_kip, patched_kip, patched_kip_size);
remaining_size -= patched_kip_size;
current_dst_kip += patched_kip_size;
free(patched_kip);
} else {
memcpy(current_dst_kip, current_kip, current_kip_size);
remaining_size -= current_kip_size;
current_dst_kip += current_kip_size;
}
process_list[merged->num_processes++] = current_kip->title_id; process_list[merged->num_processes++] = current_kip->title_id;
} }