]> Chaos Git - corbenik/corbenik.git/commitdiff
Remove all the hexdump implementations all over the place and use a common one
authorchaoskagami <chaos.kagami@gmail.com>
Thu, 9 Jun 2016 17:54:41 +0000 (13:54 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Thu, 9 Jun 2016 17:54:41 +0000 (13:54 -0400)
external/loader/source/patcher.c
source/interp.c
source/patch_format.h

index 883ebf936b4494ba1db2ff4723141f25fb1b6b5c..8682de02f246c117ce6d006d91b78a2f1383a489 100644 (file)
 #endif
 #include "../../../source/config.h"
 
-#define CODE_PATH PATH_EXEFS "/0000000000000000"
+#define CODE_PATH PATH_EXEFS  "/0000000000000000"
+#define LANG_PATH PATH_LOCEMU "/0000000000000000"
 
-static const char hexDigits[] = "0123456789ABCDEF";
+const char hexDigits[] = "0123456789ABCDEF";
 
 int
 fileOpen(Handle *file, FS_ArchiveID id, const char *path, int flags)
@@ -77,6 +78,15 @@ load_config()
     return;
 }
 
+void
+hexdump_titleid(u64 progId, char* buf) {
+    u32 i = strlen(buf) - 1;
+    while (progId) {
+        buf[i--] = hexDigits[(u32)(progId & 0xF)];
+        progId >>= 4;
+    }
+}
+
 static int
 loadTitleLocaleConfig(u64 progId, u8 *regionId, u8 *languageId)
 {
@@ -100,12 +110,8 @@ loadTitleLocaleConfig(u64 progId, u8 *regionId, u8 *languageId)
 
     // This really does need a rewrite.
 
-    char path[] = "/corbenik/locale/0000000000000000";
-    u32 i = 32;
-    while (progId) {
-        path[i--] = hexDigits[(u32)(progId & 0xF)];
-        progId >>= 4;
-    }
+    char path[] = LANG_PATH;
+       hexdump_titleid(progId, path);
 
     static const char *regions[] = { "JPN", "USA", "EUR", "AUS", "CHN", "KOR", "TWN" };
     static const char *languages[] = { "JA", "EN", "FR", "DE", "IT", "ES", "ZH", "KO", "NL", "PT", "RU", "TW" };
@@ -328,13 +334,9 @@ sd_code(u64 progId, u8 *code_loc, u32 code_len)
     u32 highTid = progId >> 0x20;
 
     char code_path[] = CODE_PATH;
-    u32 i = strlen(code_path) - 1;
     Handle code_f;
 
-    while (progId) {
-        code_path[i--] = hexDigits[(u32)(progId & 0xF)];
-        progId >>= 4;
-    }
+       hexdump_titleid(progId, code_path);
 
     u32 len;
 
index 21b940762c9e246fff361970f758c3228c8b548e..3ae139578abf998605e7c0c120a35be5186250b3 100644 (file)
@@ -57,6 +57,7 @@ int init_bytecode = 0;
 
 #ifndef LOADER
 extern int is_n3ds;
+static const char hexDigits[] = "0123456789ABCDEF";
 #else
 int is_n3ds = 1; // TODO - We don't really need to care, but it should still work from loader
 #endif
@@ -395,6 +396,8 @@ exec_bytecode(uint8_t *bytecode, uint16_t ver, uint32_t len, int debug)
     return 0;
 }
 
+void hexdump_titleid(uint64_t tid, char* path);
+
 #ifdef LOADER
 int
 execb(uint64_t tid, uint16_t ver, uint8_t *text_mem, uint32_t text_len, uint8_t *data_mem, uint32_t data_len, uint8_t *ro_mem, uint32_t ro_len)
@@ -408,14 +411,8 @@ execb(char *filename, int build_cache)
     uint32_t patch_len;
 #ifdef LOADER
     char cache_path[] = PATH_LOADER_CACHE "/0000000000000000";
-    int len = strlen(cache_path) - 16;
-
-    uint8_t *title_buf = (uint8_t *)&tid;
 
