]> Chaos Git - corbenik/corbenik.git/commitdiff
Cleanup, fixes
authorchaoskagami <chaos.kagami@gmail.com>
Tue, 10 Jan 2017 13:21:23 +0000 (08:21 -0500)
committerchaoskagami <chaos.kagami@gmail.com>
Tue, 10 Jan 2017 13:21:59 +0000 (08:21 -0500)
Brought langemu up to the assembly hacks in use in Luma3DS. Currently going through and figuring out how to go and clean up the codebase more.

external/loader/source/interp.c
external/loader/source/logger.c
external/loader/source/memory.c
external/loader/source/patcher.c
include/common.h
include/structures.h [moved from include/patch_format.h with 100% similarity]

index b71564927bf0430551d6cc9bd7171d4ef639cc8b..bf30558f538c35005361f2ec2cf61fe459285671 100644 (file)
@@ -13,7 +13,7 @@
 #define _MAX_LFN 255
 #endif
 #include <option.h>
-#include <patch_format.h>
+#include <structures.h>
 
 // Yes, we're including a C file. Problem?
 #include "../../../source/interpreter.c"
index 6bc389697193f980040cbfb61e2b826968e308c8..14c6d8a8dc38f2bbff0e5f7e039909ea145c94bb 100644 (file)
@@ -10,7 +10,7 @@
 #define _MAX_LFN 255
 #endif
 #include <option.h>
-#include <patch_format.h>
+#include <structures.h>
 
 Handle log_file_hdl;
 int logger_is_initd = 0;
index a6dcccde33dee3a0586dfb28baa4b404ba82411b..2434af6e2489989b9b5f08eb056903eddb6c7cac 100644 (file)
@@ -8,7 +8,7 @@
 #define _MAX_LFN 255
 #endif
 #include <option.h>
-#include <patch_format.h>
+#include <structures.h>
 
 // Quick Search algorithm, adapted from
 // http://igm.univ-mlv.fr/~lecroq/string/node19.html#SECTION00190
index 37abb035d5243e6c064cf1e83e3e9e6d92bf78c4..4032f225e086609cd071c234d353e870ee6b743d 100644 (file)
@@ -6,7 +6,7 @@
 #include <string.h>
 #include "memory.h"
 #include "logger.h"
-#include <patch_format.h>
+#include <structures.h>
 #include <std/unused.h>
 #include "interp.h"
 
@@ -195,6 +195,9 @@ getCfgOffsets(uint8_t *code, uint32_t size, uint32_t *CFGUHandleOffset)
         }
     }
 
