From 6f056849c508ad1ac0f326ad4db32a64214ad0e3 Mon Sep 17 00:00:00 2001 From: chaoskagami Date: Sat, 1 Oct 2016 12:35:15 -0400 Subject: [PATCH] Loader: use malloc for patches --- external/loader/source/interp.c | 9 +-------- source/interpreter.c | 16 ++++++++++------ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/external/loader/source/interp.c b/external/loader/source/interp.c index 28bc338..890555c 100644 --- a/external/loader/source/interp.c +++ b/external/loader/source/interp.c @@ -2,6 +2,7 @@ // I don't want to delete it since I'm working on it though, // so it's temporarliy #if'd 0. #include <3ds.h> +#include #include "patcher.h" #include "exheader.h" #include "fsldr.h" @@ -16,14 +17,6 @@ #include #include -// Patches must consist of fewer bytes than this. -// 16K is reasonable, IMO, and doesn't cause issues. - -// I'm too lazy to implement file buffering here, -// and 16K is large enough for anything. - -#define MAX_PATCHSIZE 16384 - // Yes, we're including a C file. Problem? #include "../../../source/interpreter.c" diff --git a/source/interpreter.c b/source/interpreter.c index 2d99329..82dda65 100644 --- a/source/interpreter.c +++ b/source/interpreter.c @@ -509,7 +509,7 @@ execb(uint64_t tid, firm_h* firm_patch) hexdump_titleid(tid, cache_path); - static uint8_t patch_dat[MAX_PATCHSIZE]; + static uint8_t *patch_mem; Handle file; u32 total; @@ -532,8 +532,9 @@ execb(uint64_t tid, firm_h* firm_patch) return 1; } - if (file_size > MAX_PATCHSIZE) { - log(" too large (please report)\n"); + patch_mem = malloc(file_size); + if (patch_mem == NULL) { + log(" out of memory on loading patch\n"); FSFILE_Close(file); // Read to memory. @@ -541,7 +542,7 @@ execb(uint64_t tid, firm_h* firm_patch) } // Read file. - if (!R_SUCCEEDED(FSFILE_Read(file, &total, 0, patch_dat, file_size))) { + if (!R_SUCCEEDED(FSFILE_Read(file, &total, 0, patch_mem, file_size))) { FSFILE_Close(file); // Read to memory. // Failed to read. @@ -564,7 +565,6 @@ execb(uint64_t tid, firm_h* firm_patch) log(" exec\n"); - uint8_t *patch_mem = (uint8_t *)patch_dat; patch_len = file_size; #else // The WHOLE firm. @@ -624,7 +624,11 @@ execb(uint64_t tid, firm_h* firm_patch) debug = 1; } - return exec_bytecode(patch_mem, patch_len, ver, debug); + int r = exec_bytecode(patch_mem, patch_len, ver, debug); + + free(patch_mem); + + return r; } #ifndef LOADER -- 2.39.5