Fix bss overflow error

This commit is contained in:
TuxSH 2018-05-06 00:45:30 +02:00
parent 8648cac77b
commit 6e5d4b8fc9
2 changed files with 39 additions and 7 deletions

View File

@ -1,4 +1,5 @@
#include <stdio.h>
#include <stdlib.h>
#include "utils.h"
#include "masterkey.h"
#include "stratosphere.h"
@ -8,10 +9,10 @@
/* Stage 2 executes from DRAM, so we have tons of space. */
/* This *greatly* simplifies logic. */
unsigned char g_patched_package2[PACKAGE2_SIZE_MAX];
unsigned char g_package2_sections[PACKAGE2_SECTION_MAX][PACKAGE2_SIZE_MAX];
static uint8_t *g_patched_package2;
static uint8_t *g_package2_sections[PACKAGE2_SECTION_MAX];
package2_header_t *g_patched_package2_header = (package2_header_t *)g_patched_package2;
static package2_header_t *g_patched_package2_header;
void package2_decrypt(void *package2_address);
void package2_add_thermosphere_section(void);
@ -19,6 +20,23 @@ void package2_patch_kernel(void);
void package2_patch_ini1(void);
void package2_fixup_header_and_section_hashes(void);
void package2_allocate_mem(void) {
/* TODO: call it */
g_patched_package2 = (uint8_t *)malloc(PACKAGE2_SIZE_MAX);
for(size_t i = 0; i < PACKAGE2_SECTION_MAX; i++) {
g_package2_sections[i] = (uint8_t *)malloc(PACKAGE2_SIZE_MAX);
}
g_patched_package2_header = (package2_header_t *)g_patched_package2;
}
void package2_free_mem(void) {
free(g_patched_package2);
for(size_t i = 0; i < PACKAGE2_SECTION_MAX; i++) {
free(g_package2_sections[i]);
}
g_patched_package2_header = NULL;
}
void package2_patch(void *package2_address) {
/* First things first: Decrypt Package2. */
package2_decrypt(package2_address);
@ -36,7 +54,7 @@ void package2_patch(void *package2_address) {
package2_fixup_header_and_section_hashes();
/* Relocate Package2. */
memcpy(NX_BOOTLOADER_PACKAGE2_LOAD_ADDRESS, g_patched_package2, sizeof(g_patched_package2));
memcpy(NX_BOOTLOADER_PACKAGE2_LOAD_ADDRESS, g_patched_package2, PACKAGE2_SIZE_MAX);
}
static void package2_crypt_ctr(unsigned int master_key_rev, void *dst, size_t dst_size, const void *src, size_t src_size, const void *ctr, size_t ctr_size) {

View File

@ -1,13 +1,27 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "utils.h"
#include "package2.h"
#include "stratosphere.h"
#include "sd_utils.h"
unsigned char g_stratosphere_ini1[PACKAGE2_SIZE_MAX];
static uint8_t *g_stratosphere_ini1;
static bool g_initialized_stratosphere_ini1 = false;
unsigned char g_ini1_buffer[PACKAGE2_SIZE_MAX];
static uint8_t *g_ini1_buffer;
void stratosphere_allocate_mem(void) {
/* TODO call it*/
g_stratosphere_ini1 = (uint8_t *)malloc(PACKAGE2_SIZE_MAX);
g_ini1_buffer = (uint8_t *)malloc(PACKAGE2_SIZE_MAX);
}
void stratosphere_free_mem(void) {
/* TODO call it*/
free(g_stratosphere_ini1);
free(g_ini1_buffer);
}
ini1_header_t *stratosphere_get_ini1(void) {
ini1_header_t *ini1_header = (ini1_header_t *)g_stratosphere_ini1;
@ -38,7 +52,7 @@ size_t stratosphere_merge_inis(void *dst, ini1_header_t **inis, unsigned int num
uint64_t process_list[INI1_MAX_KIPS] = {0};
memset(g_ini1_buffer, 0, sizeof(g_ini1_buffer));
memset(g_ini1_buffer, 0, PACKAGE2_SIZE_MAX);
ini1_header_t *merged = (ini1_header_t *)g_ini1_buffer;
merged->magic = MAGIC_INI1;
merged->num_processes = 0;