From a2bca96d479c4df689cc9f3ae58100f3a850941a Mon Sep 17 00:00:00 2001 From: Aurora Date: Sat, 3 Sep 2016 15:35:46 +0200 Subject: [PATCH] Cleanup, use sizeof() for pattern memsearches --- injector/source/patcher.c | 8 ++++---- source/emunand.c | 10 +++++----- source/patches.c | 24 ++++++++++++------------ 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/injector/source/patcher.c b/injector/source/patcher.c index 3e8af05..ae88478 100644 --- a/injector/source/patcher.c +++ b/injector/source/patcher.c @@ -325,7 +325,7 @@ void patchCode(u64 progId, u8 *code, u32 size) case 0x000400300000B102LL: // TWN Menu { static const u8 regionFreePattern[] = { - 0x00, 0x00, 0x55, 0xE3, 0x01, 0x10, 0xA0, 0xE3 + 0x00, 0x00, 0x55, 0xE3, 0x01, 0x10, 0xA0 }; static const u8 regionFreePatch[] = { 0x01, 0x00, 0xA0, 0xE3, 0x1E, 0xFF, 0x2F, 0xE1 @@ -384,7 +384,7 @@ void patchCode(u64 progId, u8 *code, u32 size) case 0x0004013000003202LL: // FRIENDS { static const u8 fpdVerPattern[] = { - 0xE0, 0x1E, 0xFF, 0x2F, 0xE1, 0x01, 0x01, 0x01 + 0xE0, 0x1E, 0xFF, 0x2F, 0xE1, 0x01, 0x01 }; static const u8 mostRecentFpdVer = 0x06; @@ -445,7 +445,7 @@ void patchCode(u64 progId, u8 *code, u32 size) if(cpuSetting) { static const u8 cfgN3dsCpuPattern[] = { - 0x00, 0x40, 0xA0, 0xE1, 0x07, 0x00 + 0x00, 0x40, 0xA0, 0xE1, 0x07 }; u32 *cfgN3dsCpuLoc = (u32 *)memsearch(code, cfgN3dsCpuPattern, size, sizeof(cfgN3dsCpuPattern)); @@ -464,7 +464,7 @@ void patchCode(u64 progId, u8 *code, u32 size) case 0x0004013000001702LL: // CFG { static const u8 secureinfoSigCheckPattern[] = { - 0x06, 0x46, 0x10, 0x48, 0xFC + 0x06, 0x46, 0x10, 0x48 }; static const u8 secureinfoSigCheckPatch[] = { 0x00, 0x26 diff --git a/source/emunand.c b/source/emunand.c index c3198a5..d34d6c3 100644 --- a/source/emunand.c +++ b/source/emunand.c @@ -63,14 +63,14 @@ static inline void *getFreeK9Space(u8 *pos, u32 size) const u8 pattern[] = {0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00}; //Looking for the last free space before Process9 - return memsearch(pos + 0x13500, pattern, size - 0x13500, 6) + 0x455; + return memsearch(pos + 0x13500, pattern, size - 0x13500, sizeof(pattern)) + 0x455; } static inline u32 getSdmmc(u8 *pos, u32 size) { //Look for struct code const u8 pattern[] = {0x21, 0x20, 0x18, 0x20}; - const u8 *off = memsearch(pos, pattern, size, 4); + const u8 *off = memsearch(pos, pattern, size, sizeof(pattern)); return *(u32 *)(off + 9) + *(u32 *)(off + 0xD); } @@ -82,8 +82,8 @@ static inline void patchNandRw(u8 *pos, u32 size, u32 branchOffset) //Look for read/write code const u8 pattern[] = {0x1E, 0x00, 0xC8, 0x05}; - u16 *readOffset = (u16 *)memsearch(pos, pattern, size, 4) - 3, - *writeOffset = (u16 *)memsearch((u8 *)(readOffset + 5), pattern, 0x100, 4) - 3; + u16 *readOffset = (u16 *)memsearch(pos, pattern, size, sizeof(pattern)) - 3, + *writeOffset = (u16 *)memsearch((u8 *)(readOffset + 5), pattern, 0x100, sizeof(pattern)) - 3; *readOffset = nandRedir[0]; readOffset[1] = nandRedir[1]; @@ -98,7 +98,7 @@ static inline void patchMpu(u8 *pos, u32 size) //Look for MPU pattern const u8 pattern[] = {0x03, 0x00, 0x24, 0x00}; - u32 *off = (u32 *)memsearch(pos, pattern, size, 4); + u32 *off = (u32 *)memsearch(pos, pattern, size, sizeof(pattern)); off[0] = 0x00360003; off[6] = 0x00200603; diff --git a/source/patches.c b/source/patches.c index d6bf68a..a2ac4d7 100644 --- a/source/patches.c +++ b/source/patches.c @@ -42,14 +42,14 @@ u32 *getKernel11Info(u8 *pos, u32 size, u8 **freeK11Space) { const u8 pattern[] = {0x00, 0xB0, 0x9C, 0xE5}; - u32 *arm11ExceptionsPage = (u32 *)memsearch(pos, pattern, size, 4) - 0xB; + u32 *arm11ExceptionsPage = (u32 *)memsearch(pos, pattern, size, sizeof(pattern)) - 0xB; u32 svcOffset = (-((arm11ExceptionsPage[2] & 0xFFFFFF) << 2) & (0xFFFFFF << 2)) - 8; //Branch offset + 8 for prefetch u32 *arm11SvcTable = (u32 *)(pos + *(u32 *)(pos + 0xFFFF0008 - svcOffset - 0xFFF00000 + 8) - 0xFFF00000); //SVC handler address while(*arm11SvcTable) arm11SvcTable++; //Look for SVC0 (NULL) const u8 pattern2[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; - *freeK11Space = memsearch(pos, pattern2, size, 5) + 1; + *freeK11Space = memsearch(pos, pattern2, size, sizeof(pattern2)) + 1; return arm11SvcTable; } @@ -62,8 +62,8 @@ void patchSignatureChecks(u8 *pos, u32 size) const u8 pattern[] = {0xC0, 0x1C, 0x76, 0xE7}, pattern2[] = {0xB5, 0x22, 0x4D, 0x0C}; - u16 *off = (u16 *)memsearch(pos, pattern, size, 4), - *off2 = (u16 *)(memsearch(pos, pattern2, size, 4) - 1); + u16 *off = (u16 *)memsearch(pos, pattern, size, sizeof(pattern)), + *off2 = (u16 *)(memsearch(pos, pattern2, size, sizeof(pattern2)) - 1); *off = sigPatch[0]; off2[0] = sigPatch[0]; @@ -75,7 +75,7 @@ void patchFirmlaunches(u8 *pos, u32 size, u32 process9MemAddr) //Look for firmlaunch code const u8 pattern[] = {0xE2, 0x20, 0x20, 0x90}; - u8 *off = memsearch(pos, pattern, size, 4) - 0x13; + u8 *off = memsearch(pos, pattern, size, sizeof(pattern)) - 0x13; //Firmlaunch function offset - offset in BLX opcode (A4-16 - ARM DDI 0100E) + 1 u32 fOpenOffset = (u32)(off + 9 - (-((*(u32 *)off & 0x00FFFFFF) << 2) & (0xFFFFFF << 2)) - pos + process9MemAddr); @@ -94,7 +94,7 @@ void patchFirmWrites(u8 *pos, u32 size) u8 *const off1 = memsearch(pos, "exe:", size, 4); const u8 pattern[] = {0x00, 0x28, 0x01, 0xDA}; - u16 *off2 = (u16 *)memsearch(off1 - 0x100, pattern, 0x100, 4); + u16 *off2 = (u16 *)memsearch(off1 - 0x100, pattern, 0x100, sizeof(pattern)); off2[0] = 0x2000; off2[1] = 0x46C0; @@ -105,7 +105,7 @@ void patchOldFirmWrites(u8 *pos, u32 size) //Look for FIRM writing code const u8 pattern[] = {0x04, 0x1E, 0x1D, 0xDB}; - u16 *off = (u16 *)memsearch(pos, pattern, size, 4); + u16 *off = (u16 *)memsearch(pos, pattern, size, sizeof(pattern)); off[0] = 0x2400; off[1] = 0xE01D; @@ -130,7 +130,7 @@ void reimplementSvcBackdoor(u8 *pos, u32 *arm11SvcTable, u8 **freeK11Space) memcpy(*freeK11Space, svcBackdoor, 40); arm11SvcTable[0x7B] = 0xFFF00000 + *freeK11Space - pos; - (*freeK11Space) += 40; + *freeK11Space += 40; } } @@ -157,15 +157,15 @@ void implementSvcGetCFWInfo(u8 *pos, u32 *arm11SvcTable, u8 **freeK11Space) info->flags = 0 /* master branch */ | ((isRelease ? 1 : 0) << 1) /* is release */; arm11SvcTable[0x2E] = 0xFFF00000 + *freeK11Space - pos; //Stubbed svc - (*freeK11Space) += svcGetCFWInfo_size; + *freeK11Space += svcGetCFWInfo_size; } void patchTitleInstallMinVersionCheck(u8 *pos, u32 size) { const u8 pattern[] = {0x0A, 0x81, 0x42, 0x02}; - - u8 *off = memsearch(pos, pattern, size, 4); - + + u8 *off = memsearch(pos, pattern, size, sizeof(pattern)); + if(off != NULL) off[4] = 0xE0; }