From 9e87679ee2e07535ca8dfaf68beafbf202ed7651 Mon Sep 17 00:00:00 2001 From: TuxSH Date: Sat, 7 May 2016 19:16:53 +0200 Subject: [PATCH] Use a much better algorithm for getLoader (Luma3DS boots around 0.25s faster now) --- source/patches.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/source/patches.c b/source/patches.c index 2938b49..1734384 100644 --- a/source/patches.c +++ b/source/patches.c @@ -74,9 +74,16 @@ u16 *getFirmWriteSafe(u8 *pos, u32 size) void *getLoader(u8 *pos, u32 size, u32 *loaderSize) { - u8 *const off = memsearch(pos, "loade", size, 5); - - *loaderSize = *(u32 *)(off - 0xFC) * 0x200; - - return off - 0x200; + u8 *off = pos; + do + { + if(*(u32 *)(off + 0x200) == 0x64616F6C) break; //"load" + off += *(u32 *)(off + 0x104) * 0x200; //size of the CXI + } + while(off < pos + size); + + if(off >= pos + size) return NULL; + + *loaderSize = *(u32 *)(off + 0x104) * 0x200; + return off; } \ No newline at end of file