From 8ffeb1e9d578b440ffea427663f3f3b0916b0dae Mon Sep 17 00:00:00 2001 From: PabloMK7 Date: Tue, 17 Dec 2019 16:48:05 +0100 Subject: [PATCH] Fix plugin loader compatibility --- Makefile | 2 +- source/csvc.h | 12 ++++++++++++ source/csvc.s | 8 ++++++++ source/ntr_launcher.c | 14 +++++++++++++- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b4e827a..8b797aa 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ LIBRARIES := citro3d ctru png z m VERSION_MAJOR := 2 VERSION_MINOR := 13 -VERSION_MICRO := 2 +VERSION_MICRO := 3 diff --git a/source/csvc.h b/source/csvc.h index e4c7ff9..a310b22 100644 --- a/source/csvc.h +++ b/source/csvc.h @@ -67,6 +67,18 @@ void svcInvalidateInstructionCacheRange(void *addr, u32 len); void svcInvalidateEntireInstructionCache(void); ///@} +///@name Memory management +///@{ +/** + * @brief Maps a block of process memory. + * @param dstProcessHandle Handle of the process to map the memory in (destination) + * @param destAddress Start address of the memory block in the destination process + * @param srcProcessHandle Handle of the process to map the memory from (source) + * @param srcAddress Start address of the memory block in the source process + * @param size Size of the block of the memory to map (truncated to a multiple of 0x1000 bytes) +*/ +Result svcMapProcessMemoryExPluginLoader(Handle dstProcessHandle, u32 destAddress, Handle srcProcessHandle, u32 srcAddress, u32 size); + ///@name Memory management ///@{ /** diff --git a/source/csvc.s b/source/csvc.s index 658992f..cf63d0c 100644 --- a/source/csvc.s +++ b/source/csvc.s @@ -63,6 +63,14 @@ SVC_BEGIN svcMapProcessMemoryEx bx lr SVC_END +SVC_BEGIN svcMapProcessMemoryExPluginLoader + str r4, [sp, #-4]! + ldr r4, [sp, #4] + svc 0xA0 + ldr r4, [sp], #4 + bx lr +SVC_END + SVC_BEGIN svcUnmapProcessMemoryEx svc 0xA1 bx lr diff --git a/source/ntr_launcher.c b/source/ntr_launcher.c index 7d6653f..9087a6e 100644 --- a/source/ntr_launcher.c +++ b/source/ntr_launcher.c @@ -29,9 +29,20 @@ int isNTRAlreadyLaunched(void) return (RESULT_ERROR); } +bool isPluginLoaderLuma() { + Handle tmpHandle; + Result res = svcConnectToPort(&tmpHandle, "plg:ldr"); + if (!res) { + svcCloseHandle(tmpHandle); + return true; + } + return false; +} + u32 findCustomPMsvcRunPattern(u32* outaddr) { Handle prochand; + bool isPlgLoader = isPluginLoaderLuma(); u32 textStart = 0; *outaddr = 0; u32 res = 0; @@ -53,7 +64,8 @@ u32 findCustomPMsvcRunPattern(u32* outaddr) { return res; } - res = svcMapProcessMemoryEx(prochand, 0x28000000, (u32)addr, (u32)info); //map PM process memory into this process @ 0x08000000 + if (isPlgLoader) res = svcMapProcessMemoryExPluginLoader(CURRENT_PROCESS_HANDLE, 0x28000000, prochand, (u32)addr, (u32)info); + else res = svcMapProcessMemoryEx(prochand, 0x28000000, (u32)addr, (u32)info); //map PM process memory into this process @ 0x08000000 if (res) { return res;