Skip to content
This repository has been archived by the owner on Jan 20, 2023. It is now read-only.

Commit

Permalink
Made changes to loader to load instantly with out reloading UI and ch…
Browse files Browse the repository at this point in the history
…anges to Game monitor.

-  Loader can now mount on inject so there isn't the need to reload the UI. If people have trouble with icons loading could be because of this.
- CPU_Monitor is now System_Monitor to try and unify data and take the load off the system thread.
- Added most offsets for 7.55 will still need alot of work on the toolbox side to figure out how to get class namespaces.
- Added patches for 6.72 and 5.05 from mira to make patches for loading kernel.
  • Loading branch information
OSM-Made committed May 29, 2021
1 parent 26ebd9d commit 0599f6f
Show file tree
Hide file tree
Showing 25 changed files with 581 additions and 307 deletions.
1 change: 0 additions & 1 deletion Loader/Kernel/source/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ extern "C" void _main(uint64_t arg)
proc* ShellUI = proc_find_by_name("SceShellUI");
if(ShellUI)
{
Jailbreak(ShellUI, nullptr);
//proc_kill(ShellUI, "Orbis Toolbox");
}
}
19 changes: 10 additions & 9 deletions Loader/Kernel/source/Util/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,31 @@ void MountDir(thread* td, char* Sandbox, char* what, int flags)
{
if(!td)
{
klog("Thread was NULL...\n");
klog("Thread was NULL...");
return;
}

char s_fulldir[0x200];
snprintf(s_fulldir, sizeof(s_fulldir), "%s%s", Sandbox, what);

klog("Mount: %s -> %s\n", s_fulldir, what);
klog("Mount: %s -> %s", s_fulldir, what);
kern_mkdir(td, s_fulldir, 0, 0777);
MountNullFS(s_fulldir, what, flags);
int res = MountNullFS(s_fulldir, what, flags);
klog("Mount Result: 0x%llX\n", res);
}

void UnMountDir(thread* td, char* Sandbox, char* what, int flags)
{
if(!td)
{
klog("Thread was NULL...\n");
klog("Thread was NULL...");
return;
}

char s_fulldir[0x200];
snprintf(s_fulldir, sizeof(s_fulldir), "%s%s", Sandbox, what);

klog("Un-Mount: %s -> %s\n", s_fulldir, what);
klog("Un-Mount: %s -> %s", s_fulldir, what);

sys_unmount(s_fulldir, flags);
kern_rmdir(td, s_fulldir, 0);
Expand Down Expand Up @@ -110,17 +111,17 @@ void Jailbreak(proc* proc, Backup_Jail* jail)
cred->cr_rgid = 0;
cred->cr_groups[0] = 0;

thread* Cur = proc->p_threads.tqh_first;
/*thread* Cur = proc->p_threads.tqh_first;
while(Cur != nullptr)
{
Cur->td_ucred->cr_sceAuthID = 0x3801000000000013;
Cur->td_ucred->cr_sceCaps[0] = 0xffffffffffffffff;
Cur->td_ucred->cr_sceCaps[1] = 0xffffffffffffffff;
Cur = Cur->td_plist.tqe_next;
}
}*/

//fd->fd_jdir = *(vnode**)rootvnode;
//fd->fd_rdir = *(vnode**)rootvnode;
fd->fd_jdir = *(vnode**)rootvnode;
fd->fd_rdir = *(vnode**)rootvnode;
}
}

Expand Down
154 changes: 127 additions & 27 deletions Loader/Kernel/source/kproc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,68 @@
#include "Loader.hpp"
#include "Util/Proc.hpp"

#define RESUME_WAIT 17000

//Event Handlers
eventhandler_entry* SystemSuspend;
eventhandler_entry* SystemResume;

eventhandler_entry* ProcessStartEvent;
eventhandler_entry* ProcessExitEvent;

bool IsSystemResuming = false;
void OnSystemSuspend(void* arg)
{
klog("System is Suspending...");
IsSystemResuming = true;
}

void OnSystemResume(void* arg)
{
klog("System is Resuming...");
IsSystemResuming = true;
}

