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

Commit

Permalink
Fixed issues with VRAM and RAM reporting incorrectly and started work…
Browse files Browse the repository at this point in the history
… on daemons.

- RAM and VRAM would only report system usage not all usage. New fix will report full usage.

- Daemon can now detect the running state of the daemon and kill the running daemon and launch a daemon.
  • Loading branch information
OSM-Made committed May 26, 2021
1 parent 2cf90f9 commit 26ebd9d
Show file tree
Hide file tree
Showing 15 changed files with 268 additions and 52 deletions.
13 changes: 5 additions & 8 deletions Loader/Kernel/source/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@ extern "C" void _main(uint64_t arg)
klog("!!! HELLO HELLO FROM KERNEL !!!");

//Init kernel process.
//kproc_Init();
kproc_Init();

/*klog("Restarting UI...");
klog("Restarting UI...");
proc* ShellUI = proc_find_by_name("SceShellUI");
if(ShellUI)
{
proc_kill(ShellUI, "Orbis Toolbox");
}*/

proc* test = proc_find_by_name("default.elf");
Backup_Jail bk;
Jailbreak(test, &bk);
Jailbreak(ShellUI, nullptr);
//proc_kill(ShellUI, "Orbis Toolbox");
}
}
12 changes: 10 additions & 2 deletions Loader/Kernel/source/Util/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,17 @@ void Jailbreak(proc* proc, Backup_Jail* jail)
cred->cr_rgid = 0;
cred->cr_groups[0] = 0;

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
6 changes: 3 additions & 3 deletions Loader/Kernel/source/kproc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ void OnProcessStart(void *arg, struct proc *p)
//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
2 changes: 1 addition & 1 deletion Orbis Toolbox/CPU_Monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void* CPU_Monitor::Monitor_Thread(void* args)
Usage[4], Usage[5], Usage[6], Usage[7]);*/
}

sceKernelSleep(3);
sceKernelSleep(2);
}

Should_Run_Thread = true;
Expand Down
76 changes: 75 additions & 1 deletion Orbis Toolbox/LncUtil.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,79 @@
#include "Common.h"
#include "LncUtil.h"

int LncUtil::GetAppStatus(AppStatus* Status)
{
MonoClass* LncUtil_Class = Mono::Get_Class(Mono::platform_dll, "Sce.Vsh.ShellUI.Lnc", "LncUtil");
MonoClass* AppStatus = Mono::Get_Class(Mono::platform_dll, "Sce.Vsh.ShellUI.Lnc", "LncUtil/AppStatus");

MonoObject* AppStatus_Instance = Mono::New_Object(AppStatus);
if (AppStatus_Instance)
{
Mono::Invoke<void>(Mono::platform_dll, AppStatus, (MonoObject*)mono_object_unbox(AppStatus_Instance), ".ctor", Status->appId, Status->launchRequestAppId, Status->appType);

int res = Mono::Invoke<int>(Mono::platform_dll, LncUtil_Class, nullptr, "GetAppStatus", mono_object_unbox(AppStatus_Instance));

memcpy(Status, (void*)mono_object_unbox(AppStatus_Instance), sizeof(AppStatus));

return res;
}

return 0;
}

//int SuspendApp(int appId, Flag flag = Flag_None);
//int ResumeApp(int appId, Flag flag = Flag_None);

//static int SetControllerFocus(int appId);
//static int SetAppFocus(int appId, Flag flag = Flag_None);

int LncUtil::GetAppId(const char* titleId)
{
MonoClass* LncUtil_Class = Mono::Get_Class(Mono::platform_dll, "Sce.Vsh.ShellUI.Lnc", "LncUtil");
return Mono::Invoke<int>(Mono::platform_dll, LncUtil_Class, nullptr, "GetAppId", Mono::New_String(titleId));
}

