revert fsldr change, fix null deref in pm

This commit is contained in:
TuxSH 2019-03-29 22:40:54 +01:00
parent e688ec9257
commit ef034a87d4
6 changed files with 61 additions and 35 deletions

View File

@ -28,6 +28,26 @@ static u64 g_cached_prog_handle;
static ExHeader_Info g_exheader;
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)
{
s64 out;
@ -565,10 +585,8 @@ void __appInit()
svcBreak(USERBREAK_PANIC);
}
// Wait for pm to call fs:REG Register on us
bool registered = false;
while (srvIsServiceRegistered(&registered, "pm:app"), registered)
svcSleepThread(500 * 1000LL);
fsRegInit();
fsldrPatchPermissions();
//fsldrInit();
res = srvGetServiceHandle(fsGetSessionHandle(), "fs:LDR");

View File

@ -205,8 +205,11 @@ static Result loadWithDependencies(Handle *outDebug, ProcessData **outProcessDat
static Result launchTitleImpl(Handle *debug, ProcessData **outProcessData, const FS_ProgramInfo *programInfo,
const FS_ProgramInfo *programInfoUpdate, u32 launchFlags, ExHeader_Info *exheaderInfo)
{
if (isTitleLaunchPrevented(programInfo->programId)) {
if (debug != NULL) {
*debug = 0;
}
if (isTitleLaunchPrevented(programInfo->programId)) {
return 0;
}

View File

@ -16,19 +16,4 @@ bool isTitleLaunchPrevented(u64 titleId)
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);;
}

View File

@ -3,5 +3,4 @@
#include <3ds/types.h>
u32 getKExtSize(void);
bool isTitleLaunchPrevented(u64 titleId);
Result fsRegSetupPermissionsForKip(u32 pid, u64 titleId);
bool isTitleLaunchPrevented(u64 titleId);

View File

@ -42,13 +42,6 @@ void Manager_RegisterKips(void)
}
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)

View File

@ -37,6 +37,39 @@
#include "menus/miscellaneous.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
bool isN3DS;
void __appInit()
@ -49,12 +82,7 @@ void __appInit()
svcBreak(USERBREAK_PANIC);
}
// Wait for pm to call fs:REG Register on us
bool registered = false;
while (srvIsServiceRegistered(&registered, "pm:app"), registered)
svcSleepThread(500 * 1000LL);
if (R_FAILED(fsInit()))
if (R_FAILED(stealFsReg()) || R_FAILED(fsRegSetupPermissions()) || R_FAILED(fsInit()))
svcBreak(USERBREAK_PANIC);
}