From ef3ba896d5a5c347e586005ab15d6931f81a159c Mon Sep 17 00:00:00 2001 From: Aurora Date: Tue, 12 Apr 2016 14:32:38 +0200 Subject: [PATCH] Cleanup, removed the non-working clock speed patch --- injector/source/patcher.c | 25 +------------------------ source/config.c | 1 - source/crypto.c | 2 +- source/draw.c | 1 + source/firm.c | 18 ++++++++---------- source/memory.c | 8 -------- source/memory.h | 1 - source/patches.c | 16 ++++++++-------- source/patches.h | 4 ++-- 9 files changed, 21 insertions(+), 55 deletions(-) diff --git a/injector/source/patcher.c b/injector/source/patcher.c index 5199c64..f5a4da9 100644 --- a/injector/source/patcher.c +++ b/injector/source/patcher.c @@ -206,7 +206,7 @@ void patchCode(u64 progId, u8 *code, u32 size) case 0x0004001000027000LL: // KOR MSET case 0x0004001000028000LL: // TWN MSET { - if(R_SUCCEEDED(loadConfig()) && ((config >> 6) & 1)) + if(R_SUCCEEDED(loadConfig()) && ((config >> 5) & 1)) { static const u16 verPattern[] = u"Ver."; const u32 currentNand = ((config >> 16) & 3); @@ -279,28 +279,5 @@ void patchCode(u64 progId, u8 *code, u32 size) break; } - - case 0x0004013020002202LL: // N3DS PTM - { - if(R_SUCCEEDED(loadConfig()) && ((config >> 4) & 1)) - { - static const u8 configN3dsCpuPattern[] = { - 0x02, 0x98, 0x01, 0x79, 0x1C - }; - static const u8 configN3dsCpuPatch[] = { - 0x02, 0x98, 0x03, 0x21 - }; - - //Disable SecureInfo signature check - patchMemory(code, size, - configN3dsCpuPattern, - sizeof(configN3dsCpuPattern), 0, - configN3dsCpuPatch, - sizeof(configN3dsCpuPatch), 1 - ); - } - - break; - } } } \ No newline at end of file diff --git a/source/config.c b/source/config.c index 9cf57c0..272243c 100644 --- a/source/config.c +++ b/source/config.c @@ -24,7 +24,6 @@ void configureCFW(const char *configPath) "( ) Updated SysNAND mode (A9LH-only)", "( ) Force A9LH detection", "( ) Use second EmuNAND as default", - "( ) Force max N3DS clock speed and L2 cache", "( ) Use developer UNITINFO", "( ) Show current NAND in System Settings", "( ) Show GBA boot screen in patched AGB_FIRM", diff --git a/source/crypto.c b/source/crypto.c index 6601f6a..5b1b6d7 100755 --- a/source/crypto.c +++ b/source/crypto.c @@ -355,7 +355,7 @@ void decryptExeFs(u8 *inbuf) u32 exeFsSize = *(u32 *)(inbuf + 0x1A4) * 0x200; u8 ncchCTR[0x10]; - memset(ncchCTR, 0, 0x10); + memset32(ncchCTR, 0, 0x10); for(u32 i=0; i<8; i++) ncchCTR[7-i] = *(inbuf + 0x108 + i); ncchCTR[8] = 2; diff --git a/source/draw.c b/source/draw.c index 17010ef..74f9a65 100644 --- a/source/draw.c +++ b/source/draw.c @@ -25,6 +25,7 @@ static inline int strlen(const char *string) { char *stringEnd = (char *)string; while(*stringEnd) stringEnd++; + return stringEnd - string; } diff --git a/source/firm.c b/source/firm.c index c32403f..337b13e 100755 --- a/source/firm.c +++ b/source/firm.c @@ -142,7 +142,7 @@ void main(void) configureCFW(configPath); //If screens are inited or the corresponding option is set, load splash screen - if(PDN_GPU_CNT != 1 || CONFIG(8, 1)) loadSplash(); + if(PDN_GPU_CNT != 1 || CONFIG(7, 1)) loadSplash(); //Determine if we need to boot an emuNAND or sysNAND nandType = (pressed & BUTTON_L1) ? autoBootSys : ((pressed & BUTTON_R1) ? updatedSys : !autoBootSys); @@ -182,7 +182,7 @@ void main(void) } } - loadFirm(firmType, !firmType && (nandType == 2 || updatedSys == !nandType)); + loadFirm(firmType, !firmType && (nandType == 2 || updatedSys == !firmSource)); if(!firmType) patchNativeFirm(nandType, emuHeader, a9lhInstalled); else patchTwlAgbFirm(firmType); @@ -232,7 +232,7 @@ static inline void patchNativeFirm(u32 nandType, u32 emuHeader, u32 a9lhInstalle nativeFirmType = (arm9Section[0x51] == 0xFF) ? 0 : 1; //Decrypt ARM9Bin and patch ARM9 entrypoint to skip arm9loader - arm9Loader((u8 *)firm + section[2].offset, nativeFirmType); + arm9Loader(arm9Section, nativeFirmType); firm->arm9Entry = (u8 *)0x801B01C; } else @@ -271,13 +271,11 @@ static inline void patchNativeFirm(u32 nandType, u32 emuHeader, u32 a9lhInstalle *(u16 *)sigOffset2 = sigPatch[0]; *((u16 *)sigOffset2 + 1) = sigPatch[1]; - if(CONFIG(5, 1)) + if(CONFIG(4, 1)) { //Apply UNITINFO patch - u32 unitInfoOffset; - - getUnitInfoValueSet(arm9Section, section[2].size, &unitInfoOffset); - *((u8*)unitInfoOffset + 3) = unitInfoPatch; + u8 *unitInfoOffset = getUnitInfoValueSet(arm9Section, section[2].size); + *unitInfoOffset = unitInfoPatch; } //Replace the FIRM loader with the injector @@ -349,7 +347,7 @@ static inline void injectLoader(void) //Check that the injector CXI isn't larger than the original if(injector_size <= (int)loaderSize) { - memset((void *)loaderOffset, 0, loaderSize); + memset32((void *)loaderOffset, 0, loaderSize); memcpy((void *)loaderOffset, injector, injector_size); //Patch content size and ExeFS size to match the repaced loader's ones @@ -385,7 +383,7 @@ static inline void patchTwlAgbFirm(u32 firmType) /* Calculate the amount of patches to apply. Only count the boot screen patch for AGB_FIRM if the matching option was enabled (keep it as last) */ - u32 numPatches = firmType == 1 ? (sizeof(twlPatches) / sizeof(patchData)) : (sizeof(agbPatches) / sizeof(patchData) - !CONFIG(7, 1)); + u32 numPatches = firmType == 1 ? (sizeof(twlPatches) / sizeof(patchData)) : (sizeof(agbPatches) / sizeof(patchData) - !CONFIG(6, 1)); const patchData *patches = firmType == 1 ? twlPatches : agbPatches; //Patch diff --git a/source/memory.c b/source/memory.c index 0df7fbf..dfcf8a6 100644 --- a/source/memory.c +++ b/source/memory.c @@ -17,14 +17,6 @@ void memcpy(void *dest, const void *src, u32 size) destc[i] = srcc[i]; } -void __attribute__((used)) memset(void *dest, int filler, u32 size) -{ - u8 *destc = (u8 *)dest; - - for(u32 i = 0; i < size; i++) - destc[i] = (u8)filler; -} - void memset32(void *dest, u32 filler, u32 size) { u32 *dest32 = (u32 *)dest; diff --git a/source/memory.h b/source/memory.h index 2b54ac8..95da9b9 100644 --- a/source/memory.h +++ b/source/memory.h @@ -11,7 +11,6 @@ #include "types.h" void memcpy(void *dest, const void *src, u32 size); -void memset(void *dest, int filler, u32 size); void memset32(void *dest, u32 filler, u32 size); int memcmp(const void *buf1, const void *buf2, u32 size); u8 *memsearch(u8 *startPos, const void *pattern, u32 size, u32 patternSize); \ No newline at end of file diff --git a/source/patches.c b/source/patches.c index 407ef25..6135246 100644 --- a/source/patches.c +++ b/source/patches.c @@ -69,18 +69,18 @@ u16 *getFirmWrite(u8 *pos, u32 size) return (u16 *)memsearch(off - 0x100, pattern, 0x100, 4); } +u8 *getUnitInfoValueSet(u8 *pos, u32 size) +{ + //Look for UNITINFO value being set + const u8 pattern[] = {0x01, 0x10, 0xA0, 0x13}; + + return memsearch(pos, pattern, size, 4) + 3; +} + void getLoader(u8 *pos, u32 size, u32 *loaderOffset, u32 *loaderSize) { u8 *const off = memsearch(pos, "loade", size, 5); *loaderOffset = (u32)off - 0x200; *loaderSize = *(u32 *)(off - 0xFC) * 0x200; -} - -void getUnitInfoValueSet(u8 *pos, u32 size, u32 *off) -{ - //Look for UNITINFO value being set - const u8 pattern[] = {0x01, 0x10, 0xA0, 0x13}; - - *off = (u32)memsearch(pos, pattern, size, 4); } \ No newline at end of file diff --git a/source/patches.h b/source/patches.h index 41485f1..0011433 100644 --- a/source/patches.h +++ b/source/patches.h @@ -25,5 +25,5 @@ void getSigChecks(u8 *pos, u32 size, u32 *off, u32 *off2); void *getReboot(u8 *pos, u32 size); u32 getfOpen(u8 *proc9Offset, void *rebootOffset); u16 *getFirmWrite(u8 *pos, u32 size); -void getLoader(u8 *pos, u32 size, u32 *loaderOffset, u32 *loaderSize); -void getUnitInfoValueSet(u8 *pos, u32 size, u32* off); \ No newline at end of file +u8 *getUnitInfoValueSet(u8 *pos, u32 size); +void getLoader(u8 *pos, u32 size, u32 *loaderOffset, u32 *loaderSize); \ No newline at end of file