From 79400db47a44201382e0b7bd2be3150e5d47687c Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sat, 18 Apr 2020 13:09:22 -0400 Subject: update patcher tool to support multiple definitions. --- tools/mwasmarm_patcher/mwasmarm_patcher.c | 70 ++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 14 deletions(-) (limited to 'tools') diff --git a/tools/mwasmarm_patcher/mwasmarm_patcher.c b/tools/mwasmarm_patcher/mwasmarm_patcher.c index 0d7470df..41271ae5 100644 --- a/tools/mwasmarm_patcher/mwasmarm_patcher.c +++ b/tools/mwasmarm_patcher/mwasmarm_patcher.c @@ -5,11 +5,49 @@ #include #include -// mwasmarm patcher v1.0 +// mwasmarm patcher v1.1 // Patches the Metrowerk C compiler assembler to stop the line ending bug. -char mwasmarm_unpatched_sha1[] = "9d63877c776245129b4727b41d3e9e63cfc9cd28"; -char mwasmarm_patched_sha1[] = "f5dea73bf90791e104cb59458bebae8b08a55484"; +// Changelog: +// v1.1: Added patch definitions and looped over them to find the matching +// definition as well as the version. + +struct PatchDef { + char *version; + char *sha1before; + char *sha1after; + int offsetPatch; + int newByte; +}; + +struct PatchDef gPatchDefs[] = { + // mwasmarm 1.2/base definition + { + "mwasmarm 1.2/base", + "87f942cc0a0e90e73550d8d6f3fffcdeb5f69fa5", + "2f1ccff22eaa443bb79235ca6477d3b86bdfd7e4", + 0x57614, + 0x5 + }, + // mwasmarm 2.0/base definition + { + "mwasmarm 2.0/base", + "9d63877c776245129b4727b41d3e9e63cfc9cd28", + "f5dea73bf90791e104cb59458bebae8b08a55484", + 0x57644, + 0x5 + }, + // mwasmarm 2.0/sp2p4 definition + { + "mwasmarm 2.0/sp2p4", + "448cb0c7f1ace4393e9a9562f819f7a9f049be83", + "c82161527277b991a1b77e14617a93bcd19cf95c", + 0x57834, + 0x5 + }, + { + } +}; void fatal_printf(char *str, ...) { va_list args; @@ -38,6 +76,7 @@ int main(int argc, char *argv[]) { if (argc != 2) { print_help(); + return 1; } else { // Open the file and sha1 read it. FILE *f = fopen(argv[1], "rb+"); @@ -47,24 +86,27 @@ int main(int argc, char *argv[]) { int fsize = get_file_size(f); char *string = malloc(fsize + 1); fread(string, 1, fsize, f); - + // Check if sha1 matches either known assembler hashes. SHA1(string, fsize, temp); for (int i=0; i < SHA_DIGEST_LENGTH; i++) { sprintf((char*)&(buf[i*2]), "%02x", temp[i]); } - - if(!strcmp(buf, mwasmarm_unpatched_sha1)) { - // Unpatched, perform the patch. - fseek(f, 0x57644, SEEK_SET); - fputc(0x05, f); - printf("Supported unpatched version detected: assembler patched\n"); - } else if(!strcmp(buf, mwasmarm_patched_sha1)) { - printf("Supported patched version detected: no action needed\n"); - } else { - fatal_printf("ERROR: Unsupported mwasmarm.exe version\n"); + + for(int i = 0; gPatchDefs[i].sha1before != NULL; i++) { + // check if already patched for the current loop. + if(!strcmp(buf, gPatchDefs[i].sha1after)) { + printf("Supported patched version detected (%s): no action needed\n", gPatchDefs[i].version); + return 0; + } else if(!strcmp(buf, gPatchDefs[i].sha1before)) { + fseek(f, gPatchDefs[i].offsetPatch, SEEK_SET); + fputc(gPatchDefs[i].newByte, f); + printf("Supported unpatched version detected (%s): assembler patched\n", gPatchDefs[i].version); + return 0; + } } + fatal_printf("ERROR: Unsupported mwasmarm.exe version\n"); } return 0; } -- cgit v1.2.3