From a302ad3bea456317469cf60d968c49cfea82791c Mon Sep 17 00:00:00 2001 From: TuxSH Date: Sat, 20 Aug 2016 18:45:56 +0200 Subject: [PATCH 1/3] R.I.P boot speed boost (for now) --- injector/source/patcher.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/injector/source/patcher.c b/injector/source/patcher.c index 4242cd2..a2e63c3 100644 --- a/injector/source/patcher.c +++ b/injector/source/patcher.c @@ -19,18 +19,6 @@ typedef struct __attribute__((packed)) CFWInfo info = {0}; -int __attribute__((naked)) svcGetCFWInfo(CFWInfo __attribute__((unused)) *out) -{ - __asm__ volatile("svc 0x2E; bx lr"); -} - -static void loadCFWInfo(void) -{ - static bool infoLoaded = false; - if(!infoLoaded) svcGetCFWInfo(&info); - infoLoaded = true; -} - #ifndef PATH_MAX #define PATH_MAX 255 #define CONFIG(a) (((info.config >> (a + 16)) & 1) != 0) @@ -118,6 +106,26 @@ static int fileOpen(IFile *file, FS_ArchiveID archiveId, const char *path, int f return IFile_Open(file, archiveId, archivePath, filePath, flags); } +int __attribute__((naked)) svcGetCFWInfo(CFWInfo __attribute__((unused)) *out) +{ + __asm__ volatile("svc 0x2E; bx lr"); +} + +static void loadCFWInfo(void) +{ + static bool infoLoaded = false; + if(!infoLoaded) + { + svcGetCFWInfo(&info); + IFile file; + if(R_SUCCEEDED(fileOpen(&file, ARCHIVE_SDMC, "/", FS_OPEN_READ))) //init SD card for firmlaunch patches + { + IFile_Close(&file); + } + } + infoLoaded = true; +} + static bool secureInfoExists(void) { static bool exists = false; @@ -584,4 +592,4 @@ void patchCode(u64 progId, u8 *code, u32 size) break; } -} \ No newline at end of file +} From ef1ecf859c4d7af3eee5d323c3b079cfc256aaa2 Mon Sep 17 00:00:00 2001 From: TuxSH Date: Sat, 20 Aug 2016 19:59:25 +0200 Subject: [PATCH 2/3] Update draw.c --- source/draw.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/draw.c b/source/draw.c index b23bc09..e715554 100644 --- a/source/draw.c +++ b/source/draw.c @@ -43,7 +43,7 @@ static inline int strlen(const char *string) bool loadSplash(void) { //Don't delay boot nor init the screens if no splash image is on the SD - if(getFileSize("/luma/splash.bin") + getFileSize("/luma/splash.bin") == 0) + if(getFileSize("/luma/splash.bin") + getFileSize("/luma/splashbottom.bin") == 0) return false; initScreens(); @@ -98,4 +98,4 @@ int drawString(const char *string, int posX, int posY, u32 color) } return posY; -} \ No newline at end of file +} From 253e031f83014ef2948e63f7b7e8b84044b720c3 Mon Sep 17 00:00:00 2001 From: TuxSH Date: Sun, 21 Aug 2016 22:09:27 +0200 Subject: [PATCH 3/3] Add support for loading /luma/TwlBg.cxi (on dev branch this will take precedence) --- source/firm.c | 64 ++++++++++++++++++++++++++++++++++++++++++------ source/firm.h | 2 +- source/patches.c | 19 +------------- source/patches.h | 3 +-- 4 files changed, 59 insertions(+), 29 deletions(-) diff --git a/source/firm.c b/source/firm.c index fde33b8..44d23ee 100755 --- a/source/firm.c +++ b/source/firm.c @@ -332,25 +332,73 @@ static inline void patchSafeFirm(void) else patchFirmWriteSafe(arm9Section, section[2].size); } -static inline void copySection0AndInjectLoader(void) +static inline void copySection0AndInjectSystemModules(FirmwareType firmType) { u8 *arm11Section0 = (u8 *)firm + section[0].offset; - u32 loaderSize; - u32 loaderOffset = getLoader(arm11Section0, &loaderSize); + struct + { + u32 size; + char name[8]; + const u8 *addr; + } modules[5] = {{0}}; - memcpy(section[0].address, arm11Section0, loaderOffset); - memcpy(section[0].address + loaderOffset, injector, injector_size); - memcpy(section[0].address + loaderOffset + injector_size, arm11Section0 + loaderOffset + loaderSize, section[0].size - (loaderOffset + loaderSize)); + u8 *pos = arm11Section0, *end = pos + section[0].size; + u32 n = 0; + + u32 loaderIndex = 0, twlBgIndex = 0; + + while(pos < end) + { + modules[n].addr = pos; + modules[n].size = *(u32 *)(pos + 0x104) * 0x200; + + memcpy(modules[n].name, pos + 0x200, 8); + pos += modules[n].size; + + if(firmType == NATIVE_FIRM && memcmp(modules[n].name, "loader", 7) == 0) loaderIndex = n; + else if(firmType == TWL_FIRM && memcmp(modules[n].name, "TwlBg", 6) == 0) twlBgIndex = n; + + n++; + } + + u32 twlBgSize = 0; + + if(firmType == NATIVE_FIRM) + { + modules[loaderIndex].size = injector_size; + modules[loaderIndex].addr = injector; + } + + else if(firmType == TWL_FIRM) + { + twlBgSize = getFileSize("/luma/TwlBg.cxi"); + if(twlBgSize != 0) + { + modules[twlBgIndex].size = twlBgSize; + modules[twlBgIndex].addr = NULL; + } + } + + pos = section[0].address; + for(u32 i = 0; i < n; i++) + { + if(firmType == TWL_FIRM && i == twlBgIndex && twlBgSize != 0) + fileRead(pos, "/luma/TwlBg.cxi"); + else if(modules[i].addr != NULL) + memcpy(pos, modules[i].addr, modules[i].size); + + pos += modules[i].size; + } } static inline void launchFirm(FirmwareType firmType, bool isFirmlaunch) { //If we're booting NATIVE_FIRM, section0 needs to be copied separately to inject 3ds_injector u32 sectionNum; - if(firmType == NATIVE_FIRM) + if(firmType != SAFE_FIRM) { - copySection0AndInjectLoader(); + copySection0AndInjectSystemModules(firmType); sectionNum = 1; } else sectionNum = 0; diff --git a/source/firm.h b/source/firm.h index 9e7bf61..7437b3e 100644 --- a/source/firm.h +++ b/source/firm.h @@ -58,5 +58,5 @@ static inline u32 loadFirm(FirmwareType firmType); static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 emuHeader, bool isA9lh); static inline void patchLegacyFirm(FirmwareType firmType); static inline void patchSafeFirm(void); -static inline void copySection0AndInjectLoader(void); +static inline void copySection0AndInjectSystemModules(FirmwareType firmType); static inline void launchFirm(FirmwareType firmType, bool isFirmlaunch); \ No newline at end of file diff --git a/source/patches.c b/source/patches.c index 371ed72..94bd77c 100644 --- a/source/patches.c +++ b/source/patches.c @@ -260,21 +260,4 @@ void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType) break; } } -} - -u32 getLoader(u8 *pos, u32 *loaderSize) -{ - u8 *off = pos; - u32 size; - - while(true) - { - size = *(u32 *)(off + 0x104) * 0x200; - if(*(u32 *)(off + 0x200) == 0x64616F6C) break; - off += size; - } - - *loaderSize = size; - - return (u32)(off - pos); -} +} \ No newline at end of file diff --git a/source/patches.h b/source/patches.h index b1e038f..b2629af 100644 --- a/source/patches.h +++ b/source/patches.h @@ -43,5 +43,4 @@ void patchFirmWrites(u8 *pos, u32 size); void patchFirmWriteSafe(u8 *pos, u32 size); void reimplementSvcBackdoor(u8 *pos, u32 size); void implementSvcGetCFWInfo(u8 *pos, u32 size); -void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType); -u32 getLoader(u8 *pos, u32 *loaderSize); \ No newline at end of file +void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType); \ No newline at end of file