Skip to content

Commit

Permalink
Fix plugin loader compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mariohackandglitch committed Dec 17, 2019
1 parent b138e1c commit 8ffeb1e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ LIBRARIES := citro3d ctru png z m

VERSION_MAJOR := 2
VERSION_MINOR := 13
VERSION_MICRO := 2
VERSION_MICRO := 3



Expand Down
12 changes: 12 additions & 0 deletions source/csvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
///@{
/**
Expand Down
8 changes: 8 additions & 0 deletions source/csvc.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion source/ntr_launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 8ffeb1e

Please sign in to comment.