void test_thread(void* arg)
{
proc* p = (proc*)arg;

klog("Hello From thread..");

//pause the thread for 20 seconds.
pause("", 20000);
if(IsSystemResuming)
pause("", 20000);
else
{
//pause the thread for 20 seconds.
#if defined(SOFTWARE_VERSION_505) || defined(SOFTWARE_VERSION_NA)
pause("", 17000);
#else
pause("", 20000);
#endif
}

//Jailbreak the process.
Backup_Jail bkJail;
Jailbreak(p, &bkJail);

//Get first thread in proc.
thread* td = p->p_threads.tqh_first;

//Get the sandbox path.
char* s_SandboxPath = nullptr;
char* s_Freepath = nullptr;
vn_fullpath(td, bkJail.fd_jdir, &s_SandboxPath, &s_Freepath);
klog("%s -> %s\n", p->p_comm, s_SandboxPath);

//Mount dirs.
MountDir(td, s_SandboxPath, "/system", MNT_SYNCHRONOUS);
MountDir(td, s_SandboxPath, "/data", MNT_SYNCHRONOUS);
MountDir(td, s_SandboxPath, "/host", MNT_SYNCHRONOUS);
MountDir(td, s_SandboxPath, "/hostapp", MNT_SYNCHRONOUS);

//Restore previous jail.
RestoreJail(p, bkJail);

//Check if Toolbox is Loaded.
bool Toolbox_Loaded = false;
dynlib* m_library = p->p_dynlibptr->p_dynlib;
Expand Down Expand Up @@ -43,6 +92,8 @@ void test_thread(void* arg)
klog("Launched Toolbox...\n");
}

IsSystemResuming = false;

kthread_exit();
}

Expand All @@ -55,31 +106,9 @@ void OnProcessStart(void *arg, struct proc *p)

if(!strcmp(p->titleId, "NPXS20001") && (!strcmp(p->p_comm, "SceShellUI") || !strcmp(p->p_comm, "eboot.bin")))
{
//Jailbreak the process.
Backup_Jail bkJail;
Jailbreak(p, &bkJail);

//Get first thread in proc.
thread* td = p->p_threads.tqh_first;

//Get the sandbox path.
char* s_SandboxPath = nullptr;
char* s_Freepath = nullptr;
vn_fullpath(td, bkJail.fd_jdir, &s_SandboxPath, &s_Freepath);
klog("%s -> %s\n", p->p_comm, s_SandboxPath);

//Mount dirs.
MountDir(td, s_SandboxPath, "/system", MNT_SYNCHRONOUS);
MountDir(td, s_SandboxPath, "/data", MNT_SYNCHRONOUS);
MountDir(td, s_SandboxPath, "/host", MNT_SYNCHRONOUS);
MountDir(td, s_SandboxPath, "/hostapp", MNT_SYNCHRONOUS);

//Restore previous jail.
RestoreJail(p, bkJail);

//proc* kernel = proc_find_by_name("kernel");
//if(kernel)
// kproc_kthread_add(test_thread, p, &kernel, NULL, NULL, 0, "kernel", "Loader Thread");
proc* kernel = proc_find_by_name("kernel");
if(kernel)
kproc_kthread_add(test_thread, p, &kernel, NULL, NULL, 0, "kernel", "Loader Thread");
}
}

Expand Down Expand Up @@ -117,12 +146,83 @@ void OnProcessExit(void *arg, struct proc *p)
}
}

