@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)
#!/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
((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.
}
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)();
}
#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.
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) {
--- /dev/null
+#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;
+}
+
--- /dev/null
+#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;
+}
+
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;
}
*/
-/* 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();
}
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?
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.");
}
}