From 3a68eed391c6b55cc295aa054f1b43161ae21f77 Mon Sep 17 00:00:00 2001 From: chaoskagami Date: Thu, 2 Jun 2016 06:50:22 -0400 Subject: [PATCH] Since the patcher VM works now, rewrite known functional patches to be stubs (until we can dynamically load em) --- .gitignore | 2 +- patch/aadowngrade.pco | 2 ++ patch/block_cart_update.pco | 2 ++ patch/block_eshop_update.pco | 2 ++ patch/block_nim_update.pco | 2 ++ patch/errdisp.pco | 2 ++ patch/friends_ver.pco | 2 ++ patch/memexec.pco | 2 ++ patch/mset_str.pco | 2 ++ patch/prot.pco | 2 ++ patch/regionfree.pco | 2 ++ patch/ro_sigs.pco | 2 ++ patch/secinfo_sigs.pco | 2 ++ patch/sig.pco | 2 ++ patch/unitinfo.pco | 2 ++ source/patch/aadowngrade.c | 26 ++----------------- source/patch/base.c | 10 -------- source/patch/prot.c | 41 +----------------------------- source/patch/sig.c | 49 ------------------------------------ 19 files changed, 32 insertions(+), 124 deletions(-) delete mode 100644 source/patch/base.c diff --git a/.gitignore b/.gitignore index c199e7e..ca27f50 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,6 @@ build *.o *.d *.elf -*.bat +*.vco input modules/template/src/symtab.h diff --git a/patch/aadowngrade.pco b/patch/aadowngrade.pco index 9439f10..6fb4f71 100644 --- a/patch/aadowngrade.pco +++ b/patch/aadowngrade.pco @@ -4,6 +4,8 @@ # $uuid 00 # $flags require +# Status: Working + # Anti-anti-downgrade fix. # Relative to process9. diff --git a/patch/block_cart_update.pco b/patch/block_cart_update.pco index 305e5b0..50e4279 100644 --- a/patch/block_cart_update.pco +++ b/patch/block_cart_update.pco @@ -4,6 +4,8 @@ # $ver 01 # $uuid 01 +# Status: needs loader + find 0C18E1D8 set 0B1821C8 diff --git a/patch/block_eshop_update.pco b/patch/block_eshop_update.pco index 1cd18c2..303c357 100644 --- a/patch/block_eshop_update.pco +++ b/patch/block_eshop_update.pco @@ -4,5 +4,7 @@ # $ver 01 # $uuid 02 +# Status: needs loader + find 30B5F1B0 set 002008607047 diff --git a/patch/block_nim_update.pco b/patch/block_nim_update.pco index 19ecfce..f81587d 100644 --- a/patch/block_nim_update.pco +++ b/patch/block_nim_update.pco @@ -4,5 +4,7 @@ # $ver 01 # $uuid 03 +# Status: needs loader + find 25790B99 set E3A0 diff --git a/patch/errdisp.pco b/patch/errdisp.pco index 227bb90..37e357d 100644 --- a/patch/errdisp.pco +++ b/patch/errdisp.pco @@ -5,6 +5,8 @@ # $uuid 04 # $flags devmode +# Status: needs loader + find 1400D0E5DB9A9FED set 0000A0E3 diff --git a/patch/friends_ver.pco b/patch/friends_ver.pco index 42e8e6f..942afc8 100644 --- a/patch/friends_ver.pco +++ b/patch/friends_ver.pco @@ -5,6 +5,8 @@ # $uuid 05 # $flags noabort +# Status: needs loader + find E01EFF2FE1010101 fwd 09 set 06 diff --git a/patch/memexec.pco b/patch/memexec.pco index d863359..6226e98 100644 --- a/patch/memexec.pco +++ b/patch/memexec.pco @@ -4,6 +4,8 @@ # $uuid 06 # $flags devmode +# Status: needs assembler to be fixed + # Relative to NATIVE_FIRM, section index [1] rel native_s1 diff --git a/patch/mset_str.pco b/patch/mset_str.pco index a3f2219..a1b3bb3 100644 --- a/patch/mset_str.pco +++ b/patch/mset_str.pco @@ -4,6 +4,8 @@ # $ver 01 # $uuid 07 +# Status: needs loader + # u"Ver." find 5600650072002e00 diff --git a/patch/prot.pco b/patch/prot.pco index 065520a..61b4ae0 100644 --- a/patch/prot.pco +++ b/patch/prot.pco @@ -4,6 +4,8 @@ # $uuid 08 # $flags require +# Status: Working + rel native_p9 # String: 'exe:' find 6578653a diff --git a/patch/regionfree.pco b/patch/regionfree.pco index 35e297e..25f3e73 100644 --- a/patch/regionfree.pco +++ b/patch/regionfree.pco @@ -4,6 +4,8 @@ # $ver 01 # $uuid 09 +# Status: needs loader + find 000055E30110A0E3 # 16 back 11 diff --git a/patch/ro_sigs.pco b/patch/ro_sigs.pco index 47f0f68..69f2831 100644 --- a/patch/ro_sigs.pco +++ b/patch/ro_sigs.pco @@ -4,6 +4,8 @@ # $ver 01 # $uuid 0a +# Status: needs loader + find 30402DE90250A0E1 set 0000A0E31EFF2FE1 diff --git a/patch/secinfo_sigs.pco b/patch/secinfo_sigs.pco index 12a3dfe..6fe262e 100644 --- a/patch/secinfo_sigs.pco +++ b/patch/secinfo_sigs.pco @@ -4,5 +4,7 @@ # $ver 01 # $uuid 0b +# Status: needs loader + find 06461048FC set 0026 diff --git a/patch/sig.pco b/patch/sig.pco index b952980..0a8fc23 100644 --- a/patch/sig.pco +++ b/patch/sig.pco @@ -4,6 +4,8 @@ # $uuid 0c # $flags require +# Status: Working + # Signature patch. # Relative to exefs. diff --git a/patch/unitinfo.pco b/patch/unitinfo.pco index 7b9b40c..4738101 100644 --- a/patch/unitinfo.pco +++ b/patch/unitinfo.pco @@ -4,6 +4,8 @@ # $uuid 0d # $flags devmode +# Status: untested, but should work + rel native_s2 find 0110A013 fwd 03 diff --git a/source/patch/aadowngrade.c b/source/patch/aadowngrade.c index e4d9e41..f7aa638 100644 --- a/source/patch/aadowngrade.c +++ b/source/patch/aadowngrade.c @@ -1,30 +1,8 @@ #include "patch_file.h" -/* - rel p9_exefs - find 6, 0x89, 0x0a, 0x81, 0x42, 0x02, 0xD2 - fwd 5 - set 1, 0xE0 - */ - -extern exefs_h* firm_p9_exefs; - PATCH(aadowngrade) { - 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; - - const uint8_t pattern[] = {0x89, 0x0A, 0x81, 0x42, 0x02, 0xD2}; - - uint8_t *off = memfind(firm_mem, size, pattern, 6); - - if(off == NULL) - return 1; // Not found. - - fprintf(stderr, "aadowngrade: %x\n", (uint32_t)off); - - off[5] = 0xE0; + execb(PATH_PATCHES "/aadowngrade.vco"); - return 0; + return 0; } diff --git a/source/patch/base.c b/source/patch/base.c deleted file mode 100644 index 847740a..0000000 --- a/source/patch/base.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "patch_file.h" - -// Do you like examples? - -PATCH(example) -{ - fprintf(stderr, "Testing, testing, 1, 2, 3, 4..\n"); - - return 0; -} diff --git a/source/patch/prot.c b/source/patch/prot.c index 544c7f9..47ebcf3 100644 --- a/source/patch/prot.c +++ b/source/patch/prot.c @@ -2,48 +2,9 @@ // This patch applies the FIRM protection code needed for safe a9lh usage. -/* - rel p9_exefs - find 4, "exe:" - back 0x1 - back 0xff - find 4, 0x00, 0x28, 0x01, 0xDA - set 4, 0x00, 0x20, 0xC0, 0x46 - */ - -extern exefs_h* firm_p9_exefs; - 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"); + execb(PATH_PATCHES "/prot.vco"); return 0; } diff --git a/source/patch/sig.c b/source/patch/sig.c index fda935c..dbc46e5 100644 --- a/source/patch/sig.c +++ b/source/patch/sig.c @@ -2,57 +2,8 @@ // This patch is responsible for fixing signature checks for the firmware. -/* - rel p9_exefs - find 4, 0xc0, 0x1c, 0x76, 0xe7 - set 2, 0x00, 0x20 - rewind - find 4, 0xb5, 0x22, 0x4d, 0x0c - set 4, 0x00, 0x20, 0x70, 0x47 - */ - -extern exefs_h* firm_p9_exefs; - 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"); -*/ execb(PATH_PATCHES "/sig.vco"); return 0; -- 2.39.5