move patches to pm
This commit is contained in:
parent
ae1f85d341
commit
e688ec9257
@ -84,8 +84,6 @@ void postprocessSvc(void)
|
|||||||
officialPostProcessSvc();
|
officialPostProcessSvc();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool doingVeryShittyPmResLimitWorkaround = false; // I feel dirty
|
|
||||||
|
|
||||||
void *svcHook(u8 *pageEnd)
|
void *svcHook(u8 *pageEnd)
|
||||||
{
|
{
|
||||||
KProcess *currentProcess = currentCoreContext->objectContext.currentProcess;
|
KProcess *currentProcess = currentCoreContext->objectContext.currentProcess;
|
||||||
@ -97,13 +95,6 @@ void *svcHook(u8 *pageEnd)
|
|||||||
{
|
{
|
||||||
case 0x01:
|
case 0x01:
|
||||||
return ControlMemoryHookWrapper;
|
return ControlMemoryHookWrapper;
|
||||||
case 0x17:
|
|
||||||
if(strcmp(codeSetOfProcess(currentProcess)->processName, "pm") == 0) // only called twice in pm, by the same function
|
|
||||||
{
|
|
||||||
*(vu32 *)(configPage + 0x44) += __end__ - __start__;
|
|
||||||
doingVeryShittyPmResLimitWorkaround = true;
|
|
||||||
}
|
|
||||||
return officialSVCs[0x17];
|
|
||||||
case 0x29:
|
case 0x29:
|
||||||
return GetHandleInfoHookWrapper;
|
return GetHandleInfoHookWrapper;
|
||||||
case 0x2A:
|
case 0x2A:
|
||||||
@ -124,13 +115,6 @@ void *svcHook(u8 *pageEnd)
|
|||||||
return SetGpuProt;
|
return SetGpuProt;
|
||||||
case 0x5A:
|
case 0x5A:
|
||||||
return SetWifiEnabled;
|
return SetWifiEnabled;
|
||||||
case 0x79:
|
|
||||||
if(doingVeryShittyPmResLimitWorkaround)
|
|
||||||
{
|
|
||||||
*(vu32 *)(configPage + 0x44) -= __end__ - __start__;
|
|
||||||
doingVeryShittyPmResLimitWorkaround = false;
|
|
||||||
}
|
|
||||||
return officialSVCs[0x79];
|
|
||||||
case 0x7B:
|
case 0x7B:
|
||||||
return Backdoor;
|
return Backdoor;
|
||||||
case 0x7C:
|
case 0x7C:
|
||||||
|
@ -28,26 +28,6 @@ static u64 g_cached_prog_handle;
|
|||||||
static ExHeader_Info g_exheader;
|
static ExHeader_Info g_exheader;
|
||||||
static char g_ret_buf[1024];
|
static char g_ret_buf[1024];
|
||||||
|
|
||||||
// MAKE SURE fsreg has been init before calling this
|
|
||||||
static Result fsldrPatchPermissions(void)
|
|
||||||
{
|
|
||||||
u32 pid;
|
|
||||||
Result res;
|
|
||||||
FS_ProgramInfo info;
|
|
||||||
ExHeader_Arm11StorageInfo storageInfo = {
|
|
||||||
.fs_access_info = FSACCESS_NANDRW | FSACCESS_NANDRO_RO | FSACCESS_SDMC_RW,
|
|
||||||
};
|
|
||||||
|
|
||||||
info.programId = 0x0004013000001302LL; // loader PID
|
|
||||||
info.mediaType = MEDIATYPE_NAND;
|
|
||||||
res = svcGetProcessId(&pid, CUR_PROCESS_HANDLE);
|
|
||||||
if (R_SUCCEEDED(res))
|
|
||||||
{
|
|
||||||
res = FSREG_Register(pid, 0xFFFF000000000000LL, &info, &storageInfo);
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void loadCFWInfo(void)
|
static inline void loadCFWInfo(void)
|
||||||
{
|
{
|
||||||
s64 out;
|
s64 out;
|
||||||
@ -585,8 +565,10 @@ void __appInit()
|
|||||||
svcBreak(USERBREAK_PANIC);
|
svcBreak(USERBREAK_PANIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
fsRegInit();
|
// Wait for pm to call fs:REG Register on us
|
||||||
fsldrPatchPermissions();
|
bool registered = false;
|
||||||
|
while (srvIsServiceRegistered(®istered, "pm:app"), registered)
|
||||||
|
svcSleepThread(500 * 1000LL);
|
||||||
|
|
||||||
//fsldrInit();
|
//fsldrInit();
|
||||||
res = srvGetServiceHandle(fsGetSessionHandle(), "fs:LDR");
|
res = srvGetServiceHandle(fsGetSessionHandle(), "fs:LDR");
|
||||||
|
@ -737,17 +737,6 @@ void patchCode(u64 progId, u16 progVer, u8 *code, u32 size, u32 textSize, u32 ro
|
|||||||
|
|
||||||
memset(start, 0, end - start);
|
memset(start, 0, end - start);
|
||||||
}
|
}
|
||||||
|
|
||||||
s64 nbSection0Modules;
|
|
||||||
svcGetSystemInfo(&nbSection0Modules, 26, 0);
|
|
||||||
|
|
||||||
if(nbSection0Modules == 6)
|
|
||||||
{
|
|
||||||
// Makes ErrDisp to not start up
|
|
||||||
static const u64 errDispTid = 0x0004003000008A02ULL;
|
|
||||||
u32 *errDispTidLoc = (u32 *)memsearch(code, &errDispTid, size, sizeof(errDispTid));
|
|
||||||
*(errDispTidLoc - 6) = 0xE3A00000; // mov r0, #0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(progId == 0x0004013000001702LL) //CFG
|
else if(progId == 0x0004013000001702LL) //CFG
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "exheader_info_heap.h"
|
#include "exheader_info_heap.h"
|
||||||
#include "task_runner.h"
|
#include "task_runner.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "luma.h"
|
||||||
|
|
||||||
static inline void removeAccessToService(const char *service, char (*serviceAccessList)[8])
|
static inline void removeAccessToService(const char *service, char (*serviceAccessList)[8])
|
||||||
{
|
{
|
||||||
@ -204,6 +205,11 @@ static Result loadWithDependencies(Handle *outDebug, ProcessData **outProcessDat
|
|||||||
static Result launchTitleImpl(Handle *debug, ProcessData **outProcessData, const FS_ProgramInfo *programInfo,
|
static Result launchTitleImpl(Handle *debug, ProcessData **outProcessData, const FS_ProgramInfo *programInfo,
|
||||||
const FS_ProgramInfo *programInfoUpdate, u32 launchFlags, ExHeader_Info *exheaderInfo)
|
const FS_ProgramInfo *programInfoUpdate, u32 launchFlags, ExHeader_Info *exheaderInfo)
|
||||||
{
|
{
|
||||||
|
if (isTitleLaunchPrevented(programInfo->programId)) {
|
||||||
|
*debug = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (launchFlags & PMLAUNCHFLAG_NORMAL_APPLICATION) {
|
if (launchFlags & PMLAUNCHFLAG_NORMAL_APPLICATION) {
|
||||||
launchFlags |= PMLAUNCHFLAG_LOAD_DEPENDENCIES;
|
launchFlags |= PMLAUNCHFLAG_LOAD_DEPENDENCIES;
|
||||||
} else {
|
} else {
|
||||||
@ -299,7 +305,7 @@ static Result launchTitleImplWrapper(Handle *outDebug, u32 *outPid, const FS_Pro
|
|||||||
ProcessData *process;
|
ProcessData *process;
|
||||||
Result res = launchTitleImpl(outDebug, &process, programInfo, programInfoUpdate, launchFlags, exheaderInfo);
|
Result res = launchTitleImpl(outDebug, &process, programInfo, programInfoUpdate, launchFlags, exheaderInfo);
|
||||||
|
|
||||||
if (outPid != NULL) {
|
if (outPid != NULL && process != NULL) {
|
||||||
*outPid = process->pid;
|
*outPid = process->pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
34
sysmodules/pm/source/luma.c
Normal file
34
sysmodules/pm/source/luma.c
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#include <3ds.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "luma.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
u32 getKExtSize(void)
|
||||||
|
{
|
||||||
|
s64 val;
|
||||||
|
Result res = svcGetSystemInfo(&val, 0x10000, 0x300);
|
||||||
|
return R_FAILED(res) ? 0 : (u32)val;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isTitleLaunchPrevented(u64 titleId)
|
||||||
|
{
|
||||||
|
s64 numKips = 0;
|
||||||
|
|
||||||
|
svcGetSystemInfo(&numKips, 26, 0);
|
||||||
|
return numKips >= 6 && (titleId & ~N3DS_TID_BIT) == 0x0004003000008A02ULL; // ErrDisp
|
||||||
|
}
|
||||||
|
|
||||||
|
Result fsRegSetupPermissionsForKip(u32 pid, u64 titleId)
|
||||||
|
{
|
||||||
|
FS_ProgramInfo info;
|
||||||
|
|
||||||
|
ExHeader_Arm11StorageInfo storageInfo = {
|
||||||
|
.fs_access_info = FSACCESS_NANDRO_RW | FSACCESS_NANDRW | FSACCESS_SDMC_RW,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Non-dummy TID
|
||||||
|
info.programId = titleId;
|
||||||
|
info.mediaType = MEDIATYPE_NAND;
|
||||||
|
|
||||||
|
return FSREG_Register(pid, 0xFFFF000000000000LL, &info, &storageInfo);;
|
||||||
|
}
|
7
sysmodules/pm/source/luma.h
Normal file
7
sysmodules/pm/source/luma.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <3ds/types.h>
|
||||||
|
|
||||||
|
u32 getKExtSize(void);
|
||||||
|
bool isTitleLaunchPrevented(u64 titleId);
|
||||||
|
Result fsRegSetupPermissionsForKip(u32 pid, u64 titleId);
|
@ -3,6 +3,7 @@
|
|||||||
#include "manager.h"
|
#include "manager.h"
|
||||||
#include "reslimit.h"
|
#include "reslimit.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "luma.h"
|
||||||
|
|
||||||
Manager g_manager;
|
Manager g_manager;
|
||||||
|
|
||||||
@ -41,6 +42,13 @@ void Manager_RegisterKips(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ProcessList_Unlock(&g_manager.processList);
|
ProcessList_Unlock(&g_manager.processList);
|
||||||
|
|
||||||
|
// Register loader, pm, and rosalina (if applicable)
|
||||||
|
assertSuccess(fsRegSetupPermissionsForKip(1, 0x0004013000001302LL)); // loader
|
||||||
|
assertSuccess(fsRegSetupPermissionsForKip(2, 0x0004013000001202LL)); // pm
|
||||||
|
if (numKips >= 6) {
|
||||||
|
assertSuccess(fsRegSetupPermissionsForKip(5, 0x0004013000006902LL)); // rosalina
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Result UnregisterProcess(u64 titleId)
|
Result UnregisterProcess(u64 titleId)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "reslimit.h"
|
#include "reslimit.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "manager.h"
|
#include "manager.h"
|
||||||
|
#include "luma.h"
|
||||||
|
|
||||||
typedef s64 ReslimitValues[10];
|
typedef s64 ReslimitValues[10];
|
||||||
|
|
||||||
@ -242,7 +243,7 @@ static ReslimitValues *fixupReslimitValues(void)
|
|||||||
{
|
{
|
||||||
// In order: APPLICATION, SYS_APPLET, LIB_APPLET, OTHER
|
// In order: APPLICATION, SYS_APPLET, LIB_APPLET, OTHER
|
||||||
// Fixup "commit" reslimit
|
// Fixup "commit" reslimit
|
||||||
u32 sysmemalloc = SYSMEMALLOC;
|
u32 sysmemalloc = SYSMEMALLOC + getKExtSize();
|
||||||
ReslimitValues *values = !IS_N3DS ? g_o3dsReslimitValues : g_n3dsReslimitValues;
|
ReslimitValues *values = !IS_N3DS ? g_o3dsReslimitValues : g_n3dsReslimitValues;
|
||||||
|
|
||||||
static const u32 minAppletMemAmount = 0x1200000;
|
static const u32 minAppletMemAmount = 0x1200000;
|
||||||
|
@ -37,39 +37,6 @@
|
|||||||
#include "menus/miscellaneous.h"
|
#include "menus/miscellaneous.h"
|
||||||
#include "menus/screen_filters.h"
|
#include "menus/screen_filters.h"
|
||||||
|
|
||||||
static Result stealFsReg(void)
|
|
||||||
{
|
|
||||||
Result ret = 0;
|
|
||||||
|
|
||||||
ret = svcControlService(SERVICEOP_STEAL_CLIENT_SESSION, fsRegGetSessionHandle(), "fs:REG");
|
|
||||||
while(ret == 0x9401BFE)
|
|
||||||
{
|
|
||||||
svcSleepThread(500 * 1000LL);
|
|
||||||
ret = svcControlService(SERVICEOP_STEAL_CLIENT_SESSION, fsRegGetSessionHandle(), "fs:REG");
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Result fsRegSetupPermissions(void)
|
|
||||||
{
|
|
||||||
u32 pid;
|
|
||||||
Result res;
|
|
||||||
FS_ProgramInfo info;
|
|
||||||
|
|
||||||
ExHeader_Arm11StorageInfo storageInfo = {
|
|
||||||
.fs_access_info = FSACCESS_NANDRO_RW | FSACCESS_NANDRW | FSACCESS_SDMC_RW,
|
|
||||||
};
|
|
||||||
|
|
||||||
info.programId = 0x0004013000006902LL; // Rosalina TID
|
|
||||||
info.mediaType = MEDIATYPE_NAND;
|
|
||||||
|
|
||||||
if(R_SUCCEEDED(res = svcGetProcessId(&pid, CUR_PROCESS_HANDLE)))
|
|
||||||
res = FSREG_Register(pid, 0xFFFF000000000000LL, &info, &storageInfo);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
// this is called before main
|
// this is called before main
|
||||||
bool isN3DS;
|
bool isN3DS;
|
||||||
void __appInit()
|
void __appInit()
|
||||||
@ -82,7 +49,12 @@ void __appInit()
|
|||||||
svcBreak(USERBREAK_PANIC);
|
svcBreak(USERBREAK_PANIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (R_FAILED(stealFsReg()) || R_FAILED(fsRegSetupPermissions()) || R_FAILED(fsInit()))
|
// Wait for pm to call fs:REG Register on us
|
||||||
|
bool registered = false;
|
||||||
|
while (srvIsServiceRegistered(®istered, "pm:app"), registered)
|
||||||
|
svcSleepThread(500 * 1000LL);
|
||||||
|
|
||||||
|
if (R_FAILED(fsInit()))
|
||||||
svcBreak(USERBREAK_PANIC);
|
svcBreak(USERBREAK_PANIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user