Add function to test OFW behavior under CFW

This commit is contained in:
plutooo 2019-02-14 22:03:00 +01:00
parent fc557cbf2a
commit 17731d750e
2 changed files with 10 additions and 0 deletions

View File

@ -22,3 +22,5 @@ bool detectDebugger(void);
/// Returns true if the kernel is patched to allow self-process-jit.
bool detectCfwJitPatch(void);
/// After this has been called, libnx will pretend that CFW is not present. For testing purposes only.
void detectPretendNotCfwForTesting(void);

View File

@ -71,6 +71,7 @@ static void _CacheCfwJit(void)
{
// On an unpatched kernel on 5.0.0 and above, this would return 0xD401.
// It is not allowed for the creator-process of a CodeMemory object to use svcControlCodeMemory on it.
// If the patch is present, the function should return 0xF001, because -1 is not a valid enum CodeOperation.
rc = svcControlCodeMemory(code, -1, 0, 0x1000, 0);
g_CfwJitPatchDetected = (rc == 0xF001);
@ -120,3 +121,10 @@ bool detectCfwJitPatch(void) {
_CacheCfwJit();
return g_CfwJitPatchDetected;
}
void detectPretendNotCfwForTesting(void) {
mutexLock(&g_CfwJitMutex);
g_CfwJitPatchDetected = false;
__atomic_store_n(&g_CfwJitCached, true, __ATOMIC_SEQ_CST);
mutexUnlock(&g_CfwJitMutex);
}