-    for (int j = 0; j < 8; j++) {
-        cache_path[len + (j * 2)] = ("0123456789ABCDEF")[(title_buf[j] >> 4) & 0x0f];
-        cache_path[len + (j * 2) + 1] = ("0123456789ABCDEF")[title_buf[j] & 0x0f];
-    }
+       hexdump_titleid(tid, cache_path);
 
     static uint8_t patch_dat[MAX_PATCHSIZE];
 
@@ -511,13 +508,13 @@ execb(char *filename, int build_cache)
             fprintf(stderr, "patch: %s\n", patch->name);
 
             for (uint32_t i = 0; i < patch->titles; i++, title_buf += 8) {
-                // FIXME - This is outputting once per boot. We need to detect and nuke the cache.
                 char cache_path[] = PATH_LOADER_CACHE "/0000000000000000";
-                int len = strlen(cache_path) - 16;
 
-                for (int j = 0; j < 8; j++) {
-                    cache_path[len + (j * 2)] = ("0123456789ABCDEF")[(title_buf[j] >> 4) & 0x0f];
-                    cache_path[len + (j * 2) + 1] = ("0123456789ABCDEF")[title_buf[j] & 0x0f];
+                uint32_t len = strlen(cache_path) - 1;
+                               uint64_t prog = *(uint64_t*)title_buf;
+                while (prog) {
+                    title_buf[i--] = hexDigits[(uint32_t)(prog & 0xF)];
+                    prog >>= 4;
                 }
 
                 fprintf(stderr, "  cache: %s\n", &cache_path[len]);
@@ -533,7 +530,6 @@ execb(char *filename, int build_cache)
             }
         } else {
             // BOOT patch
-            // FIXME - This is outputting once per boot. We need to detect and nuke the cache.
             char cache_path[] = PATH_LOADER_CACHE "/BOOT";
             char reset = 0xFF;
 
index d39e39fef64812f6d3aa9afeaba96ca61aade873..afe96468d0873981c4df8d99b4bd11bb561fd2f4 100644 (file)
@@ -32,7 +32,7 @@
 
 #define PATH_CONFIG_DIR PATH_CFW "/config"          // Config file directory.
 #define PATH_CONFIG PATH_CONFIG_DIR "/main.conf"    // Config file.
-#define PATH_LOCEMU PATH_CONFIG_DIR "/langemu.conf" // Locale emulation config
+#define PATH_LOCEMU PATH_CONFIG_DIR "/locale" // Locale emulation config
 #define PATH_CPU_CFG PATH_CONFIG_DIR "/cpu.conf"    // CPU settings config
 
 #define PATH_PATCHES PATH_CFW "/patch"      // Patch binary folder.
@@ -49,7 +49,8 @@
 
 #define PATH_KEYS PATH_CFW "/keys" // Keyfiles will be loaded from this dir, and
                                    // additionally the root if not found.
-#define PATH_EXEFS PATH_CFW "/exe" // ExeFS overrides, named like '<titleid>.exefs' - NYI
+
+#define PATH_EXEFS PATH_CFW "/exe" // ExeFS overrides, named by titleid
 
 #define PATH_BITS PATH_CFW "/bits" // Path to misc bits we need (emunand code, reboot code, etc)
 
 #define PATH_TWL_FIRMKEY PATH_KEYS "/twl.key"
 #define PATH_AGB_FIRMKEY PATH_KEYS "/agb.key"
 
-// These are used with O3DS units. Keep in mind I have no way to test this.
-#define PATH_NATIVE_FIRMKEY_2 PATH_KEYS "/native_old.key"
-#define PATH_TWL_FIRMKEY_2 PATH_KEYS "/twl_old.key"
-#define PATH_AGB_FIRMKEY_2 PATH_KEYS "/agb_old.key"
-
 #define PATH_SLOT0X11KEY96 PATH_KEYS "/11.key"
 
 #define PATH_ALT_SLOT0X11KEY96 "/slot0x11key96.bin" // Hey, your perrogative, buddy. I like cleaned up