]> Chaos Git - corbenik/corbenik.git/commitdiff
Make titleID cache properly (alignment issues on ARM with uint64_t apparently)
authorchaoskagami <chaos.kagami@gmail.com>
Thu, 9 Jun 2016 20:03:18 +0000 (16:03 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Thu, 9 Jun 2016 21:12:13 +0000 (17:12 -0400)
external/loader/source/patcher.c
external/loader/source/patcher.h
source/interp.c

index 0e9328de24656f3b377ea5cc03190ae96f074456..d8f8fa490d76eee045ae4bebff0f66269def0427 100644 (file)
@@ -82,7 +82,8 @@ void
 hexdump_titleid(u64 progId, char *buf)
 {
     u32 i = strlen(buf) - 1;
-    while (progId) {
+    u32 j = 16;
+    while (j--) {
         buf[i--] = hexDigits[(u32)(progId & 0xF)];
         progId >>= 4;
     }
@@ -111,7 +112,7 @@ loadTitleLocaleConfig(u64 progId, u8 *regionId, u8 *languageId)
 
     // This really does need a rewrite.
 
-    char path[] = LANG_PATH;
+    static char path[] = LANG_PATH;
     hexdump_titleid(progId, path);
 
     static const char *regions[] = { "JPN", "USA", "EUR", "AUS", "CHN", "KOR", "TWN" };
@@ -334,7 +335,7 @@ sd_code(u64 progId, u8 *code_loc, u32 code_len)
 
     u32 highTid = progId >> 0x20;
 
-    char code_path[] = CODE_PATH;
+    static char code_path[] = CODE_PATH;
     Handle code_f;
 
     hexdump_titleid(progId, code_path);
index 6a5dfec1cadf276ff6e7e50b0d9dfa6e497ff5b9..3bcf32fec65147e3cd95d8790bc3325887887504 100644 (file)
@@ -17,4 +17,6 @@ int fileOpen(Handle *file, FS_ArchiveID id, const char *path, int flags);
 
 u8 get_cpumode(u64 progId);
 
+void hexdump_titleid(u64 progId, char *buf);
+
 #endif
index 82e608f04ab8354c90ad59a672aa3141568d1a46..e413f06c3de25a67d26a4b5ff1aaa8834df54f77 100644 (file)
@@ -396,8 +396,6 @@ 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)
@@ -507,17 +505,20 @@ 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) {
+            for (uint32_t i = 0; i < patch->titles; i++) {
                 char cache_path[] = PATH_LOADER_CACHE "/0000000000000000";
 
-                uint32_t len = strlen(cache_path) - 1;
-                uint64_t prog = *(uint64_t *)title_buf;
-                while (prog) {
-                    title_buf[len--] = hexDigits[(uint32_t)(prog & 0xF)];
-                    prog >>= 4;
+                uint64_t title = 0;
+                memcpy(&title, &title_buf[i * 8], 8);
+
+                uint32_t tlen = strlen(cache_path) - 1;
+                int j = 16;
+                while (j--) {
+                    cache_path[tlen--] = hexDigits[title & 0xF];
+                    title >>= 4;
                 }
 
-                fprintf(stderr, "  cache: %s\n", cache_path);
+                fprintf(stderr, "  cache: %s\n", &cache_path[strlen(cache_path) - 16]);
 
                 char reset = 0xFF;