]> Chaos Git - corbenik/corbenik.git/commitdiff
More changes and code restructure. Just the usual, etc.
authorchaoskagami <chaos.kagami@gmail.com>
Thu, 19 May 2016 22:22:33 +0000 (18:22 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Thu, 19 May 2016 22:22:33 +0000 (18:22 -0400)
13 files changed:
doc/todo.md [new file with mode: 0644]
external/loader/source/patcher.c
external/service/Makefile
external/service/stub.s [new file with mode: 0644]
source/linker.c
source/patch/base.c
source/patch/prot.c
source/patch/sig.c
source/patch/svc.c
vco/signatures/src/link_table.s [deleted symlink]
vco/template/linker.ld
vco/template/src/link_table.s [deleted file]
vco/template/src/start.s

diff --git a/doc/todo.md b/doc/todo.md
new file mode 100644 (file)
index 0000000..751b634
--- /dev/null
@@ -0,0 +1 @@
+ * Attempt to create a replacement handler for Service 0x3D, AKA OutputDebugString(void const, int) to log to a file on SD.
index 272ea5e6c12e85695d6d6c86d03eca50e1ae21c1..d6794015a21a0388bc982291fb5839821775c0d9 100644 (file)
@@ -559,7 +559,7 @@ void patch_text(u64 progId, u8 *text, u32 size, u32 orig_size) {
         case 0x0004013000008002LL: // NS
         {
                        disable_cart_updates(progId, text, orig_size);
-                       adjust_cpu_settings(progId, text, orig_size); // DEFAULT cpu settings that are inherited system-wide. Per-app is handled in default.
+                       adjust_cpu_settings(progId, text, orig_size);
             break;
         }
 
index b390e7296b2a84526284356487a38b099b0eee2e..3e2acda3198eb33910bb380b81c2c516ed7f8d0c 100644 (file)
@@ -1,6 +1,6 @@
 PATH := $(PATH):$(DEVKITARM)/bin
 
-all: 7b.bin
+all: 7b.bin stub.bin
 
 %.o: %.s
        arm-none-eabi-as -o $@ $<
diff --git a/external/service/stub.s b/external/service/stub.s
new file mode 100644 (file)
index 0000000..7706777
--- /dev/null
@@ -0,0 +1,6 @@
+// This is not intended to be built, but is what a stub service's code is
+.section .text
+.global _start
+_start:
+       ldr r0, =0xf8c007f4
+       bx lr
index 4ec769e5d43b9f80ac617df8028a912e57e38e5d..af13c1978eeeaf99dda1f40c1fcfb7fb9850350a 100644 (file)
@@ -2,50 +2,30 @@
 #include "firm/fcram.h"
 #include "firm/firm.h"
 
-extern void flush_cache();
-
-extern firm_h *firm_loc;
-extern exefs_h *firm_p9_exefs;
-
-extern firm_h *twl_firm_loc;
-extern exefs_h *twl_firm_p9_exefs;
+// Yes, this is EXACTLY what it looks like. We dynamically link and
+// load patches as binaries; they use functions from corbenik to do
+// the work, and therefore must have a function table in them.
 
-extern firm_h *agb_firm_loc;
-extern exefs_h *agb_firm_p9_exefs;
+// See vco/template for how this magic works.
 
-firm_h* __attribute__((optimize("O0"))) get_firm() {
-       return firm_loc;
-}
+// This ensures relatively small patches while also having incredible
+// flexibility unlike a 'patch format'.
 
-exefs_h* __attribute__((optimize("O0"))) get_firm_proc9_exefs() {
+extern exefs_h* firm_p9_exefs;
+exefs_h* get_firm_proc9_exefs() {
        return firm_p9_exefs;
 }
 
-firm_h* __attribute__((optimize("O0"))) get_agb() {
-       return agb_firm_loc;
+extern exefs_h* twl_firm_p9_exefs;
+exefs_h* get_twl_proc9_exefs() {
+       return twl_firm_p9_exefs;
 }
 
-exefs_h* __attribute__((optimize("O0"))) get_agb_proc9_exefs() {
+extern exefs_h* agb_firm_p9_exefs;
+exefs_h* get_agb_proc9_exefs() {
        return agb_firm_p9_exefs;
 }
 
-firm_h* __attribute__((optimize("O0"))) get_twl() {
-       return twl_firm_loc;
-}
-
-exefs_h* __attribute__((optimize("O0"))) get_twl_proc9_exefs() {
-       return twl_firm_p9_exefs;
-}
-
-// Yes, this is EXACTLY what it looks like. We dynamically link and
-// load patches as binaries; they use functions from corbenik to do
-// the work, and therefore must have a function table in them.
-
-// See vco/template for how this magic works.
-
-// This ensures relatively small patches while also having incredible
-// flexibility unlike a 'patch format'.
-
 int execp(char* path) {
        int basename = 0;
        for(basename=strlen(path); basename > 0; basename--)
@@ -53,7 +33,7 @@ int execp(char* path) {
                        break;
        basename++;
 
-       fprintf(stderr, "Executing patchbin: %s\n", &path[basename]);
+       fprintf(stderr, "Exec: %s\n", &path[basename]);
 
        struct system_patch patch;
 
@@ -70,14 +50,8 @@ int execp(char* path) {
        fclose(f);
 
        fprintf(stderr, "[s]");
-       // Now then...find the magical number.
-       uint8_t magic[] = { 0xc0, 0x9b, 0xe5, 0x1c };
-       uint32_t* link_table = (uint32_t*)memfind((uint8_t*)FCRAM_PATCHBIN_EXEC_LOC, patch.patch_size, magic, 4);
 
-       if (link_table == NULL) {
-               fprintf(stderr, "\n Table missing. Abort.\n");
-               return 1;
-       }
+       uint32_t* link_table = (uint32_t*)(FCRAM_PATCHBIN_EXEC_LOC+4);
 
        fprintf(stderr, "[r]");
 
@@ -101,14 +75,11 @@ int execp(char* path) {
        link_table[26] = (uint32_t)fprintf;
 
        // Get functions
-       link_table[28] = (uint32_t)get_firm;
-       link_table[30] = (uint32_t)get_firm_proc9_exefs;
+       link_table[28] = (uint32_t)get_firm_proc9_exefs;
 
-       link_table[32] = (uint32_t)get_agb;
-       link_table[34] = (uint32_t)get_agb_proc9_exefs;
+       link_table[30] = (uint32_t)get_agb_proc9_exefs;
 
-       link_table[36] = (uint32_t)get_twl;
-       link_table[38] = (uint32_t)get_twl_proc9_exefs;
+       link_table[32] = (uint32_t)get_twl_proc9_exefs;
 
        fprintf(stderr, "[b]\n");
 
index fd12e795d575723b02d30dbfc101dcce525f792f..68a35fdd0a1e7812fdeb231e47448ade86509acb 100644 (file)
@@ -5,6 +5,8 @@
 #include "../config.h"
 #include "../common.h"
 
+// Do you like examples?
+
 int patch_test() {
        fprintf(stderr, "Testing, testing, 1, 2, 3, 4..\n");
 
index 76e92cc298fdc6d81a5f62b1a94fb197af9a9e82..f5acd7437433baaed2b44009c655ebd88408ab03 100644 (file)
@@ -5,6 +5,8 @@
 #include "../config.h"
 #include "../common.h"
 
+// This patch applies the FIRM protection code needed for safe a9lh usage.
+
 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;
index 3d0adbd1b6d8913bf6a4c2a40705413ad6061fb8..85ef9480143f45a6c20e0f17a8d8862a11f77653 100644 (file)
@@ -5,6 +5,8 @@
 #include "../config.h"
 #include "../common.h"
 
+// This patch is responsible for fixing signature checks for the firmware.
+
 int patch_signatures() {
     //Look for signature checks
 
index 661a4beaf0cdaeea60457e56b8d987639c1c1900..ed2060d21625dfda919adc6936b1c8e06a3585c4 100644 (file)
@@ -5,6 +5,11 @@
 #include "../config.h"
 #include "../common.h"
 
+// This patch handles replacement of services. This includes backdoor, but not just backdoor.
+// Any service can be replaced provided there's enough space within the exception page.
+
+// Please note that the actual code for services is in `external/service`.
+
 uint32_t *getSvcAndExceptions(uint8_t *pos, uint32_t size, uint32_t **exceptionsPage) {
     uint8_t pattern[] = {0x00, 0xB0, 0x9C, 0xE5}; //cpsid aif
 
diff --git a/vco/signatures/src/link_table.s b/vco/signatures/src/link_table.s
deleted file mode 120000 (symlink)
index 501d0b2..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../../template/src/link_table.s
\ No newline at end of file
index 7d6129bad20a2d9173336ab4d55d3ead037c3fe3..0a7a3ade4ffcf3e0ae26e2b6cab0200a9f9ff91a 100644 (file)
@@ -1,19 +1,3 @@
-/* This memory map is mainly to assist in doing stuff in code.
-MEMORY
-{
-    INSTRUCTION_TCM  (rw)   : ORIGIN = 0x00000000, LENGTH = 0x08000000
-    ARM_INTERNAL     (rw)  : ORIGIN = 0x08000000, LENGTH = 0x00100000
-    NEW_INTERNAL     (rw)  : ORIGIN = 0x08100000, LENGTH = 0x00080000
-    IO_MEMORY        (rw)  : ORIGIN = 0x10000000, LENGTH = 0x08000000
-    VRAM             (rw)  : ORIGIN = 0x18000000, LENGTH = 0x00600000
-    DSP_MEMORY       (rw)  : ORIGIN = 0x1FF00000, LENGTH = 0x00080000
-    AXI_WRAM         (rw)  : ORIGIN = 0x1FF80000, LENGTH = 0x00080000
-    FCRAM            (rwx) : ORIGIN = 0x20000000, LENGTH = 0x08000000
-    NEW_FCRAM        (rwx) : ORIGIN = 0x28000000, LENGTH = 0x08000000
-    DATA_TCM         (rw)  : ORIGIN = 0xFFF00000, LENGTH = 0x00004000
-    BOOTROM          (rw)   : ORIGIN = 0xFFFF0000, LENGTH = 0x00010000
-} */
-
 ENTRY(_start)
 SECTIONS
 {
@@ -25,12 +9,6 @@ SECTIONS
       }
     START_SECTION_END = .;
 
-    TABLE_SECTION = .;
-      .text.table : {
-          *(.text.table)
-      }
-    TABLE_SECTION_END = .;
-
     TEXT_SECTION = .;
       .text : {
           *(.text)
diff --git a/vco/template/src/link_table.s b/vco/template/src/link_table.s
deleted file mode 100644 (file)
index 0c459b5..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-.section .text.table
-.align 4
-
-.macro stub name
-       .global \name
-       \name :
-               ldr pc, [pc, #-4] // Load the data after this to the PC. return will be before this call.
-               bx lr // Fall through in case of error.
-.endm
-
-// (int) [0]
-.global MAGIC_START
-MAGIC_START:
-       .byte 0xc0
-       .byte 0x9b
-       .byte 0xe5
-       .byte 0x1c
-
-// Exported functions.
-
-// memory.c
-// (int) [3]
-stub strlen
-// (int) [5]
-stub isprint
-// (int) [7]
-stub memcpy
-// (int) [9]
-stub memmove
-// (int) [11]
-stub memset
-// (int) [13]
-stub memcmp
-// (int) [15]
-stub strncpy
-// (int) [17]
-stub strncmp
-// (int) [19]
-stub atoi
-// (int) [21]
-stub memfind
-
-// draw.c
-// (int) [23]
-stub putc
-// (int) [25]
-stub puts
-// (int) [27]
-stub fprintf
-
-// Wrappers to get shit.
-
-// Gets NATIVE_FIRM memory offset as (firm_h*)
-stub get_firm
-
-// Get NATIVE_FIRM process9
-stub get_firm_proc9_exefs
-
-// Gets AGB_FIRM.
-stub get_agb
-
-// Get AGB_FIRM process9 exefs
-stub get_agb_proc9_exefs
-
-// Gets TWL_FIRM.
-stub get_twl
-
-// Get TWL_FIRM process9 exefs
-stub get_twl_proc9_exefs
index 441e530d1982de61d072c1a2036d4393ddaf16fe..5898ae64c835701a3923cb386fd23fea2f7582e6 100644 (file)
@@ -3,5 +3,38 @@
 .global _start
 _start:
        b main
-_die:
-       b _die // I have no clue how one would end up here.
+
+.macro stub name
+       .global \name
+       \name :
+               ldr pc, [pc, #-4] // Load the data after this to the PC. return will be before this call.
+               bx lr // Fall through in case of error.
+.endm
+
+// memory.c
+stub strlen
+stub isprint
+stub memcpy
+stub memmove
+stub memset
+stub memcmp
+stub strncpy
+stub strncmp
+stub atoi
+stub memfind
+
+// draw.c
+stub putc
+stub puts
+stub fprintf
+
+// Wrappers to get shit.
+
+// Get NATIVE_FIRM process9
+stub get_firm_proc9_exefs
+
+// Get AGB_FIRM process9 exefs
+stub get_agb_proc9_exefs
+
+// Get TWL_FIRM process9 exefs
+stub get_twl_proc9_exefs