From: chaoskagami Date: Thu, 9 Jun 2016 20:03:18 +0000 (-0400) Subject: Make titleID cache properly (alignment issues on ARM with uint64_t apparently) X-Git-Tag: v0.0.8~4^2 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=e1289dd8f5bb9197f1049c068b4c3626393e2f8c;p=corbenik%2Fcorbenik.git Make titleID cache properly (alignment issues on ARM with uint64_t apparently) --- diff --git a/external/loader/source/patcher.c b/external/loader/source/patcher.c index 0e9328d..d8f8fa4 100644 --- a/external/loader/source/patcher.c +++ b/external/loader/source/patcher.c @@ -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); diff --git a/external/loader/source/patcher.h b/external/loader/source/patcher.h index 6a5dfec..3bcf32f 100644 --- a/external/loader/source/patcher.h +++ b/external/loader/source/patcher.h @@ -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 diff --git a/source/interp.c b/source/interp.c index 82e608f..e413f06 100644 --- a/source/interp.c +++ b/source/interp.c @@ -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;