From 47087e8c6467a2bf8c54ea50f70db3767df1978f Mon Sep 17 00:00:00 2001 From: chaoskagami Date: Thu, 9 Jun 2016 13:54:41 -0400 Subject: [PATCH] Remove all the hexdump implementations all over the place and use a common one --- external/loader/source/patcher.c | 28 +++++++++++++++------------- source/interp.c | 22 +++++++++------------- source/patch_format.h | 10 +++------- 3 files changed, 27 insertions(+), 33 deletions(-) diff --git a/external/loader/source/patcher.c b/external/loader/source/patcher.c index 883ebf9..8682de0 100644 --- a/external/loader/source/patcher.c +++ b/external/loader/source/patcher.c @@ -13,9 +13,10 @@ #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; diff --git a/source/interp.c b/source/interp.c index 21b9407..3ae1395 100644 --- a/source/interp.c +++ b/source/interp.c @@ -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; diff --git a/source/patch_format.h b/source/patch_format.h index d39e39f..afe9646 100644 --- a/source/patch_format.h +++ b/source/patch_format.h @@ -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 '.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) @@ -68,11 +69,6 @@ #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 -- 2.39.5