From dd6e071ddead5dacdcf3e8be7a0671f4392c4b9f Mon Sep 17 00:00:00 2001 From: Nanquitas Date: Thu, 5 Jul 2018 22:01:53 +0200 Subject: [PATCH 1/8] socAccept: Fix an omitted comment, which masked a condition --- sysmodules/rosalina/source/minisoc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sysmodules/rosalina/source/minisoc.c b/sysmodules/rosalina/source/minisoc.c index 06f04cc..d41fb6d 100644 --- a/sysmodules/rosalina/source/minisoc.c +++ b/sysmodules/rosalina/source/minisoc.c @@ -314,7 +314,7 @@ int socAccept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) if(ret == 0) ret = _net_convert_error(cmdbuf[2]); - if(ret < 0) + // if(ret < 0) //errno = -ret; if(ret >= 0 && addr != NULL) From 89cc6ede1a5dc3f846cf508c5f698a869e9e1018 Mon Sep 17 00:00:00 2001 From: Aurora Wright Date: Tue, 31 Jul 2018 04:32:29 +0200 Subject: [PATCH 2/8] Fix patchKernel9Panic on 11.8 NATIVE_FIRM (pattern tested down to 3.0) --- source/patches.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/patches.c b/source/patches.c index 6968711..38966b0 100644 --- a/source/patches.c +++ b/source/patches.c @@ -508,13 +508,13 @@ u32 patchSvcBreak9(u8 *pos, u32 size, u32 kernel9Address) u32 patchKernel9Panic(u8 *pos, u32 size) { - static const u8 pattern[] = {0xFF, 0xEA, 0x04, 0xD0}; + static const u8 pattern[] = {0x00, 0x20, 0x92, 0x15}; u8 *temp = memsearch(pos, pattern, size, sizeof(pattern)); if(temp == NULL) return 1; - u32 *off = (u32 *)(temp - 0x12); + u32 *off = (u32 *)(temp - 0x34); *off = 0xE12FFF7E; return 0; From bc06b1782335c3bb018e0e779f605e362800603e Mon Sep 17 00:00:00 2001 From: tstambaugh92 <42028641+tstambaugh92@users.noreply.github.com> Date: Tue, 7 Aug 2018 06:50:48 -0400 Subject: [PATCH 3/8] Fixed cheat functionality (#1116) Fixed functionality of BXXXXXXX codes --- sysmodules/rosalina/source/menus/cheats.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sysmodules/rosalina/source/menus/cheats.c b/sysmodules/rosalina/source/menus/cheats.c index 64351bb..beb543f 100644 --- a/sysmodules/rosalina/source/menus/cheats.c +++ b/sysmodules/rosalina/source/menus/cheats.c @@ -468,7 +468,9 @@ static u32 Cheat_ApplyCheat(const Handle processHandle, const CheatDescription* // Description: Loads offset register. if (!skipExecution) { - cheat_state.offset = (arg0 & 0x0FFFFFFF); + u32 value; + if (!Cheat_Read32(processHandle, arg0 & 0x0FFFFFFF, &value)) return 0; + cheat_state.offset = value; } break; case 0xC: From 2219b19d5f60b8680fcbbbb868db7077bc406ed4 Mon Sep 17 00:00:00 2001 From: tstambaugh92 <42028641+tstambaugh92@users.noreply.github.com> Date: Thu, 9 Aug 2018 08:21:16 -0400 Subject: [PATCH 4/8] Fixed cheat functionality (#1117) --- sysmodules/rosalina/include/menus/cheats.h | 2 +- sysmodules/rosalina/source/menu.c | 4 +--- sysmodules/rosalina/source/menus/cheats.c | 14 +++++++------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/sysmodules/rosalina/include/menus/cheats.h b/sysmodules/rosalina/include/menus/cheats.h index cd66c6c..b95e36c 100644 --- a/sysmodules/rosalina/include/menus/cheats.h +++ b/sysmodules/rosalina/include/menus/cheats.h @@ -33,4 +33,4 @@ #define CHEATS_PER_MENU_PAGE 18 void RosalinaMenu_Cheats(void); -void Cheat_ApplyKeyCheats(); +void Cheat_ApplyCheats(); diff --git a/sysmodules/rosalina/source/menu.c b/sysmodules/rosalina/source/menu.c index ae32bf3..7d1145e 100644 --- a/sysmodules/rosalina/source/menu.c +++ b/sysmodules/rosalina/source/menu.c @@ -169,9 +169,7 @@ void menuThreadMain(void) } else { - if (HID_PAD & 0xFFF) { - Cheat_ApplyKeyCheats(); - } + Cheat_ApplyCheats(); } svcSleepThread(50 * 1000 * 1000LL); } diff --git a/sysmodules/rosalina/source/menus/cheats.c b/sysmodules/rosalina/source/menus/cheats.c index beb543f..ed8cad9 100644 --- a/sysmodules/rosalina/source/menus/cheats.c +++ b/sysmodules/rosalina/source/menus/cheats.c @@ -465,7 +465,7 @@ static u32 Cheat_ApplyCheat(const Handle processHandle, const CheatDescription* case 0xB: // B Type // Format: BXXXXXXX 00000000 - // Description: Loads offset register. + // Description: Loads offset register with value at given XXXXXXX if (!skipExecution) { u32 value; @@ -1120,16 +1120,12 @@ static u32 Cheat_GetCurrentPID(u64* titleId) } } -void Cheat_ApplyKeyCheats(void) +void Cheat_ApplyCheats(void) { if (!cheatCount) { return; } - if (!hasKeyActivated) - { - return; - } u64 titleId = 0; u32 pid = Cheat_GetCurrentPID(&titleId); @@ -1151,9 +1147,13 @@ void Cheat_ApplyKeyCheats(void) u32 keys = HID_PAD & 0xFFF; for (int i = 0; i < cheatCount; i++) { - if (cheats[i]->active && cheats[i]->keyActivated && (cheats[i]->keyCombo & keys) == keys) + if (cheats[i]->active && !(cheats[i]->keyActivated)) { Cheat_MapMemoryAndApplyCheat(pid, cheats[i]); + } + else if (cheats[i]->active && cheats[i]->keyActivated && (cheats[i]->keyCombo & keys) == keys) + { + Cheat_MapMemoryAndApplyCheat(pid, cheats[i]); } } } From 53622d777bd22e5384c3779d66369b476991a83a Mon Sep 17 00:00:00 2001 From: Aurora Wright Date: Tue, 21 Aug 2018 18:57:45 +0200 Subject: [PATCH 5/8] Fix https://github.com/AuroraWright/Luma3DS/issues/1095 and https://github.com/AuroraWright/Luma3DS/issues/1118 --- k11_extension/source/svc/GetSystemInfo.c | 2 +- source/firm.c | 4 ++-- source/firm.h | 2 +- source/main.c | 15 ++++++++++++--- source/patches.c | 4 ++-- source/patches.h | 2 +- sysmodules/loader/source/loader.c | 6 +++--- sysmodules/loader/source/patcher.h | 2 +- 8 files changed, 23 insertions(+), 14 deletions(-) diff --git a/k11_extension/source/svc/GetSystemInfo.c b/k11_extension/source/svc/GetSystemInfo.c index 9cb8b51..52c5c32 100644 --- a/k11_extension/source/svc/GetSystemInfo.c +++ b/k11_extension/source/svc/GetSystemInfo.c @@ -71,7 +71,7 @@ Result GetSystemInfoHook(s64 *out, s32 type, s32 param) case 0x201: // isN3DS *out = (cfwInfo.flags >> 4) & 1; break; - case 0x202: // isSafeMode + case 0x202: // needToInitSd *out = (cfwInfo.flags >> 5) & 1; break; case 0x203: // isSdMode diff --git a/source/firm.c b/source/firm.c index c6d73dd..430d61c 100755 --- a/source/firm.c +++ b/source/firm.c @@ -344,7 +344,7 @@ static inline void mergeSection0(FirmwareType firmType, u32 firmVersion, bool lo } } -u32 patchNativeFirm(u32 firmVersion, FirmwareSource nandType, bool loadFromStorage, bool isFirmProtEnabled, bool isSafeMode, bool doUnitinfoPatch) +u32 patchNativeFirm(u32 firmVersion, FirmwareSource nandType, bool loadFromStorage, bool isFirmProtEnabled, bool needToInitSd, bool doUnitinfoPatch) { u8 *arm9Section = (u8 *)firm + firm->section[2].offset, *arm11Section1 = (u8 *)firm + firm->section[1].offset; @@ -374,7 +374,7 @@ u32 patchNativeFirm(u32 firmVersion, FirmwareSource nandType, bool loadFromStora //Skip on FIRMs < 4.0 if(ISN3DS || firmVersion >= 0x1D) { - ret += installK11Extension(arm11Section1, firm->section[1].size, isSafeMode, baseK11VA, arm11ExceptionsPage, &freeK11Space); + ret += installK11Extension(arm11Section1, firm->section[1].size, needToInitSd, baseK11VA, arm11ExceptionsPage, &freeK11Space); ret += patchKernel11(arm11Section1, firm->section[1].size, baseK11VA, arm11SvcTable, arm11ExceptionsPage); } diff --git a/source/firm.h b/source/firm.h index f1a6e98..5299a42 100644 --- a/source/firm.h +++ b/source/firm.h @@ -31,7 +31,7 @@ u32 loadNintendoFirm(FirmwareType *firmType, FirmwareSource nandType, bool loadFromStorage, bool isSafeMode); void loadHomebrewFirm(u32 pressed); -u32 patchNativeFirm(u32 firmVersion, FirmwareSource nandType, bool loadFromStorage, bool isFirmProtEnabled, bool isSafeMode, bool doUnitinfoPatch); +u32 patchNativeFirm(u32 firmVersion, FirmwareSource nandType, bool loadFromStorage, bool isFirmProtEnabled, bool needToInitSd, bool doUnitinfoPatch); u32 patchTwlFirm(u32 firmVersion, bool loadFromStorage, bool doUnitinfoPatch); u32 patchAgbFirm(bool loadFromStorage, bool doUnitinfoPatch); u32 patch1x2xNativeAndSafeFirm(void); diff --git a/source/main.c b/source/main.c index 120b8ae..15c0cc3 100644 --- a/source/main.c +++ b/source/main.c @@ -51,6 +51,7 @@ void main(int argc, char **argv, u32 magicWord) { bool isFirmProtEnabled, isSafeMode = false, + needToInitSd = false, isNoForceFlagSet = false, isNtrBoot; FirmwareType firmType; @@ -192,9 +193,16 @@ void main(int argc, char **argv, u32 magicWord) goto boot; } - /* Else, force the last used boot options unless a button is pressed + //Account for DSiWare soft resets if exiting TWL_FIRM + if(CFG_BOOTENV == 3) + { + static const u8 TLNC[] = {0x54, 0x4C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4E, 0x43}; + if(memcmp((void *)0x20000C00, TLNC, 10) == 0) needToInitSd = true; + } + + /* Force the last used boot options if autobooting a TWL title, or unless a button is pressed or the no-forcing flag is set */ - if(!pressed && !BOOTCFG_NOFORCEFLAG) + if(needToInitSd || memcmp((void *)0x20000300, "TLNC", 4) == 0 || (!pressed && !BOOTCFG_NOFORCEFLAG)) { nandType = (FirmwareSource)BOOTCFG_NAND; firmSource = (FirmwareSource)BOOTCFG_FIRM; @@ -223,6 +231,7 @@ void main(int argc, char **argv, u32 magicWord) firmSource = FIRMWARE_SYSNAND; isSafeMode = true; + needToInitSd = true; //If the PIN has been verified, wait to make it easier to press the SAFE_MODE combo if(pinExists && !shouldLoadConfigMenu) @@ -328,7 +337,7 @@ boot: switch(firmType) { case NATIVE_FIRM: - res = patchNativeFirm(firmVersion, nandType, loadFromStorage, isFirmProtEnabled, isSafeMode, doUnitinfoPatch); + res = patchNativeFirm(firmVersion, nandType, loadFromStorage, isFirmProtEnabled, needToInitSd, doUnitinfoPatch); break; case TWL_FIRM: res = patchTwlFirm(firmVersion, loadFromStorage, doUnitinfoPatch); diff --git a/source/patches.c b/source/patches.c index 38966b0..af6fcf9 100644 --- a/source/patches.c +++ b/source/patches.c @@ -100,7 +100,7 @@ static inline u32 *getKernel11HandlerVAPos(u8 *pos, u32 *arm11ExceptionsPage, u3 return (u32 *)(pos + pointedInstructionVA - baseK11VA + 8); } -u32 installK11Extension(u8 *pos, u32 size, bool isSafeMode, u32 baseK11VA, u32 *arm11ExceptionsPage, u8 **freeK11Space) +u32 installK11Extension(u8 *pos, u32 size, bool needToInitSd, u32 baseK11VA, u32 *arm11ExceptionsPage, u8 **freeK11Space) { //The parameters to be passed on to the kernel ext //Please keep that in sync with the definition in k11_extension/source/main.c @@ -201,7 +201,7 @@ u32 installK11Extension(u8 *pos, u32 size, bool isSafeMode, u32 baseK11VA, u32 * if(ISRELEASE) info->flags = 1; if(ISN3DS) info->flags |= 1 << 4; - if(isSafeMode) info->flags |= 1 << 5; + if(needToInitSd) info->flags |= 1 << 5; if(isSdMode) info->flags |= 1 << 6; return 0; diff --git a/source/patches.h b/source/patches.h index 1382125..c7ae877 100644 --- a/source/patches.h +++ b/source/patches.h @@ -39,7 +39,7 @@ u8 *getProcess9Info(u8 *pos, u32 size, u32 *process9Size, u32 *process9MemAddr); u32 *getKernel11Info(u8 *pos, u32 size, u32 *baseK11VA, u8 **freeK11Space, u32 **arm11SvcHandler, u32 **arm11ExceptionsPage); -u32 installK11Extension(u8 *pos, u32 size, bool isSafeMode, u32 baseK11VA, u32 *arm11ExceptionsPage, u8 **freeK11Space); +u32 installK11Extension(u8 *pos, u32 size, bool needToInitSd, u32 baseK11VA, u32 *arm11ExceptionsPage, u8 **freeK11Space); u32 patchKernel11(u8 *pos, u32 size, u32 baseK11VA, u32 *arm11SvcTable, u32 *arm11ExceptionsPage); u32 patchSignatureChecks(u8 *pos, u32 size); u32 patchOldSignatureChecks(u8 *pos, u32 size); diff --git a/sysmodules/loader/source/loader.c b/sysmodules/loader/source/loader.c index ec0f0c2..7370c7c 100644 --- a/sysmodules/loader/source/loader.c +++ b/sysmodules/loader/source/loader.c @@ -12,7 +12,7 @@ #define HBLDR_3DSX_TID (*(vu64 *)0x1FF81100) u32 config, multiConfig, bootConfig; -bool isN3DS, isSafeMode, isSdMode; +bool isN3DS, needToInitSd, isSdMode; const char CODE_PATH[] = {0x01, 0x00, 0x00, 0x00, 0x2E, 0x63, 0x6F, 0x64, 0x65, 0x00, 0x00, 0x00}; @@ -47,12 +47,12 @@ static inline void loadCFWInfo(void) if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 0x201))) svcBreak(USERBREAK_ASSERT); isN3DS = (bool)out; if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 0x202))) svcBreak(USERBREAK_ASSERT); - isSafeMode = (bool)out; + needToInitSd = (bool)out; if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 0x203))) svcBreak(USERBREAK_ASSERT); isSdMode = (bool)out; IFile file; - if(isSafeMode) fileOpen(&file, ARCHIVE_SDMC, "/", FS_OPEN_READ); //Init SD card if SAFE_MODE is being booted + if(needToInitSd) fileOpen(&file, ARCHIVE_SDMC, "/", FS_OPEN_READ); //Init SD card if SAFE_MODE is being booted } static int lzss_decompress(u8 *end) diff --git a/sysmodules/loader/source/patcher.h b/sysmodules/loader/source/patcher.h index e2eebd7..3fceb0d 100644 --- a/sysmodules/loader/source/patcher.h +++ b/sysmodules/loader/source/patcher.h @@ -39,7 +39,7 @@ enum singleOptions }; extern u32 config, multiConfig, bootConfig; -extern bool isN3DS, isSafeMode, isSdMode; +extern bool isN3DS, needToInitSd, isSdMode; void patchCode(u64 progId, u16 progVer, u8 *code, u32 size, u32 textSize, u32 roSize, u32 dataSize, u32 roAddress, u32 dataAddress); Result fileOpen(IFile *file, FS_ArchiveID archiveId, const char *path, int flags); From 3903ac640987ab29984dfb6ace0afd1a419ae494 Mon Sep 17 00:00:00 2001 From: Aurora Wright Date: Tue, 21 Aug 2018 22:07:18 +0200 Subject: [PATCH 6/8] Implement https://github.com/AuroraWright/Luma3DS/issues/470 --- source/config.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/config.c b/source/config.c index 14aba08..0dabbf0 100644 --- a/source/config.c +++ b/source/config.c @@ -31,6 +31,7 @@ #include "utils.h" #include "screen.h" #include "draw.h" +#include "emunand.h" #include "buttons.h" #include "pin.h" @@ -196,6 +197,13 @@ void configMenu(bool oldPinStatus, u32 oldPinMode) "GitHub repository!" }; + FirmwareSource nandType = FIRMWARE_SYSNAND; + if(isSdMode) + { + nandType = FIRMWARE_EMUNAND; + locateEmuNand(&nandType); + } + struct multiOption { u32 posXs[4]; u32 posY; From 1052e04679ceb5a98713da5070e3061bfdf48644 Mon Sep 17 00:00:00 2001 From: luigoalma Date: Mon, 10 Sep 2018 19:57:14 +0100 Subject: [PATCH 7/8] Added Patch to Process9 11.8 to the new AMPXI function Patch it to call __rt_memclr instead of internal PRNG when generating Key and IV. Only if UNITINFO is set, preventing on regular console usage NIM sending to nintendo a 0 Key and IV, and allowing nintendo to know who has a patched console. --- source/firm.c | 3 +++ source/patches.c | 22 ++++++++++++++++++++++ source/patches.h | 1 + 3 files changed, 26 insertions(+) diff --git a/source/firm.c b/source/firm.c index 430d61c..259cca7 100755 --- a/source/firm.c +++ b/source/firm.c @@ -400,6 +400,9 @@ u32 patchNativeFirm(u32 firmVersion, FirmwareSource nandType, bool loadFromStora //Apply anti-anti-DG patches on 11.0+ if(firmVersion >= (ISN3DS ? 0x21 : 0x52)) ret += patchTitleInstallMinVersionChecks(process9Offset, process9Size, firmVersion); + //patch P9 AM ticket wrapper on 11.8+ to use 0 Key and IV, only on UNITINFO patch to prevent NIM from actually send any + if(doUnitinfoPatch && firmVersion >= (ISN3DS ? 0x35 : 0x64)) ret += patchP9AMTicketWrapperZeroKeyIV(process9Offset, process9Size); + //Apply UNITINFO patches if(doUnitinfoPatch) { diff --git a/source/patches.c b/source/patches.c index af6fcf9..b4418d1 100644 --- a/source/patches.c +++ b/source/patches.c @@ -668,3 +668,25 @@ u32 patchAgbBootSplash(u8 *pos, u32 size) return 0; } + +u32 patchP9AMTicketWrapperZeroKeyIV(u8* pos, u32 size) +{ + static const u8 __rt_memclr_pattern[] = {0x00, 0x20, 0xA0, 0xE3, 0x04, 0x00, 0x51, 0xE3, 0x07, 0x00, 0x00, 0x3A}; + static const u8 pattern[] = {0x20, 0x21, 0xA6, 0xA8}; + + u32 function = (u32)memsearch(pos, __rt_memclr_pattern, size, sizeof(__rt_memclr_pattern)); + u32 *off = (u32*)memsearch(pos, pattern, size, sizeof(pattern)); + + if(function == 0 || off == NULL) return 1; + + s32 opjumpdistance = (s32)(function - ((u32)&off[2])) / 2; + + //beyond limit + if(opjumpdistance < -0x1fffff || opjumpdistance > 0x1fffff) return 1; + + //r0 and r1 for old call are already correctly for this one + //BLX __rt_memclr + off[1] = 0xE800F000U | (((u32)opjumpdistance & 0x7FF) << 16) | (((u32)opjumpdistance >> 11) & 0x3FF) | (((u32)opjumpdistance >> 21) & 0x400); + + return 0; +} \ No newline at end of file diff --git a/source/patches.h b/source/patches.h index c7ae877..0b62a09 100644 --- a/source/patches.h +++ b/source/patches.h @@ -64,3 +64,4 @@ u32 patchTwlFlashcartChecks(u8 *pos, u32 size, u32 firmVersion); u32 patchOldTwlFlashcartChecks(u8 *pos, u32 size); u32 patchTwlShaHashChecks(u8 *pos, u32 size); u32 patchAgbBootSplash(u8 *pos, u32 size); +u32 patchP9AMTicketWrapperZeroKeyIV(u8* pos, u32 size); From bd15f51af319e56b6812efd622ed2fd4651f978f Mon Sep 17 00:00:00 2001 From: Aurora Date: Fri, 28 Sep 2018 03:08:35 +0200 Subject: [PATCH 8/8] Fix incomplete commit (https://github.com/AuroraWright/Luma3DS/commit/3903ac640987ab29984dfb6ace0afd1a419ae494) --- source/config.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/config.c b/source/config.c index 0dabbf0..0477d29 100644 --- a/source/config.c +++ b/source/config.c @@ -210,7 +210,7 @@ void configMenu(bool oldPinStatus, u32 oldPinMode) u32 enabled; bool visible; } multiOptions[] = { - { .visible = isSdMode }, + { .visible = nandType == FIRMWARE_EMUNAND }, { .visible = true }, { .visible = true }, { .visible = true }, @@ -223,8 +223,8 @@ void configMenu(bool oldPinStatus, u32 oldPinMode) bool enabled; bool visible; } singleOptions[] = { - { .visible = isSdMode }, - { .visible = isSdMode }, + { .visible = nandType == FIRMWARE_EMUNAND }, + { .visible = nandType == FIRMWARE_EMUNAND }, { .visible = true }, { .visible = true }, { .visible = true },