From f8f4ecea276432be47d080b3363f0658b1529e53 Mon Sep 17 00:00:00 2001 From: Aurora Date: Wed, 13 Apr 2016 00:15:09 +0200 Subject: [PATCH] Add better code to the FIRM finding function to convert from integer to its hex representation array --- injector/source/patcher.c | 2 +- source/fs.c | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/injector/source/patcher.c b/injector/source/patcher.c index 2ea5f0c..5162d1e 100644 --- a/injector/source/patcher.c +++ b/injector/source/patcher.c @@ -114,7 +114,7 @@ static int loadConfig() { ret = IFile_Read(&file, &total, &config, 3); IFile_Close(&file); - if(R_SUCCEEDED(ret)) config |= 1 << 24; + if(R_SUCCEEDED(ret)) config |= 1 << 4; } return ret; diff --git a/source/fs.c b/source/fs.c index 1b17301..45d0886 100644 --- a/source/fs.c +++ b/source/fs.c @@ -94,10 +94,10 @@ void firmRead(void *dest, const char *firmFolder) //Convert the .app name to an integer u32 tempId = 0; - for(char *tmp = info.fname; (*tmp) != '.'; tmp++) + for(char *tmp = info.fname; *tmp != '.'; tmp++) { tempId <<= 4; - tempId += *tmp > '9' ? (*tmp - 'A') + 9 : (*tmp) - '0'; + tempId += *tmp > '9' ? *tmp - 'A' + 10 : *tmp - '0'; } //Found a newer cxi @@ -113,13 +113,12 @@ void firmRead(void *dest, const char *firmFolder) u32 i = 42; //Convert back the .app name from integer to array - while(id > 15) + while(id > 0) { - u32 remainder = (id % 16); - path[i--] = remainder > 9 ? remainder - 9 + 'A' : remainder + '0'; - id /= 16; + static const char hexDigits[] = "0123456789ABCDEF"; + path[i--] = hexDigits[id & 0xF]; + id >>= 4; } - path[i] = id > 9 ? id - 9 + 'A' : id + '0'; fileRead(dest, path, 0); } \ No newline at end of file