mirror of
https://github.com/switchbrew/nx-hbloader.git
synced 2025-06-21 05:22:40 +02:00
Automatically determine which AppletType/AppletFlags to use by checking pmshellGetApplicationPid output.
This commit is contained in:
parent
6826b064e9
commit
aedf312fa0
@ -12,6 +12,7 @@ static char g_nextNroPath[512];
|
|||||||
static u64 g_nroAddr = 0;
|
static u64 g_nroAddr = 0;
|
||||||
static u64 g_nroSize = 0;
|
static u64 g_nroSize = 0;
|
||||||
static NroHeader g_nroHeader;
|
static NroHeader g_nroHeader;
|
||||||
|
static bool g_isApplication = 0;
|
||||||
|
|
||||||
static u8 g_savedTls[0x100];
|
static u8 g_savedTls[0x100];
|
||||||
|
|
||||||
@ -115,6 +116,26 @@ void threadFunc(void* ctx)
|
|||||||
svcCloseHandle(session);
|
svcCloseHandle(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Gets the PID of the process with application_type==APPLICATION in the NPDM, then sets g_isApplication if it matches the current PID.
|
||||||
|
void getIsApplication(void) {
|
||||||
|
Result rc=0;
|
||||||
|
u64 cur_pid=0, app_pid=0;
|
||||||
|
|
||||||
|
g_isApplication = 0;
|
||||||
|
|
||||||
|
rc = svcGetProcessId(&cur_pid, CUR_PROCESS_HANDLE);
|
||||||
|
if (R_FAILED(rc)) return;
|
||||||
|
|
||||||
|
rc = pmshellInitialize();
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
rc = pmshellGetApplicationPid(&app_pid);
|
||||||
|
pmshellExit();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc) && cur_pid == app_pid) g_isApplication = 1;
|
||||||
|
}
|
||||||
|
|
||||||
void getOwnProcessHandle(void)
|
void getOwnProcessHandle(void)
|
||||||
{
|
{
|
||||||
static Thread t;
|
static Thread t;
|
||||||
@ -313,6 +334,13 @@ void loadNro(void)
|
|||||||
{ EntryType_EndOfList, 0, {0, 0} }
|
{ EntryType_EndOfList, 0, {0, 0} }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ConfigEntry *entry_AppletType = &entries[2];
|
||||||
|
|
||||||
|
if (g_isApplication) {
|
||||||
|
entry_AppletType->Value[0] = AppletType_SystemApplication;
|
||||||
|
entry_AppletType->Value[1] = EnvAppletFlags_ApplicationOverride;
|
||||||
|
}
|
||||||
|
|
||||||
// MainThreadHandle
|
// MainThreadHandle
|
||||||
entries[0].Value[0] = envGetMainThreadHandle();
|
entries[0].Value[0] = envGetMainThreadHandle();
|
||||||
// ProcessHandle
|
// ProcessHandle
|
||||||
@ -344,6 +372,7 @@ int main(int argc, char **argv)
|
|||||||
memcpy(g_savedTls, (u8*)armGetTls() + 0x100, 0x100);
|
memcpy(g_savedTls, (u8*)armGetTls() + 0x100, 0x100);
|
||||||
|
|
||||||
setupHbHeap();
|
setupHbHeap();
|
||||||
|
getIsApplication();
|
||||||
getOwnProcessHandle();
|
getOwnProcessHandle();
|
||||||
loadNro();
|
loadNro();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user