From: root Date: Tue, 17 May 2016 04:20:22 +0000 (-0400) Subject: Shuffle stuff around to allow working on it in abscense of external patches X-Git-Tag: stable-1~73 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=63fdc3fdd1e3664f582f54da090065b0f4d9cc51;p=corbenik%2Fcorbenik.git Shuffle stuff around to allow working on it in abscense of external patches --- diff --git a/Makefile b/Makefile index 5344ae6..c71c9a3 100644 --- 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 4cb3f7f..7e26056 100644 --- 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 diff --git a/source/firm/firm.c b/source/firm/firm.c index 1e66922..0d930a5 100644 --- a/source/firm/firm.c +++ b/source/firm/firm.c @@ -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)(); } diff --git a/source/main.c b/source/main.c index e0ea618..33843bf 100644 --- a/source/main.c +++ b/source/main.c @@ -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 index 0000000..76e92cc --- /dev/null +++ b/source/patch/prot.c @@ -0,0 +1,40 @@ +#include +#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 index 0000000..3d0adbd --- /dev/null +++ b/source/patch/sig.c @@ -0,0 +1,47 @@ +#include +#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; +} + diff --git a/source/patcher.c b/source/patcher.c index 7e38394..0527051 100644 --- a/source/patcher.c +++ b/source/patcher.c @@ -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."); } }