From 98f650a5de9de143ef3452f340193dcf74feadd0 Mon Sep 17 00:00:00 2001 From: Aurora Wright Date: Sat, 20 May 2017 05:09:48 +0200 Subject: [PATCH] Make loader recognize SD/CTRNAND modes and only look in the appropriate one --- injector/source/patcher.c | 23 +++++++++-------------- injector/source/patcher.h | 3 ++- source/config.c | 2 +- source/config.h | 2 +- source/fs.c | 2 +- source/main.c | 8 +++----- source/patches.c | 1 + source/types.h | 3 ++- 8 files changed, 20 insertions(+), 24 deletions(-) diff --git a/injector/source/patcher.c b/injector/source/patcher.c index b399311..160fade 100644 --- a/injector/source/patcher.c +++ b/injector/source/patcher.c @@ -40,19 +40,19 @@ static Result fileOpen(IFile *file, FS_ArchiveID archiveId, const char *path, in return IFile_Open(file, archiveId, archivePath, filePath, flags); } -static u32 dirCheck(FS_ArchiveID archiveId, const char *path) +static bool dirCheck(FS_ArchiveID archiveId, const char *path) { - u32 ret; + bool ret; Handle handle; FS_Archive archive; FS_Path dirPath = {PATH_ASCII, strnlen(path, 255) + 1, path}, archivePath = {PATH_EMPTY, 1, (u8 *)""}; - if(R_FAILED(FSLDR_OpenArchive(&archive, archiveId, archivePath))) ret = 1; + if(R_FAILED(FSLDR_OpenArchive(&archive, archiveId, archivePath))) ret = false; else { - ret = R_SUCCEEDED(FSLDR_OpenDirectory(&handle, archive, dirPath)) ? 0 : 2; - if(!ret) FSDIR_Close(handle); + ret = R_SUCCEEDED(FSLDR_OpenDirectory(&handle, archive, dirPath)); + if(ret) FSDIR_Close(handle); FSLDR_CloseArchive(archive); } @@ -61,21 +61,16 @@ static u32 dirCheck(FS_ArchiveID archiveId, const char *path) static bool openLumaFile(IFile *file, const char *path) { - Result res = fileOpen(file, ARCHIVE_SDMC, path, FS_OPEN_READ); + FS_ArchiveID archiveId = ISSDMODE ? ARCHIVE_SDMC : ARCHIVE_NAND_RW; - if(R_SUCCEEDED(res)) return true; - - //Returned if SD is not mounted - return (u32)res == 0xC88044AB && R_SUCCEEDED(fileOpen(file, ARCHIVE_NAND_RW, path, FS_OPEN_READ)); + return R_SUCCEEDED(fileOpen(file, archiveId, path, FS_OPEN_READ)); } static u32 checkLumaDir(const char *path) { - u32 res = dirCheck(ARCHIVE_SDMC, path); + FS_ArchiveID archiveId = ISSDMODE ? ARCHIVE_SDMC : ARCHIVE_NAND_RW; - if(!res) return ARCHIVE_SDMC; - - return res == 1 && !dirCheck(ARCHIVE_NAND_RW, path) ? ARCHIVE_NAND_RW : 0; + return dirCheck(archiveId, path) ? archiveId : 0; } static inline void loadCFWInfo(void) diff --git a/injector/source/patcher.h b/injector/source/patcher.h index 7b1d697..995c5a4 100644 --- a/injector/source/patcher.h +++ b/injector/source/patcher.h @@ -39,7 +39,8 @@ enum singleOptions enum flags { ISN3DS = 0, - ISSAFEMODE + ISSAFEMODE, + ISSDMODE }; void patchCode(u64 progId, u16 progVer, u8 *code, u32 size, u32 textSize, u32 roSize, u32 dataSize, u32 roAddress, u32 dataAddress); diff --git a/source/config.c b/source/config.c index 216930a..4811482 100644 --- a/source/config.c +++ b/source/config.c @@ -72,7 +72,7 @@ void writeConfig(bool isPayloadLaunch) error("Error writing the configuration file"); } -void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode) +void configMenu(bool oldPinStatus, u32 oldPinMode) { const char *multiOptionsText[] = { "Default EmuNAND: 1( ) 2( ) 3( ) 4( )", "Screen brightness: 4( ) 3( ) 2( ) 1( )", diff --git a/source/config.h b/source/config.h index e7bc916..b5a832e 100644 --- a/source/config.h +++ b/source/config.h @@ -67,4 +67,4 @@ typedef enum ConfigurationStatus bool readConfig(void); void writeConfig(bool isPayloadLaunch); -void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode); +void configMenu(bool oldPinStatus, u32 oldPinMode); diff --git a/source/fs.c b/source/fs.c index f0d4b23..acf075f 100644 --- a/source/fs.c +++ b/source/fs.c @@ -219,7 +219,7 @@ void loadPayload(u32 pressed, const char *payloadPath) writeConfig(true); - if(memcmp(launchedPath, u"nand", 8) == 0) + if(!isSdMode) sprintf(absPath, "nand:/rw/luma/%s", path); else sprintf(absPath, "sdmc:/luma/%s", path); diff --git a/source/main.c b/source/main.c index b8190db..8cc2fe1 100644 --- a/source/main.c +++ b/source/main.c @@ -38,7 +38,8 @@ extern CfgData configData; extern ConfigurationStatus needConfig; extern FirmwareSource firmSource; -bool isFirmlaunch; +bool isFirmlaunch, + isSdMode; u16 launchedPath[41]; void main(int argc, char **argv) @@ -85,9 +86,6 @@ void main(int argc, char **argv) break; } - //Mount SD or CTRNAND - bool isSdMode; - if(memcmp(launchedPath, u"sdmc", 8) == 0) { if(!mountFs(true, false)) error("Failed to mount SD."); @@ -182,7 +180,7 @@ void main(int argc, char **argv) if(shouldLoadConfigMenu) { - configMenu(isSdMode, pinExists, pinMode); + configMenu(pinExists, pinMode); //Update pressed buttons pressed = HID_PAD; diff --git a/source/patches.c b/source/patches.c index 4df6719..39cc82c 100644 --- a/source/patches.c +++ b/source/patches.c @@ -313,6 +313,7 @@ u32 implementSvcGetCFWInfo(u8 *pos, u32 *arm11SvcTable, u32 baseK11VA, u8 **free if(isRelease) info->flags = 1; if(ISN3DS) info->flags |= 1 << 4; if(isSafeMode) info->flags |= 1 << 5; + if(isSdMode) info->flags |= 1 << 6; arm11SvcTable[0x2E] = baseK11VA + *freeK11Space - pos; //Stubbed svc *freeK11Space += svcGetCFWInfo_bin_size; diff --git a/source/types.h b/source/types.h index 44b4b00..7b017a9 100644 --- a/source/types.h +++ b/source/types.h @@ -110,7 +110,8 @@ typedef enum FirmwareType NATIVE_FIRM1X2X } FirmwareType; -extern bool isFirmlaunch; +extern bool isFirmlaunch, + isSdMode; extern u16 launchedFirmTidLow[8]; extern u16 launchedPath[41];