int LncUtil::LaunchApp(const char* titleId, char* args, int argsSize, LaunchAppParam* param)
{
MonoClass* LncUtil_Class = Mono::Get_Class(Mono::platform_dll, "Sce.Vsh.ShellUI.Lnc", "LncUtil");

//
// Init Launch Param
//
MonoClass* LaunchAppParam_class = Mono::Get_Class(Mono::platform_dll, "Sce.Vsh.ShellUI.Lnc", "LncUtil/LaunchAppParam");

MonoObject* LaunchAppParam_Instance = Mono::New_Object(LaunchAppParam_class);
MonoObject* LaunchAppParam_Instance_real = (MonoObject*)mono_object_unbox(LaunchAppParam_Instance);
mono_runtime_object_init(LaunchAppParam_Instance_real);

Mono::Set_Field(LaunchAppParam_Instance_real, "size", param->size);
Mono::Set_Field(LaunchAppParam_Instance_real, "userId", param->userId);
Mono::Set_Field(LaunchAppParam_Instance_real, "appAttr", param->appAttr);
Mono::Set_Field(LaunchAppParam_Instance_real, "enableCrashReport", param->enableCrashReport);
Mono::Set_Field(LaunchAppParam_Instance_real, "checkFlag", param->checkFlag);

//LaunchAppParam* p = (LaunchAppParam*)mono_object_unbox(LaunchAppParam_Instance);
//memcpy(p, param, sizeof(LaunchAppParam));

//
// Init Byte Class.
//
MonoArray* Array = Mono::New_Array(mono_get_byte_class(), argsSize);
//char* Array_addr = mono_array_addr_with_size(Array, sizeof(char), 0);
//memcpy(Array_addr, args, argsSize);

return Mono::Invoke<int>(Mono::platform_dll, LncUtil_Class, nullptr, "LaunchApp", Mono::New_String(titleId), Array, argsSize, LaunchAppParam_Instance);
}

int LncUtil::KillApp(int appId, int userId)
{
MonoClass* LncUtil_Class = Mono::Get_Class(Mono::platform_dll, "Sce.Vsh.ShellUI.Lnc", "LncUtil");
return Mono::Invoke<int>(Mono::platform_dll, LncUtil_Class, nullptr, "KillApp", appId, userId, 0, 0);
}

//static int ForceKillApp(int appId, int userId = -1);
//static int KillLocalProcess(int appId, int appLocalPid);

void LncUtil::SystemShutdown(Boot flag)
{
MonoClass* LncUtil_Class = Mono::Get_Class(Mono::platform_dll, "Sce.Vsh.ShellUI.Lnc", "LncUtil");
Expand All @@ -17,4 +90,5 @@ void LncUtil::SystemSuspend()
{
MonoClass* LncUtil_Class = Mono::Get_Class(Mono::platform_dll, "Sce.Vsh.ShellUI.Lnc", "LncUtil");
Mono::Invoke<int>(Mono::platform_dll, LncUtil_Class, nullptr, "SystemSuspend");
}
}

6 changes: 3 additions & 3 deletions Orbis Toolbox/LncUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ class LncUtil
{
int appId;
int launchRequestAppId;
AppType appType;
char appType;
};

static int GetAppStatus(AppStatus* status);
static int GetAppStatus(AppStatus* Status);
static int SuspendApp(int appId, Flag flag = Flag_None);
static int ResumeApp(int appId, Flag flag = Flag_None);

static int SetControllerFocus(int appId);
static int SetAppFocus(int appId, Flag flag = Flag_None);

static int GetAppId(const char* titleId);
static int LaunchApp(const char* titleId, char* args, int argsSize, LaunchAppParam param);
static int LaunchApp(const char* titleId, char* args, int argsSize, LaunchAppParam* param);
static int KillApp(int appId, int userId = -1);
static int ForceKillApp(int appId, int userId = -1);
static int KillLocalProcess(int appId, int appLocalPid);
Expand Down
88 changes: 74 additions & 14 deletions Orbis Toolbox/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

std::map<const char*, MenuOption>* Menu::Options;
bool Menu::Auto_Load_Settings;
char Test[0x100] = { "Stopped" };

