diff --git a/injector/source/patcher.c b/injector/source/patcher.c index cd420fb..e0064ac 100644 --- a/injector/source/patcher.c +++ b/injector/source/patcher.c @@ -67,36 +67,34 @@ static bool secureInfoExists(void) return exists; } -static int loadCustomVerString(u16 *out, u32 *verStringSize) +static void loadCustomVerString(u16 *out, u32 *verStringSize) { static const char path[] = "/luma/customversion.txt"; IFile file; - Result ret = fileOpen(&file, ARCHIVE_SDMC, path, FS_OPEN_READ); - if(R_SUCCEEDED(ret)) + + if(R_SUCCEEDED(fileOpen(&file, ARCHIVE_SDMC, path, FS_OPEN_READ))) { u64 fileSize; - ret = IFile_GetSize(&file, &fileSize); - if(R_SUCCEEDED(ret) && fileSize <= 19) + if(R_SUCCEEDED(IFile_GetSize(&file, &fileSize)) && fileSize <= 19) { - *verStringSize = (u32)fileSize; u8 buf[19]; u64 total; - ret = IFile_Read(&file, &total, buf, *verStringSize); + if(R_SUCCEEDED(IFile_Read(&file, &total, buf, fileSize))) + { + *verStringSize = (u32)fileSize; - for(u32 i = 0; i < *verStringSize; i++) - ((u8 *)out)[2 * i] = buf[i]; + for(u32 i = 0; i < *verStringSize; i++) + ((u8 *)out)[2 * i] = buf[i]; - *verStringSize *= 2; + *verStringSize *= 2; + } } - else ret = -1; IFile_Close(&file); } - - return ret; } static void loadTitleCodeSection(u64 progId, u8 *code, u32 size) @@ -108,24 +106,22 @@ static void loadTitleCodeSection(u64 progId, u8 *code, u32 size) progIdToStr(path + 35, progId); IFile file; - Result ret = fileOpen(&file, ARCHIVE_SDMC, path, FS_OPEN_READ); - if(R_SUCCEEDED(ret)) + if(R_SUCCEEDED(fileOpen(&file, ARCHIVE_SDMC, path, FS_OPEN_READ))) { u64 fileSize; - ret = IFile_GetSize(&file, &fileSize); - if(R_SUCCEEDED(ret) && fileSize <= size) + if(R_SUCCEEDED(IFile_GetSize(&file, &fileSize)) && fileSize <= size) { u64 total; - ret = IFile_Read(&file, &total, code, fileSize); + IFile_Read(&file, &total, code, fileSize); } IFile_Close(&file); } } -static int loadTitleLocaleConfig(u64 progId, u8 *regionId, u8 *languageId) +static void loadTitleLocaleConfig(u64 progId, u8 *regionId, u8 *languageId) { /* Here we look for "/luma/locales/[u64 titleID in hex, uppercase].txt" If it exists it should contain, for example, "EUR IT" */ @@ -134,22 +130,19 @@ static int loadTitleLocaleConfig(u64 progId, u8 *regionId, u8 *languageId) progIdToStr(path + 29, progId); IFile file; - Result ret = fileOpen(&file, ARCHIVE_SDMC, path, FS_OPEN_READ); - if(R_SUCCEEDED(ret)) + + if(R_SUCCEEDED(fileOpen(&file, ARCHIVE_SDMC, path, FS_OPEN_READ))) { u64 fileSize; - ret = IFile_GetSize(&file, &fileSize); - if(R_SUCCEEDED(ret) && fileSize == 6) + if(R_SUCCEEDED(IFile_GetSize(&file, &fileSize)) && fileSize == 6) { char buf[6]; u64 total; - ret = IFile_Read(&file, &total, buf, 6); - - if(R_SUCCEEDED(ret)) + if(R_SUCCEEDED(IFile_Read(&file, &total, buf, 6))) { - for(u32 i = 0; i < 7; ++i) + for(u32 i = 0; i < 7; i++) { static const char *regions[] = {"JPN", "USA", "EUR", "AUS", "CHN", "KOR", "TWN"}; @@ -160,7 +153,7 @@ static int loadTitleLocaleConfig(u64 progId, u8 *regionId, u8 *languageId) } } - for(u32 i = 0; i < 12; ++i) + for(u32 i = 0; i < 12; i++) { static const char *languages[] = {"JP", "EN", "FR", "DE", "IT", "ES", "ZH", "KO", "NL", "PT", "RU", "TW"}; @@ -172,12 +165,9 @@ static int loadTitleLocaleConfig(u64 progId, u8 *regionId, u8 *languageId) } } } - else ret = -1; IFile_Close(&file); } - - return ret; } static u8 *getCfgOffsets(u8 *code, u32 size, u32 *CFGUHandleOffset) @@ -367,11 +357,11 @@ void patchCode(u64 progId, u8 *code, u32 size) 0xE0, 0x1E, 0xFF, 0x2F, 0xE1, 0x01, 0x01 }; - u8 mostRecentFpdVer = 0x07; + u8 mostRecentFpdVer = 7; u8 *fpdVer = memsearch(code, fpdVerPattern, size, sizeof(fpdVerPattern)); - //Allow online access to work with old friends modules, without breaking newer firmwares + //Allow online access to work with old friends modules if(fpdVer != NULL && fpdVer[9] < mostRecentFpdVer) fpdVer[9] = mostRecentFpdVer; break; @@ -391,7 +381,9 @@ void patchCode(u64 progId, u8 *code, u32 size) u32 verStringSize; u16 customVerString[19] = {0}; - if(R_SUCCEEDED(loadCustomVerString(customVerString, &verStringSize))) verString = customVerString; + loadCustomVerString(customVerString, &verStringSize); + + if(customVerString[0] != 0) verString = customVerString; else { verStringSize = 8; @@ -442,7 +434,7 @@ void patchCode(u64 progId, u8 *code, u32 size) //Patch Ver. string patchMemory(code, size, verPattern, - sizeof(verPattern) - sizeof(u16), 0, + sizeof(verPattern) - 2, 0, verString, verStringSize, 1 ); @@ -514,10 +506,10 @@ void patchCode(u64 progId, u8 *code, u32 size) //Use SecureInfo_C patchMemory(code, size, secureinfoFilenamePattern, - sizeof(secureinfoFilenamePattern) - sizeof(u16), - sizeof(secureinfoFilenamePattern) - sizeof(u16), + sizeof(secureinfoFilenamePattern) - 2, + sizeof(secureinfoFilenamePattern) - 2, secureinfoFilenamePatch, - sizeof(secureinfoFilenamePatch) - sizeof(u16), 2 + sizeof(secureinfoFilenamePatch) - 2, 2 ); } @@ -605,9 +597,7 @@ void patchCode(u64 progId, u8 *code, u32 size) default: if(CONFIG(USELANGEMUANDCODE)) { - u32 tidHigh = (progId & 0xFFFFFFF000000000LL) >> 0x24; - - if(tidHigh == 0x0004000) + if((u32)((progId & 0xFFFFFFF000000000LL) >> 0x24) == 0x0004000) { //External .code section loading loadTitleCodeSection(progId, code, size); @@ -615,11 +605,11 @@ void patchCode(u64 progId, u8 *code, u32 size) //Language emulation u8 regionId = 0xFF, languageId = 0xFF; + loadTitleLocaleConfig(progId, ®ionId, &languageId); - if(R_SUCCEEDED(loadTitleLocaleConfig(progId, ®ionId, &languageId))) + if(regionId != 0xFF || regionId != 0xFF) { u32 CFGUHandleOffset; - u8 *CFGU_GetConfigInfoBlk2_endPos = getCfgOffsets(code, size, &CFGUHandleOffset); if(CFGU_GetConfigInfoBlk2_endPos != NULL) diff --git a/loader/source/main.c b/loader/source/main.c index b902b9d..1602ac2 100644 --- a/loader/source/main.c +++ b/loader/source/main.c @@ -31,6 +31,7 @@ void main(void) memcpy(payloadAddress, (void *)0x24F00000, payloadSize); + //Ensure that all memory transfers have completed and that the caches have been flushed flushCaches(); ((void (*)())payloadAddress)(); diff --git a/source/draw.c b/source/draw.c index 0ee1030..ed9bd46 100644 --- a/source/draw.c +++ b/source/draw.c @@ -34,8 +34,8 @@ bool loadSplash(void) { - const char *topSplashPath = "/luma/splash.bin", - *bottomSplashPath = "/luma/splashbottom.bin"; + const char topSplashPath[] = "/luma/splash.bin", + bottomSplashPath[] = "/luma/splashbottom.bin"; bool isTopSplashValid = getFileSize(topSplashPath) == SCREEN_TOP_FBSIZE, isBottomSplashValid = getFileSize(bottomSplashPath) == SCREEN_BOTTOM_FBSIZE; diff --git a/source/firm.c b/source/firm.c index 2344bc1..9ecc5cc 100755 --- a/source/firm.c +++ b/source/firm.c @@ -339,7 +339,6 @@ static inline u32 loadFirm(FirmwareType *firmType, FirmwareSource firmSource) if(!fileRead(firm, "/luma/firmware.bin", 0x400000) || section[2].address != (u8 *)0x8006800) error("An old unsupported FIRM has been detected.\nCopy a valid firmware.bin in /luma to boot"); - //No assumption regarding FIRM version firmVersion = 0xFFFFFFFF; } } @@ -595,7 +594,8 @@ static inline void launchFirm(FirmwareType firmType) //Set ARM11 kernel entrypoint *arm11 = (u32)firm->arm11Entry; - flushEntireDCache(); //Ensure that all memory transfers have completed and that the data cache has been flushed + //Ensure that all memory transfers have completed and that the caches have been flushed + flushEntireDCache(); flushEntireICache(); //Final jump to ARM9 kernel diff --git a/source/pin.c b/source/pin.c index bfd8d34..4e08163 100644 --- a/source/pin.c +++ b/source/pin.c @@ -132,7 +132,7 @@ bool verifyPin(void) u8 cnt = 0; u32 charDrawPos = 16 * SPACING_X; - const char *messagePath = "/luma/pinmessage.txt"; + const char messagePath[] = "/luma/pinmessage.txt"; u32 messageSize = getFileSize(messagePath); if(messageSize > 0 && messageSize <= 800) diff --git a/source/utils.c b/source/utils.c index e38bf27..b4e2d42 100644 --- a/source/utils.c +++ b/source/utils.c @@ -58,7 +58,8 @@ void mcuReboot(void) { if(!isFirmlaunch && PDN_GPU_CNT != 1) clearScreens(true, true); - flushEntireDCache(); //Ensure that all memory transfers have completed and that the data cache has been flushed + //Ensure that all memory transfers have completed and that the data cache has been flushed + flushEntireDCache(); i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 2); while(true); @@ -68,17 +69,15 @@ void mcuPowerOff(void) { if(!isFirmlaunch && PDN_GPU_CNT != 1) clearScreens(true, true); - flushEntireDCache(); //Ensure that all memory transfers have completed and that the data cache has been flushed + //Ensure that all memory transfers have completed and that the data cache has been flushed + flushEntireDCache(); i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 0); while(true); } -//TODO: add support for TIMER IRQ static inline void startChrono(u64 initialTicks) { - //Based on a NATIVE_FIRM disassembly - REG_TIMER_CNT(0) = 0; //67MHz for(u32 i = 1; i < 4; i++) REG_TIMER_CNT(i) = 4; //Count-up