From bb9cde1e3d0f32276927979e5b72950229495545 Mon Sep 17 00:00:00 2001 From: Leonid Pavel Date: Sun, 11 Jun 2023 20:08:01 +0000 Subject: [PATCH] kernel: replace title ID offset references with p_titleid field --- kernel/src/OrbisOS/Utilities.cpp | 4 ++-- kernel/src/Plugins/FakePkg/FakePkgManager.cpp | 2 +- .../Plugins/MorpheusEnabler/MorpheusEnabler.cpp | 2 +- .../RemotePlayEnabler/RemotePlayEnabler.cpp | 2 +- kernel/src/Plugins/Substitute/Substitute.cpp | 15 +++++++-------- kernel/src/Plugins/Substitute2/Substitute2.cpp | 4 ++-- 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/kernel/src/OrbisOS/Utilities.cpp b/kernel/src/OrbisOS/Utilities.cpp index 89af6ca3..186c1f07 100644 --- a/kernel/src/OrbisOS/Utilities.cpp +++ b/kernel/src/OrbisOS/Utilities.cpp @@ -425,7 +425,7 @@ int Utilities::CreatePOSIXThread(struct proc* p, void* entrypoint) { size_t s_Size = 0; int s_Ret = 0; - char* s_TitleId = (char*)((uint64_t)p + 0x390); + char* s_TitleId = p->p_titleid; WriteLog(LL_Info, "[%s] Creating POSIX Thread (Entrypoint: %p) ...", s_TitleId, entrypoint); @@ -567,7 +567,7 @@ int Utilities::LoadPRXModule(struct proc* p, const char* prx_path) size_t s_Size = 0; int s_Ret = 0; - char* s_TitleId = (char*)((uint64_t)p + 0x390); + char* s_TitleId = p->p_titleid; WriteLog(LL_Info, "[%s] Loading PRX (%s) over POSIX ...", s_TitleId, prx_path); diff --git a/kernel/src/Plugins/FakePkg/FakePkgManager.cpp b/kernel/src/Plugins/FakePkg/FakePkgManager.cpp index 07f780a0..1fc99f5e 100644 --- a/kernel/src/Plugins/FakePkg/FakePkgManager.cpp +++ b/kernel/src/Plugins/FakePkg/FakePkgManager.cpp @@ -434,7 +434,7 @@ void FakePkgManager::ProcessStartEvent(void *arg, struct ::proc *p) if (!p) return; - char* s_TitleId = (char*)((uint64_t)p + 0x390); + char* s_TitleId = p->p_titleid; if (strncmp(s_TitleId, "NPXS20000", 9) == 0) ShellCorePatch(); diff --git a/kernel/src/Plugins/MorpheusEnabler/MorpheusEnabler.cpp b/kernel/src/Plugins/MorpheusEnabler/MorpheusEnabler.cpp index beb06462..519971fe 100644 --- a/kernel/src/Plugins/MorpheusEnabler/MorpheusEnabler.cpp +++ b/kernel/src/Plugins/MorpheusEnabler/MorpheusEnabler.cpp @@ -36,7 +36,7 @@ void MorpheusEnabler::ProcessStartEvent(void *arg, struct ::proc *p) if (!p) return; - char* s_TitleId = (char*)((uint64_t)p + 0x390); + char* s_TitleId = p->p_titleid; if (strncmp(s_TitleId, "NPXS20000", 9) == 0) DoPatch(); diff --git a/kernel/src/Plugins/RemotePlayEnabler/RemotePlayEnabler.cpp b/kernel/src/Plugins/RemotePlayEnabler/RemotePlayEnabler.cpp index f07d8770..430dcdc3 100644 --- a/kernel/src/Plugins/RemotePlayEnabler/RemotePlayEnabler.cpp +++ b/kernel/src/Plugins/RemotePlayEnabler/RemotePlayEnabler.cpp @@ -36,7 +36,7 @@ void RemotePlayEnabler::ProcessStartEvent(void *arg, struct ::proc *p) if (!p) return; - char* s_TitleId = (char*)((uint64_t)p + 0x390); + char* s_TitleId = p->p_titleid; if (strncmp(s_TitleId, "NPXS20001", 9) == 0) ShellUIPatch(); diff --git a/kernel/src/Plugins/Substitute/Substitute.cpp b/kernel/src/Plugins/Substitute/Substitute.cpp index 1a845d23..49f2319b 100644 --- a/kernel/src/Plugins/Substitute/Substitute.cpp +++ b/kernel/src/Plugins/Substitute/Substitute.cpp @@ -769,7 +769,7 @@ void Substitute::CleanupProcessHook(struct proc* p) { if (!p) return; - char* s_TitleId = (char*)((uint64_t)p + 0x390); + char* s_TitleId = p->p_titleid; WriteLog(LL_Info, "Cleaning up hook for %s", s_TitleId); @@ -799,8 +799,7 @@ void* Substitute::FindOriginalAddress(struct proc* p, const char* name, int32_t if (p == nullptr) return nullptr; - // TODO: Fix this structure within proc - char* s_TitleId = (char*)((uint64_t)p + 0x390); + char* s_TitleId = p->p_titleid; void* s_Address = nullptr; WriteLog(LL_Info, "TitleId: (%s).", s_TitleId); @@ -869,7 +868,7 @@ uint64_t Substitute::FindJmpslotAddress(struct proc* p, const char* module_name, return 0; } - char* s_TitleId = (char*)((uint64_t)p + 0x390); + char* s_TitleId = p->p_titleid; // Get the nids of the function char nids[0xD] = { 0 }; @@ -1000,7 +999,7 @@ void Substitute::LoadAllPrx(struct thread* td, const char* folder_path) return; } - char* s_TitleId = (char*)((uint64_t)td->td_proc + 0x390); + char* s_TitleId = td->td_proc->p_titleid; // Opening substitute folder auto s_DirectoryHandle = kopen_t(folder_path, O_RDONLY | O_DIRECTORY, 0777, td); @@ -1059,7 +1058,7 @@ bool Substitute::OnProcessExecEnd(struct proc *p) auto vn_fullpath = (int(*)(struct thread *td, struct vnode *vp, char **retbuf, char **freebuf))kdlsym(vn_fullpath); struct thread* s_ProcessThread = FIRST_THREAD_IN_PROC(p); - char* s_TitleId = (char*)((uint64_t)p + 0x390); + char* s_TitleId = p->p_titleid; // Check if it's a valid process if ( !s_TitleId || s_TitleId[0] == 0 ) @@ -1173,7 +1172,7 @@ bool Substitute::OnProcessExit(struct proc *p) { // Get process information struct thread* s_ProcessThread = FIRST_THREAD_IN_PROC(p); - char* s_TitleId = (char*)((uint64_t)p + 0x390); + char* s_TitleId = p->p_titleid; Substitute* substitute = GetPlugin(); @@ -1277,7 +1276,7 @@ int Substitute::Sys_dynlib_dlsym_hook(struct thread* td, struct dynlib_dlsym_arg return ret; } - char* s_TitleId = (char*)((uint64_t)td->td_proc + 0x390); + char* s_TitleId = td->td_proc->p_titleid; // Check if it's a valid process if ( !s_TitleId || s_TitleId[0] == 0) { diff --git a/kernel/src/Plugins/Substitute2/Substitute2.cpp b/kernel/src/Plugins/Substitute2/Substitute2.cpp index 328ca0ca..21a7cc8a 100644 --- a/kernel/src/Plugins/Substitute2/Substitute2.cpp +++ b/kernel/src/Plugins/Substitute2/Substitute2.cpp @@ -23,7 +23,7 @@ bool Substitute2::OnProcessExecEnd(struct proc* p_Process) return true; // Check the title id's against the supported - const char* s_TitleId = &p_Process->p_unk348[0x58]; + const char* s_TitleId = p_Process->p_titleid; if (s_TitleId == nullptr) return false; @@ -50,4 +50,4 @@ bool Substitute2::OnProcessExit(struct proc* p_Process) bool Substitute2::GetTitlePath(SubstituteFlags p_Flags, const char* p_TitleId, const char*& p_OutPath) { return false; -} \ No newline at end of file +}