void Menu::Init()
{
Expand Down Expand Up @@ -39,33 +40,92 @@ void Menu::Init()

// Note: Package Installer does not need to be done here
// because of the fact its managed by the system.
Add_Option("id_message");

Add_Option("id_ORBS30000", &Test, Type_String, []() -> void { Notify("Test"); }, []() -> void { Notify("Test"); });
Add_Option("id_OFTP00001", []() -> void {

int AppId = LncUtil::GetAppId("OFTP00001");
if (AppId > 0)
{
LncUtil::KillApp(AppId);

AppId = LncUtil::GetAppId("OFTP00001");
if (AppId < 0)
{
UI::Utilities::Set_Value("id_OFTP00001", "Stopped");
UI::Utilities::ResetMenuItem("id_OFTP00001");
}
}
else
{
char Args;
LncUtil::LaunchAppParam p = { sizeof(LncUtil::LaunchAppParam), -1, 0, 0, LncUtil::Flag_None };
LncUtil::LaunchApp("OFTP00001", &Args, 0, &p);

//LaunchAppParam p = { sizeof(LaunchAppParam), -1, 0, 0, LncUtilFlag::LncUtilFlagNone };
//sceLncUtilLaunchApp("OFTP00001", 0, &p);

AppId = LncUtil::GetAppId("OFTP00001");
if (AppId > 0)
{
UI::Utilities::Set_Value("id_OFTP00001", "Running");
UI::Utilities::ResetMenuItem("id_OFTP00001");
}
}
Notify("Test");

});

// Daemon Manager
Add_Option("id_daemons", []() -> void {
Add_Option("id_daemons", nullptr, nullptr, []() -> void {

int fd = sceKernelOpen(DAEMON_DIR, 0, 0511);
/*int fd = sceKernelOpen(DAEMON_DIR, 0, 0511);
if (fd)
{
OrbisKernelStat stats;
sceKernelFstat(fd, &stats);
//OrbisKernelStat stats;
//sceKernelFstat(fd, &stats);
//char* Dent_Buffer = (char*)malloc((size_t)stats.st_blksize);
char buf[1024];
OrbisKernelDirents *dent;
int bpos;
char* Dent_Buffer = (char*)malloc((size_t)stats.st_blksize);
int nread = sceKernelGetdents(fd, buf, 1024);
sceKernelGetdents(fd, Dent_Buffer, stats.st_blksize);
if (nread <= 0)
return;
OrbisKernelDirents* File = (OrbisKernelDirents*)&Dent_Buffer[0];
OrbisKernelDirents* File_End = (OrbisKernelDirents*)&Dent_Buffer[stats.st_blksize];
int seek = 0;
while (File != File_End)
for (bpos = 0; bpos < nread;)
{
klog("%s\n", File->d_name);
File = (OrbisKernelDirents*)(((uint64_t)File + File->d_reclen));
dent = (OrbisKernelDirents*) (buf + bpos);
//Find any daemons that arent system. Making sure the type is directory and its name doesnt contain NPXS.
if (dent->d_type == DT_DIR && !strstr(dent->d_name, "NPXS") && !strstr(dent->d_name, "."))
{
klog("%s\n", dent->d_name);
if (!strcmp(dent->d_name, "OFTP00001"))
{*/
UI::Utilities::AddMenuItem(UI::Utilities::ElementData("id_OFTP00001", "Orbis FTP", "A simple FTP Daemon that has read write privlage to anywhere.", "file://system/vsh/app/OFTP00001/sce_sys/icon0.png"));

int AppId = LncUtil::GetAppId("OFTP00001");
klog("%i\n", AppId);

if(AppId > 0)
UI::Utilities::Set_Value("id_OFTP00001", "Running");
else
UI::Utilities::Set_Value("id_OFTP00001", "Stopped");
/*}
}
bpos += dent->d_reclen;
}
sceKernelClose(fd);
}

}*/
(*Options)["id_message"].Visible = false;
UI::Utilities::ResetMenuItem("id_message");

});
Expand Down
4 changes: 3 additions & 1 deletion Orbis Toolbox/Orbis_Toolbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ extern "C"
{
klog("!! Hello World !!\n");

//Test2();

Mono::Init();

UI::Utilities::SetVersionString("5.05 OSM's Cool Firmware");
//UI::Utilities::SetVersionString("5.05 OSM's Cool Firmware");
CPU_Monitor::Init();
Settings_Menu::Init();
//Title_Menu::Init();
Expand Down
7 changes: 7 additions & 0 deletions Orbis Toolbox/Settings_Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ void Settings_Menu::OnPreCreate_Hook(MonoObject* Instance, MonoObject* element,
MonoClass* SettingElement = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.Settings.Core", "SettingElement");
char* Id = mono_string_to_utf8(Mono::Get_Property<MonoString*>(SettingElement, element, "Id"));

klog("OnPreCreate: %s\n", Id);

if (!strcmp(Id, "id_ORBS30000"))
{
Mono::Set_Property(SettingElement, element, "Value", Mono::New_String("Stopped"));
}

for (std::map<const char*, MenuOption>::iterator it = Menu::Options->begin(); it != Menu::Options->end(); it++)
{
if (!strcmp(Id, it->first))
Expand Down
46 changes: 46 additions & 0 deletions Orbis Toolbox/UI_Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@ void UI::Utilities::AddMenuItem(MonoObject* ElementData)
Mono::Invoke<void>(Mono::App_exe, UIManager, Mono::Get_Instance(UIManager, "Instance"), "AddMenuItem", ElementData, Mono::New_String(""));
}

MonoObject* UI::Utilities::GetElement(const char* Id)
{
MonoClass* UIManager = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.Settings.Core", "UIManager");
return Mono::Invoke<MonoObject*>(Mono::App_exe, UIManager, Mono::Get_Instance(UIManager, "Instance"), "GetElement", Mono::New_String(Id));
}

void UI::Utilities::Set_Value(const char* Id, const char* Value)
{
MonoClass* SettingElement = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.Settings.Core", "SettingElement");

MonoObject* Elem = GetElement(Id);
if(Elem)
Mono::Set_Property(SettingElement, Elem, "Value", Mono::New_String(Value));
}

MonoObject* UI::Utilities::ElementData(const char* Id, const char* Title, const char* Title2, const char* Icon)
{
MonoClass* ButtonElementData = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.Settings.Core", "ButtonElementData");
Expand Down Expand Up @@ -164,4 +179,35 @@ float UI::Utilities::ScreenWidth()
{
MonoClass* UISystem = Mono::Get_Class(Mono::UI_dll, Mono::PUI2 ? "Sce.PlayStation.PUI" : "Sce.PlayStation.HighLevel.UI2", "UISystem");
return Mono::Get_Property<int>(UISystem, nullptr, "ScreenWidth");
}

//Sce.Vsh.ShellUI.Library OptionMenuFactory IsAppRunning
bool UI::Utilities::IsAppRunning(const char* TitleId)
{
MonoClass* ApplicationMonitor = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.AppSystem", "ApplicationMonitor");

if (ApplicationMonitor == nullptr)
{
klog("IsAppRunning: ApplicationMonitor was null.");
return false;
}

MonoMethod* Method = mono_class_get_method_from_name(ApplicationMonitor, "GetAppEvent", 1);

if (!Method)
{
klog("Get_Address_of_Method: failed to find method \"%s\" in class \"%s\"", "GetAppEvent", "ApplicationMonitor");
return false;
}

void* Args[] = { Mono::New_String(TitleId) };

uint64_t obj = (uint64_t)mono_runtime_invoke(Method, nullptr, Args, NULL);

//MonoObject* Res = Mono::Invoke<MonoObject*>(Mono::App_exe, ApplicationMonitor, nullptr, "GetAppEvent", Mono::New_String(TitleId));

klog("obj = %llX\n", obj);
return (obj != NULL);

return true;
}
3 changes: 3 additions & 0 deletions Orbis Toolbox/UI_Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ namespace UI
static MonoObject* IUFont(int size, int style, int weight);
static MonoObject* MemoryStream(void* Buffer, int Buffer_Size);
static void ResetMenuItem(const char* Menu);
static MonoObject* GetElement(const char* Id);
static void Set_Value(const char* Id, const char* Value);
static void AddMenuItem(MonoObject* ElementData);
static MonoObject* ElementData(const char* Id, const char* Title, const char* Title2, const char* Icon);
static MonoObject* UIColor(float R, float G, float B, float A);
static MonoObject* UIColor(float R, float G, float B);
static float ScreenHeight();
static float ScreenWidth();
static bool IsAppRunning(const char* TitleId);
private:

};
Expand Down
Loading

0 comments on commit 26ebd9d

Please sign in to comment.