]> Chaos Git - corbenik/corbenik.git/commitdiff
Shuffle stuff around to allow working on it in abscense of external patches
authorroot <chaos.kagami@gmail.com>
Tue, 17 May 2016 04:20:22 +0000 (00:20 -0400)
committerroot <chaos.kagami@gmail.com>
Tue, 17 May 2016 04:20:22 +0000 (00:20 -0400)
Makefile
copy.sh
source/firm/firm.c
source/main.c
source/patch/prot.c [new file with mode: 0644]
source/patch/sig.c [new file with mode: 0644]
source/patcher.c

index 5344ae6757d576932ffade7bd420025872927273..c71c9a3bebf4c531a326d77f5d5ae8fb24da79e0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -85,4 +85,13 @@ $(dir_build)/firm/%.o: $(dir_source)/firm/%.s
        @mkdir -p "$(@D)"
        $(COMPILE.s) -mthumb -mthumb-interwork $(OUTPUT_OPTION) $<
 
+
+$(dir_build)/patch/%.o: $(dir_source)/patch/%.c
+       @mkdir -p "$(@D)"
+       $(COMPILE.c) -mthumb -mthumb-interwork -Wno-unused-function $(OUTPUT_OPTION) $<
+
+$(dir_build)/patch/%.o: $(dir_source)/patch/%.s
+       @mkdir -p "$(@D)"
+       $(COMPILE.s) -mthumb -mthumb-interwork $(OUTPUT_OPTION) $<
+
 include $(call rwildcard, $(dir_build), *.d)
diff --git a/copy.sh b/copy.sh
index 4cb3f7f71603b287ad4969faac26bd45479358be..7e26056332f896582af10c82eee14cf73397dbac 100644 (file)
--- a/copy.sh
+++ b/copy.sh
@@ -1,6 +1,7 @@
 #!/bin/bash
 mount /dev/sdb1 /media/cd || exit 0
 cp out/arm9loaderhax.bin /media/cd/anim/boot/a.bin || exit 0
+cp out/arm9loaderhax.bin /media/cd/anim/boot/r.bin || exit 0
 cp -r out/corbenik /media/cd/ || exit 0
 umount /media/cd || exit 0
 eject /dev/sdb || exit 0
index 1e66922f25331fe8167a79b35ee25efccb0554db..0d930a50a696f10ca2f0f5764e70e3ae407c357b 100644 (file)
@@ -244,6 +244,8 @@ void __attribute__((naked)) disable_lcds() {
     ((void (*)())*a11_entry)();
 }
 
+extern void wait();
+
 void boot_firm() {
     // Set up the keys needed to boot a few firmwares, due to them being unset, depending on which firmware you're booting from.
     // TODO: Don't use the hardcoded offset.
@@ -270,12 +272,14 @@ void boot_firm() {
     }
     fprintf(BOTTOM_SCREEN, "Copied FIRM\n");
 
+       wait();
+
+       // No fprintf will work from here on out.
+
     *a11_entry = (uint32_t)disable_lcds;
     while (*a11_entry);  // Make sure it jumped there correctly before changing it.
     *a11_entry = (uint32_t)firm_loc->a11Entry;
 
-    fprintf(BOTTOM_SCREEN, "Prepared arm11 entry, jumping to FIRM\n");
-
     ((void (*)())firm_loc->a9Entry)();
 }
 
index e0ea618d8612dca2b297f6e41a7f35a34842c6ae..33843bf7f505b6ab95f90896d8ec6f1956daa405 100644 (file)
@@ -1,11 +1,15 @@
 #include "common.h"
 #include "firm/firm.h"
+#include "input.h"
+#include "config.h"
 
 void init_system() {
 }
 
 int menu_handler();
 
