]> Chaos Git - corbenik/corbenik.git/commitdiff
Loader: use malloc for patches
authorchaoskagami <chaos.kagami@gmail.com>
Sat, 1 Oct 2016 16:35:15 +0000 (12:35 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Sat, 1 Oct 2016 16:35:15 +0000 (12:35 -0400)
external/loader/source/interp.c
source/interpreter.c

index 28bc33831024d770fa554968bc49747a0cdaeb70..890555c3e5be829fff18f127e8c3a64911c7fd79 100644 (file)
@@ -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 <stdlib.h>
 #include "patcher.h"
 #include "exheader.h"
 #include "fsldr.h"
 #include <option.h>
 #include <patch_format.h>
 
-// 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"
 
index 2d99329125760e43899ef290230a65939df6dd5c..82dda656d78f07a243c7be15f5318d59610bf4a3 100644 (file)
@@ -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