From 22a8661fe1840057d3a6a720b79659a85b50d633 Mon Sep 17 00:00:00 2001 From: TuxSH Date: Thu, 2 Nov 2017 21:52:14 +0100 Subject: [PATCH] Always patch FS and P9, remove SM service checks --- k11_extension/include/config.h | 1 - source/config.c | 6 -- source/config.h | 3 +- source/firm.c | 2 +- sysmodules/loader/source/patcher.h | 1 - .../rosalina/include/menus/process_patches.h | 5 +- sysmodules/rosalina/source/main.c | 2 + sysmodules/rosalina/source/menus.c | 3 +- .../rosalina/source/menus/process_patches.c | 72 +------------------ sysmodules/sm/source/main.c | 19 +---- sysmodules/sm/source/processes.c | 22 +----- sysmodules/sm/source/services.c | 17 ++--- 12 files changed, 17 insertions(+), 136 deletions(-) diff --git a/k11_extension/include/config.h b/k11_extension/include/config.h index 18f2bb8..e1c6392 100644 --- a/k11_extension/include/config.h +++ b/k11_extension/include/config.h @@ -31,7 +31,6 @@ enum singleOptions PATCHGAMES, PATCHVERSTRING, SHOWGBABOOT, - PATCHACCESS, PATCHUNITINFO, DISABLEARM11EXCHANDLERS }; diff --git a/source/config.c b/source/config.c index af19ca3..d8b8c98 100644 --- a/source/config.c +++ b/source/config.c @@ -91,7 +91,6 @@ void configMenu(bool oldPinStatus, u32 oldPinMode) "( ) Enable game patching", "( ) Show NAND or user string in System Settings", "( ) Show GBA boot screen in patched AGB_FIRM", - "( ) Patch ARM9 access", "( ) Set developer UNITINFO", "( ) Disable ARM11 exception handlers", }; @@ -174,10 +173,6 @@ void configMenu(bool oldPinStatus, u32 oldPinMode) "Enable showing the GBA boot screen\n" "when booting GBA games.", - "Disable ARM9 exheader access checks.\n\n" - "Only select this if you know what you\n" - "are doing!", - "Make the console be always detected\n" "as a development unit, and conversely.\n" "(which breaks online features, amiibo\n" @@ -219,7 +214,6 @@ void configMenu(bool oldPinStatus, u32 oldPinMode) { .visible = true }, { .visible = true }, { .visible = true }, - { .visible = true }, { .visible = true } }; diff --git a/source/config.h b/source/config.h index ae913dd..dfcb5d7 100644 --- a/source/config.h +++ b/source/config.h @@ -34,7 +34,7 @@ #define CONFIG_FILE "config.bin" #define CONFIG_VERSIONMAJOR 2 -#define CONFIG_VERSIONMINOR 1 +#define CONFIG_VERSIONMINOR 2 #define BOOTCFG_NAND BOOTCONFIG(0, 7) #define BOOTCFG_FIRM BOOTCONFIG(3, 7) @@ -58,7 +58,6 @@ enum singleOptions PATCHGAMES, PATCHVERSTRING, SHOWGBABOOT, - PATCHACCESS, PATCHUNITINFO, DISABLEARM11EXCHANDLERS }; diff --git a/source/firm.c b/source/firm.c index 22c55e7..3611d83 100755 --- a/source/firm.c +++ b/source/firm.c @@ -405,7 +405,7 @@ u32 patchNativeFirm(u32 firmVersion, FirmwareSource nandType, bool loadFromStora ret += patchSvcBreak9(arm9Section, kernel9Size, (u32)firm->section[2].address); ret += patchKernel9Panic(arm9Section, kernel9Size); - if(CONFIG(PATCHACCESS)) ret += patchP9AccessChecks(process9Offset, process9Size); + ret += patchP9AccessChecks(process9Offset, process9Size); mergeSection0(NATIVE_FIRM, firmVersion, loadFromStorage); firm->section[0].size = 0; diff --git a/sysmodules/loader/source/patcher.h b/sysmodules/loader/source/patcher.h index e9891c7..a4e4ee9 100644 --- a/sysmodules/loader/source/patcher.h +++ b/sysmodules/loader/source/patcher.h @@ -33,7 +33,6 @@ enum singleOptions PATCHGAMES, PATCHVERSTRING, SHOWGBABOOT, - PATCHACCESS, PATCHUNITINFO, DISABLEARM11EXCHANDLERS }; diff --git a/sysmodules/rosalina/include/menus/process_patches.h b/sysmodules/rosalina/include/menus/process_patches.h index aa2e52d..9bd9687 100644 --- a/sysmodules/rosalina/include/menus/process_patches.h +++ b/sysmodules/rosalina/include/menus/process_patches.h @@ -29,7 +29,4 @@ #include <3ds/types.h> #include "menu.h" -extern Menu processPatchesMenu; - -void ProcessPatchesMenu_PatchUnpatchSM(void); -void ProcessPatchesMenu_PatchUnpatchFS(void); +void ProcessPatchesMenu_PatchUnpatchFSDirectly(void); diff --git a/sysmodules/rosalina/source/main.c b/sysmodules/rosalina/source/main.c index 12350e4..e75ffac 100644 --- a/sysmodules/rosalina/source/main.c +++ b/sysmodules/rosalina/source/main.c @@ -85,6 +85,8 @@ void initSystem() miscellaneousMenu.items[0].title = HBLDR_3DSX_TID == HBLDR_DEFAULT_3DSX_TID ? "Switch the hb. title to the current app." : "Switch the hb. title to hblauncher_loader"; + + ProcessPatchesMenu_PatchUnpatchFSDirectly(); __sync_init(); __appInit(); } diff --git a/sysmodules/rosalina/source/menus.c b/sysmodules/rosalina/source/menus.c index dd04aa4..b66bc13 100644 --- a/sysmodules/rosalina/source/menus.c +++ b/sysmodules/rosalina/source/menus.c @@ -40,10 +40,9 @@ Menu rosalinaMenu = { "Rosalina menu", - .nbItems = 10, + .nbItems = 9, { { "Process list", METHOD, .method = &RosalinaMenu_ProcessList }, - { "Process patches menu...", MENU, .menu = &processPatchesMenu }, { "Take screenshot (slow!)", METHOD, .method = &RosalinaMenu_TakeScreenshot }, { "New 3DS menu...", MENU, .menu = &N3DSMenu }, { "Debugger options...", MENU, .menu = &debuggerMenu }, diff --git a/sysmodules/rosalina/source/menus/process_patches.c b/sysmodules/rosalina/source/menus/process_patches.c index 8b585c7..47021a8 100644 --- a/sysmodules/rosalina/source/menus/process_patches.c +++ b/sysmodules/rosalina/source/menus/process_patches.c @@ -33,44 +33,6 @@ #include "fmt.h" #include "utils.h" -Menu processPatchesMenu = { - "Process patches menu", - .nbItems = 2, - { - { "Patch SM for the service checks", METHOD, .method = &ProcessPatchesMenu_PatchUnpatchSM }, - { "Patch FS for the archive checks", METHOD, .method = &ProcessPatchesMenu_PatchUnpatchFS }, - } -}; - -static Result ProcessPatchesMenu_DoPatchUnpatchSM(u32 textTotalRoundedSize) -{ - static bool patched = false; - static u32 *off; - static u32 origData; - - if(patched) - { - *off = origData; - patched = false; - } - else - { - for(off = (u32 *)0x00100000; off < (u32 *)(0x00100000 + textTotalRoundedSize) - 3 && - (off[0] != 0xE1A01006 || (off[1] & 0xFFFF) != 5); - off++); - - if(off >= (u32 *)(0x00100000 + textTotalRoundedSize) - 3) - return -1; - - off += 2; - *off = 0xE3A00001; // mov r0, #1 - patched = true; - } - - processPatchesMenu.items[0].title = patched ? "Unpatch SM for the service checks" : "Patch SM for the service checks"; - return 0; -} - static Result ProcessPatchesMenu_DoPatchUnpatchFS(u32 textTotalRoundedSize) { static bool patched = false; @@ -101,7 +63,7 @@ static Result ProcessPatchesMenu_DoPatchUnpatchFS(u32 textTotalRoundedSize) patched = true; } - processPatchesMenu.items[1].title = patched ? "Unpatch FS for the archive checks" : "Patch FS for the archive checks"; + //processPatchesMenu.items[1].title = patched ? "Unpatch FS for the archive checks" : "Patch FS for the archive checks"; return 0; } @@ -152,35 +114,7 @@ static u32 ProcessPatchesMenu_PatchUnpatchProcessByName(const char *name, Result return res; } -static void ProcessPatchesMenu_PatchUnpatchProcess(const char *processName, Result (*func)(u32 size)) +void ProcessPatchesMenu_PatchUnpatchFSDirectly(void) { - Draw_Lock(); - Draw_ClearFramebuffer(); - Draw_FlushFramebuffer(); - Draw_Unlock(); - - Result res = ProcessPatchesMenu_PatchUnpatchProcessByName(processName, func); - - do - { - Draw_Lock(); - Draw_DrawString(10, 10, COLOR_TITLE, "Process patches menu"); - if(R_SUCCEEDED(res)) - Draw_DrawString(10, 30, COLOR_WHITE, "Operation succeeded."); - else - Draw_DrawFormattedString(10, 30, COLOR_WHITE, "Operation failed (0x%08x).", res); - Draw_FlushFramebuffer(); - Draw_Unlock(); - } - while(!(waitInput() & BUTTON_B) && !terminationRequest); -} - -void ProcessPatchesMenu_PatchUnpatchSM(void) -{ - ProcessPatchesMenu_PatchUnpatchProcess("sm", &ProcessPatchesMenu_DoPatchUnpatchSM); -} - -void ProcessPatchesMenu_PatchUnpatchFS(void) -{ - ProcessPatchesMenu_PatchUnpatchProcess("fs", &ProcessPatchesMenu_DoPatchUnpatchFS); + ProcessPatchesMenu_PatchUnpatchProcessByName("fs", &ProcessPatchesMenu_DoPatchUnpatchFS); } diff --git a/sysmodules/sm/source/main.c b/sysmodules/sm/source/main.c index 298f950..553bca2 100644 --- a/sysmodules/sm/source/main.c +++ b/sysmodules/sm/source/main.c @@ -13,13 +13,6 @@ This is part of 3ds_sm, which is licensed under the MIT license (see LICENSE for #include "srv_pm.h" #include "list.h" -extern u32 __ctru_heap; -extern u32 __ctru_linear_heap; -extern char (*serviceAccessListBuffers)[34][8]; - -u32 __ctru_heap_size = 0x4000; -u32 __ctru_linear_heap_size = 0; - u32 nbSection0Modules; Handle resumeGetServiceHandleOrPortRegisteredSemaphore; @@ -43,7 +36,6 @@ void __appInit(void) svcGetSystemInfo(&out, 26, 0); nbSection0Modules = out; assertSuccess(svcCreateSemaphore(&resumeGetServiceHandleOrPortRegisteredSemaphore, 0, 64)); - serviceAccessListBuffers = (char (*)[34][8])__ctru_heap; buildList(&freeSessionDataList, sessionDataPool, sizeof(sessionDataPool) / sizeof(SessionData), sizeof(SessionData)); buildList(&freeProcessDataList, processDataPool, sizeof(processDataPool) / sizeof(ProcessData), sizeof(ProcessData)); @@ -53,16 +45,7 @@ void __appInit(void) // this is called after main exits void __appExit(void){} -void __system_allocateHeaps(void) -{ - u32 tmp = 0; - - // Allocate the application heap - __ctru_heap = 0x08000000; - svcControlMemory(&tmp, __ctru_heap, 0x0, __ctru_heap_size, MEMOP_ALLOC, MEMPERM_READ | MEMPERM_WRITE); - - __ctru_linear_heap = 0; -} +void __system_allocateHeaps(void){} void __system_initSyscalls(void){} diff --git a/sysmodules/sm/source/processes.c b/sysmodules/sm/source/processes.c index 3f92071..b4f7236 100644 --- a/sysmodules/sm/source/processes.c +++ b/sysmodules/sm/source/processes.c @@ -10,10 +10,6 @@ This is part of 3ds_sm, which is licensed under the MIT license (see LICENSE for #include "services.h" ProcessDataList processDataInUseList = { NULL, NULL }, freeProcessDataList = { NULL, NULL }; -char (*serviceAccessListBuffers)[34][8]; - -// The kernel limits the number of processes to 47 anyways... -static u64 freeServiceAccessListBuffersIds = (1ULL << 59) - 1; ProcessData *findProcessData(u32 pid) { @@ -28,20 +24,10 @@ ProcessData *findProcessData(u32 pid) ProcessData *doRegisterProcess(u32 pid, char (*serviceAccessList)[8], u32 serviceAccessListSize) { + (void)serviceAccessList; // Service access list checks removed for Luma3DS, see original 3ds_sm for implementation details. + (void)serviceAccessListSize; + ProcessData *processData = (ProcessData *)allocateNode(&processDataInUseList, &freeProcessDataList, sizeof(ProcessData), false); - if(serviceAccessListSize != 0) - { - s32 bufferId = 63 - __builtin_clzll(freeServiceAccessListBuffersIds); - if(bufferId == -1) - panic(); - else - { - freeServiceAccessListBuffersIds &= ~(1ULL << bufferId); - processData->serviceAccessList = serviceAccessListBuffers[bufferId]; - processData->serviceAccessListSize = serviceAccessListSize; - memcpy(processData->serviceAccessList, serviceAccessList, serviceAccessListSize); - } - } assertSuccess(svcCreateSemaphore(&processData->notificationSemaphore, 0, 0x10)); processData->pid = pid; @@ -81,8 +67,6 @@ Result UnregisterProcess(u32 pid) } } - freeServiceAccessListBuffersIds |= 1ULL << (u32)((processData->serviceAccessList - serviceAccessListBuffers[0]) / 34); - moveNode(processData, &freeProcessDataList, false); return 0; } diff --git a/sysmodules/sm/source/services.c b/sysmodules/sm/source/services.c index 25d422d..7fedeaf 100644 --- a/sysmodules/sm/source/services.c +++ b/sysmodules/sm/source/services.c @@ -38,20 +38,11 @@ static s32 findServicePortByName(bool isNamedPort, const char *name, s32 nameSiz static bool checkServiceAccess(SessionData *sessionData, const char *name, s32 nameSize) { - if(sessionData->pid < nbSection0Modules) - return true; + (void)sessionData; + (void)name; + (void)nameSize; - ProcessData *processData = findProcessData(sessionData->pid); - if(processData == NULL) - return false; - - for(u32 i = 0; i < processData->serviceAccessListSize; i++) - { - if(areServiceNamesEqual(processData->serviceAccessList[i], name, nameSize)) - return true; - } - - return false; + return true; // Service access list checks removed for Luma3DS, see original 3ds_sm for implementation details. } static Result doRegisterServiceOrPort(u32 pid, Handle *serverPort, Handle clientPort, const char *name, s32 nameSize, s32 maxSessions, bool isNamedPort)