From 47369c8f5ec23464253a740b2a0f2b65bca6f555 Mon Sep 17 00:00:00 2001 From: Aurora Wright Date: Fri, 2 Jun 2017 05:48:29 +0200 Subject: [PATCH] Should use the function here too --- sysmodules/loader/source/patcher.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/sysmodules/loader/source/patcher.c b/sysmodules/loader/source/patcher.c index 08c0948..6298ef1 100644 --- a/sysmodules/loader/source/patcher.c +++ b/sysmodules/loader/source/patcher.c @@ -159,6 +159,17 @@ exit: IFile_Close(&file); } +static u32 findFunctionStart(u8 *code, u32 pos) +{ + while(pos >= 4) + { + pos -= 4; + if(*(u16 *)(code + pos + 2) == 0xE92D) return pos; + } + + return 0xFFFFFFFF; +} + static inline u8 *getCfgOffsets(u8 *code, u32 size, u32 *CFGUHandleOffset) { /* HANS: @@ -202,11 +213,11 @@ static inline u8 *getCfgOffsets(u8 *code, u32 size, u32 *CFGUHandleOffset) static inline bool patchCfgGetLanguage(u8 *code, u32 size, u8 languageId, u8 *CFGU_GetConfigInfoBlk2_endPos) { - u8 *CFGU_GetConfigInfoBlk2_startPos; //Let's find STMFD SP (there might be a NOP before, but nevermind) + u32 additive = findFunctionStart(code, (u32)(CFGU_GetConfigInfoBlk2_endPos - code)); - for(CFGU_GetConfigInfoBlk2_startPos = CFGU_GetConfigInfoBlk2_endPos - 4; - *((u16 *)CFGU_GetConfigInfoBlk2_startPos + 1) != 0xE92D; CFGU_GetConfigInfoBlk2_startPos -= 4) - if(CFGU_GetConfigInfoBlk2_startPos < code + 4) return false; + if(additive == 0xFFFFFFFF) return false; + + u8 *CFGU_GetConfigInfoBlk2_startPos = code + additive; for(u8 *languageBlkIdPos = code; languageBlkIdPos <= code + size - 4; languageBlkIdPos += 4) { @@ -269,17 +280,6 @@ static inline void patchCfgGetRegion(u8 *code, u32 size, u8 regionId, u32 CFGUHa } } -static u32 findFunctionStart(u8 *code, u32 pos) -{ - while(pos >= 4) - { - pos -= 4; - if(*(u16 *)(code + pos + 2) == 0xE92D) return pos; - } - - return 0xFFFFFFFF; -} - static inline bool findLayeredFsSymbols(u8 *code, u32 size, u32 *fsMountArchive, u32 *fsRegisterArchive, u32 *fsTryOpenFile, u32 *fsOpenFileDirectly) { u32 found = 0,