+    if(!n)
+        return NULL;
+
     for (uint8_t *CFGU_GetConfigInfoBlk2_endPos = code; CFGU_GetConfigInfoBlk2_endPos < code + size - 8; CFGU_GetConfigInfoBlk2_endPos += 4) {
         static const uint32_t CFGU_GetConfigInfoBlk2_endPattern[] = { 0xE8BD8010, 0x00010082 };
 
@@ -206,7 +209,7 @@ getCfgOffsets(uint8_t *code, uint32_t size, uint32_t *CFGUHandleOffset)
             *CFGUHandleOffset = *((uint32_t *)CFGU_GetConfigInfoBlk2_endPos + 2);
 
             for (uint32_t i = 0; i < n; i++)
-                if (possible[i] == *CFGUHandleOffset)
+                if (possible[i] == cmp[2])
                     return CFGU_GetConfigInfoBlk2_endPos;
 
             CFGU_GetConfigInfoBlk2_endPos += 4;
@@ -242,24 +245,18 @@ patchCfgGetLanguage(uint8_t *code, uint32_t size, uint8_t languageId, uint8_t *C
 
                         calledFunction += offset;
 
-                        found = calledFunction >= CFGU_GetConfigInfoBlk2_startPos - 4 && calledFunction <= CFGU_GetConfigInfoBlk2_endPos;
-                        i++;
-                    } while (i < 2 && !found && calledFunction[3] == 0xEA);
-
-                    if (found) {
-                        *((uint32_t *)instr - 1) = 0xE3A00000 | languageId; // mov    r0, sp
-                                                                       // => mov r0, =languageId
-                        *(uint32_t *)instr = 0xE5CD0000;                    // bl
-                        // CFGU_GetConfigInfoBlk2 =>
-                        // strb r0, [sp]
-                        *((uint32_t *)instr + 1) = 0xE3B00000; // (1 or 2 instructions)         => movs
-                                                          // r0, 0             (result code)
+                        if(calledFunction >= CFGU_GetConfigInfoBlk2_startPos - 4 && calledFunction <= CFGU_GetConfigInfoBlk2_endPos) {
+                            *((uint32_t *)instr - 1) = 0xE3A00000 | languageId; // mov    r0, sp => mov r0, =languageId
+                            *(uint32_t *)instr = 0xE5CD0000; // bl CFGU_GetConfigInfoBlk2 => strb r0, [sp]
+                            *((uint32_t *)instr + 1) = 0xE3B00000; // (1 or 2 instructions)         => movs r0, 0             (result code)
 
-                        logstr("  patched cfggetlanguage\n");
+                            logstr("  patched cfggetlanguage\n");
 
-                        // We're done
-                        return;
-                    }
+                            // We're done
+                            return;
+                        }
+                        i++;
+                    } while (i < 2 && !found && calledFunction[3] == 0xEA);
                 }
             }
         }
@@ -270,16 +267,16 @@ static void
 patchCfgGetRegion(uint8_t *code, uint32_t size, uint8_t regionId, uint32_t CFGUHandleOffset)
 {
     for (uint8_t *cmdPos = code; cmdPos < code + size - 28; cmdPos += 4) {
-        static const uint32_t cfgSecureInfoGetRegionCmdPattern[] = { 0xEE1D4F70, 0xE3A00802, 0xE5A40080 };
+        static const uint32_t cfgSecureInfoGetRegionCmdPattern[] = { 0xEE1D4F70, 0xE3A00802 };
 
         uint32_t *cmp = (uint32_t *)cmdPos;
 
-        if (cmp[0] == cfgSecureInfoGetRegionCmdPattern[0] && cmp[1] == cfgSecureInfoGetRegionCmdPattern[1] && cmp[2] == cfgSecureInfoGetRegionCmdPattern[2] &&
+        if (cmp[0] == cfgSecureInfoGetRegionCmdPattern[0] && cmp[1] == cfgSecureInfoGetRegionCmdPattern[1] &&
             *((uint16_t *)cmdPos + 7) == 0xE59F && *(uint32_t *)(cmdPos + 20 + *((uint16_t *)cmdPos + 6)) == CFGUHandleOffset) {
+
             *((uint32_t *)cmdPos + 4) = 0xE3A00000 | regionId; // mov    r0, =regionId
             *((uint32_t *)cmdPos + 5) = 0xE5C40008;            // strb   r0, [r4, 8]
-            *((uint32_t *)cmdPos + 6) = 0xE3B00000;            // movs   r0, 0            (result
-                                                          // code) ('s' not needed but nvm)
+            *((uint32_t *)cmdPos + 6) = 0xE3A00000;            // mov    r0, 0            (result code)
             *((uint32_t *)cmdPos + 7) = 0xE5840004;            // str    r0, [r4, 4]
 
             // The remaining, not patched, function code will do the rest for us
index 1b2940b9f09c89a1d31a599b8be63a6fb9662905..e698971c5d37ea046818499dfa42433be8e2ded1 100644 (file)
@@ -11,7 +11,7 @@
 
 #include <std/types.h>
 
-#include <patch_format.h>
+#include <structures.h>
 
 #include <std/memory.h>
 #include <std/fs.h>
similarity index 100%
rename from include/patch_format.h
rename to include/structures.h