+int doing_autoboot = 0;
+
 int main() {
     if (fmount()) {
         // Failed to mount SD. Bomb out.
@@ -18,6 +22,12 @@ int main() {
 
     load_firms();
 
+       // Autoboot, and not R?
+       if (config.options[OPTION_AUTOBOOT] && !(HID_PAD & BUTTON_R)) {
+               doing_autoboot = 1;
+               boot_cfw(); // Just boot shit.
+       }
+
     int in_menu = 1;
 
     while(in_menu) {
diff --git a/source/patch/prot.c b/source/patch/prot.c
new file mode 100644 (file)
index 0000000..76e92cc
--- /dev/null
@@ -0,0 +1,40 @@
+#include <stdint.h>
+#include "../std/unused.h"
+#include "../std/memory.h"
+#include "../firm/firm.h"
+#include "../config.h"
+#include "../common.h"
+
+int patch_firmprot() {
+       uint8_t *firm_mem = (uint8_t*)firm_p9_exefs + sizeof(exefs_h) + firm_p9_exefs->fileHeaders[0].offset;
+       uint32_t size = firm_p9_exefs->fileHeaders[0].size;
+
+    // We look for 'exe:' first; this string is close to what we patch
+    uint8_t* off = memfind(firm_mem, size, (uint8_t*)"exe:", 4);
+
+       if(off == NULL) {
+               fprintf(stderr, "Couldn't find 'exe:' string.\n");
+               return 1;
+       }
+
+       fprintf(stderr, "Firmprot: 'exe:' string @ %x\n", (uint32_t)off);
+
+    uint8_t pattern[] = {0x00, 0x28, 0x01, 0xDA};
+
+    uint8_t* firmprot = memfind(off - 0x100, 0x100, pattern, 4);
+
+       if(firmprot == NULL) {
+               fprintf(stderr, "Couldn't find firmprot code.\n");
+               return 2;
+       }
+
+       fprintf(stderr, "Firmprot: %x\n", (uint32_t)firmprot);
+
+       uint8_t patch[] = {0x00, 0x20, 0xC0, 0x46};
+       memcpy(firmprot, patch, 4);
+
+       fprintf(stderr, "Applied firmprot patch.\n");
+
+       return 0;
+}
+
diff --git a/source/patch/sig.c b/source/patch/sig.c
new file mode 100644 (file)
index 0000000..3d0adbd
--- /dev/null
@@ -0,0 +1,47 @@
+#include <stdint.h>
+#include "../std/unused.h"
+#include "../std/memory.h"
+#include "../firm/firm.h"
+#include "../config.h"
+#include "../common.h"
+
+int patch_signatures() {
+    //Look for signature checks
+
+       uint8_t pat1[] = {0xC0, 0x1C, 0x76, 0xE7};
+       uint8_t pat2[] = {0xB5, 0x22, 0x4D, 0x0C};
+
+       // The code segment.
+       uint8_t *firm_mem = (uint8_t*)firm_p9_exefs + sizeof(exefs_h) + firm_p9_exefs->fileHeaders[0].offset;
+       uint32_t size = firm_p9_exefs->fileHeaders[0].size;
+
+    uint8_t *off  = memfind(firm_mem, size, pat1, 4);
+
+       // We're subbing one because the code goes back 1.
+       // Unique patterns, etc.
+    uint8_t *off2 = memfind(firm_mem, size, pat2, 4) - 1;
+
+       if (off == NULL) {
+               fprintf(stderr, "Signature patch failed on P0.\n");
+               return 1; // Failed to find sigpatch. Ugh.
+       }
+
+       if (off2 == NULL) {
+               fprintf(stderr, "Signature patch failed on P1.\n");
+               return 2; // Failed to find sigpatch. Ugh.
+       }
+
+       fprintf(stderr, "Signatures[0]: 0x%x\n", (uint32_t)off);
+       fprintf(stderr, "Signatures[1]: 0x%x\n", (uint32_t)off2);
+
+       // See asm/sigpatches.s for the code here
+       uint8_t sigpatch[] = {0x00, 0x20, 0x70, 0x47};
+
+       memcpy(off,  sigpatch, 2);
+       memcpy(off2, sigpatch, 4);
+
+       fprintf(stderr, "Signature patch succeded.\n");
+
+       return 0;
+}
+
index 7e383944259d40b3bbd50a17b136876d291eaba0..0527051b2da0803bff8d2ae960f1fc537fb2bcd6 100644 (file)
@@ -10,6 +10,9 @@
 uint32_t wait_key();
 int execp(char* path);
 
+extern int patch_signatures();
+extern int patch_firmprot();
+
 // A portion of this file is inherited from Luma3DS.
 /*u32 getLoader(u8 *pos, u32 *loaderSize) {
     u8 *off = pos;
@@ -28,81 +31,10 @@ int execp(char* path);
 }
 */
 
-/* int patch_signatures() {
-    //Look for signature checks
-
-       uint8_t pat1[] = {0xC0, 0x1C, 0x76, 0xE7};
-       uint8_t pat2[] = {0xB5, 0x22, 0x4D, 0x0C};
-
-       // The code segment.
-       uint8_t *firm_mem = (uint8_t*)firm_p9_exefs + sizeof(exefs_h) + firm_p9_exefs->fileHeaders[0].offset;
-       uint32_t size = firm_p9_exefs->fileHeaders[0].size;
-
-    uint8_t *off  = memfind(firm_mem, size, pat1, 4);
-
-       // We're subbing one because the code goes back 1.
-       // Unique patterns, etc.
-    uint8_t *off2 = memfind(firm_mem, size, pat2, 4) - 1;
-
-       if (off == NULL) {
-               fprintf(stderr, "Signature patch failed on P0.\n");
-               return 1; // Failed to find sigpatch. Ugh.
-       }
-
-       if (off2 == NULL) {
-               fprintf(stderr, "Signature patch failed on P1.\n");
-               return 2; // Failed to find sigpatch. Ugh.
-       }
-
-       fprintf(stderr, "Signatures[0]: 0x%x\n", (uint32_t)off);
-       fprintf(stderr, "Signatures[1]: 0x%x\n", (uint32_t)off2);
-
-       // See asm/sigpatches.s for the code here
-       uint8_t sigpatch[] = {0x00, 0x20, 0x70, 0x47};
-
-       memcpy(off,  sigpatch, 2);
-       memcpy(off2, sigpatch, 4);
-
-       fprintf(stderr, "Signature patch succeded.\n");
-
-       return 0;
-} */
-
-int patch_firmprot() {
-       uint8_t *firm_mem = (uint8_t*)firm_p9_exefs + sizeof(exefs_h) + firm_p9_exefs->fileHeaders[0].offset;
-       uint32_t size = firm_p9_exefs->fileHeaders[0].size;
-
-    // We look for 'exe:' first; this string is close to what we patch
-    uint8_t* off = memfind(firm_mem, size, (uint8_t*)"exe:", 4);
-
-       if(off == NULL) {
-               fprintf(stderr, "Couldn't find 'exe:' string.\n");
-               return 1;
-       }
-
-       fprintf(stderr, "Firmprot: 'exe:' string @ %x\n", (uint32_t)off);
-
-    uint8_t pattern[] = {0x00, 0x28, 0x01, 0xDA};
-
-    uint8_t* firmprot = memfind(off - 0x100, 0x100, pattern, 4);
-
-       if(firmprot == NULL) {
-               fprintf(stderr, "Couldn't find firmprot code.\n");
-               return 2;
-       }
-
-       fprintf(stderr, "Firmprot: %x\n", (uint32_t)firmprot);
-
-       uint8_t patch[] = {0x00, 0x20, 0xC0, 0x46};
-       memcpy(firmprot, patch, 4);
-
-       fprintf(stderr, "Applied firmprot patch.\n");
-
-       return 0;
-}
+extern int doing_autoboot;
 
 void wait() {
-       if (config.options[OPTION_TRACE]) {
+       if (config.options[OPTION_TRACE] && !doing_autoboot) {
                fprintf(stderr, "[press key]\n");
                wait_key();
        }
@@ -110,9 +42,9 @@ void wait() {
 
 int patch_firm_all() {
        // FIXME - Linker is bork at the moment.
-       execp(PATH_PATCHES "/example.vco");
+//     execp(PATH_PATCHES "/example.vco");
 
-       wait();
+//     wait();
 
        // Use builtin signature patcher?
 
@@ -124,7 +56,8 @@ int patch_firm_all() {
 
        if (config.options[OPTION_SIGPATCH]) {
                // TODO - Patch menu. This is okay-ish for now.
-               if(execp(PATH_PATCHES "/signatures.vco")) {
+//             if(execp(PATH_PATCHES "/signatures.vco")) {
+               if(patch_signatures()) {
                        abort("Fatal. Sigpatch has failed.");
                }
        }