void test2_thread(void* arg)
{
klog("Hello From thread..");

proc* p = proc_find_by_name("SceShellUI");

if(!p)
{
kthread_exit();
return;
}

//Jailbreak the process.
Backup_Jail bkJail;
Jailbreak(p, &bkJail);

//Get first thread in proc.
thread* td = curthread();// p->p_threads.tqh_first;

//Get the sandbox path.
char* s_SandboxPath = nullptr;
char* s_Freepath = nullptr;
vn_fullpath(td, bkJail.fd_jdir, &s_SandboxPath, &s_Freepath);
klog("%s -> %s\n", p->p_comm, s_SandboxPath);

//Mount dirs.
MountDir(td, s_SandboxPath, "/system", MNT_SYNCHRONOUS);
MountDir(td, s_SandboxPath, "/data", MNT_SYNCHRONOUS);
MountDir(td, s_SandboxPath, "/host", MNT_SYNCHRONOUS);
MountDir(td, s_SandboxPath, "/hostapp", MNT_SYNCHRONOUS);

//Restore previous jail.
RestoreJail(p, bkJail);

//Check if Toolbox is Loaded.
bool Toolbox_Loaded = false;
dynlib* m_library = p->p_dynlibptr->p_dynlib;
while(m_library != 0)
{
if(!strcmp(basename(m_library->ModulePath), "Orbis Toolbox.sprx"))
{
Toolbox_Loaded = true;
break;
}
m_library = m_library->dynlib_next;
}

//If the tool box is not loaded init the loader and load the module.
if(!Toolbox_Loaded)
{
klog("****\nLaunching Toolbox...\n****");

Loader_Init(p);

Load_SPRX(SPRX_PATH);

Loader_Term();

klog("Launched Toolbox...\n");
}

kthread_exit();
}

void kproc_Init()
{
//Register Events
SystemSuspend = EVENTHANDLER_REGISTER(system_suspend_phase1, (void*)OnProcessStart, nullptr, EVENTHANDLER_PRI_FIRST);
SystemResume = EVENTHANDLER_REGISTER(system_resume_phase1, (void*)OnProcessStart, nullptr, EVENTHANDLER_PRI_FIRST);

ProcessStartEvent = EVENTHANDLER_REGISTER(process_exec_end, (void*)OnProcessStart, nullptr, EVENTHANDLER_PRI_LAST);
ProcessExitEvent = EVENTHANDLER_REGISTER(process_exit, (void*)OnProcessExit, nullptr, EVENTHANDLER_PRI_ANY);

proc* kernel = proc_find_by_name("kernel");
if(kernel)
kproc_kthread_add(test2_thread, nullptr, &kernel, NULL, NULL, 0, "kernel", "Loader Thread");

klog("kproc_Init() -> Sucess!");
}

Expand Down
4 changes: 3 additions & 1 deletion Loader/Userland/include/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@
#include "Resolver/Patches.h"
#include "syscall.h"
#include "ELF.h"
#include "Util/Utils.h"
#include "Util/Utils.h"

extern uint8_t* gKernelBase;
10 changes: 5 additions & 5 deletions Loader/Userland/include/Resolver/Patches.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

void Install_505(uint64_t kernbase);
void Install_672(uint8_t* kernbase);
void Install_702(uint64_t kernbase);
void Install_755(uint64_t kernbase);
void Install_Patches(uint64_t kernbase);
void Install_505();
void Install_672();
void Install_702();
void Install_755();
void Install_Patches();
2 changes: 1 addition & 1 deletion Loader/Userland/include/Resolver/Resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int (*ksprintf)(char* dst, const char *fmt, ...);
int (*kvsprintf)(char* dst, const char* fmt, va_list ap);
void(*kprintf)(const char* fmt, ...);

void Kern_Resolve(uint64_t kernbase);
void Kern_Resolve();

//Kernel
int(*sceKernelDebugOutText)(int dbg_channel, const char* text);
Expand Down
21 changes: 21 additions & 0 deletions Loader/Userland/include/Util/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,27 @@ static inline __attribute__((always_inline)) uint64_t __readmsr(uint32_t __regis
return (((uint64_t)__edx) << 32) | (uint64_t)__eax;
}

#define CR0_WP (1 << 16) // write protect

static inline __attribute__((always_inline)) uint64_t __readcr0(void) {
uint64_t cr0;

__asm__ volatile (
"movq %0, %%cr0"
: "=r" (cr0)
: : "memory"
);

return cr0;
}
static inline __attribute__((always_inline)) void __writecr0(uint64_t cr0) {
__asm__ volatile (
"movq %%cr0, %0"
: : "r" (cr0)
: "memory"
);
}

struct Backup_Jail
{
struct prison* cr_prison;
Expand Down
Loading

0 comments on commit 0599f6f

Please sign in to comment.