From 4e9c8d9f0e6a9006e84f492ff5d7878fae4457df Mon Sep 17 00:00:00 2001 From: Greg Date: Sun, 18 Dec 2022 10:05:47 -0700 Subject: [PATCH] Clean up libjbc, add sqlite library, App Start/Stop API commands added & Added more to lncutil temp class. --- .gitmodules | 3 + External/LibSQLite-ps4 | 1 + External/ps4-libjbc | 2 +- Misc/libjbc.h | 6 -- Playstation/OrbisLibAPI/Apps.cpp | 71 +++++++++++++++++++ Playstation/OrbisLibAPI/Apps.h | 2 + Playstation/OrbisLibAPI/LncUtil.cpp | 10 +-- Playstation/OrbisLibAPI/LncUtil.h | 34 +++++---- Playstation/OrbisLibAPI/Version.h | 22 +++--- Playstation/OrbisLibAPI/main.cpp | 2 +- .../OrbisLib/Classes/Target/Application.cs | 65 ++++++++++++++++- Windows/Libraries/OrbisLib/Common/API/API.cs | 2 +- .../Controls/AppPanel.xaml.cs | 13 +++- .../Resources/BuildNumber.txt | 2 +- .../Resources/BuildString.txt | 2 +- 15 files changed, 193 insertions(+), 44 deletions(-) create mode 160000 External/LibSQLite-ps4 diff --git a/.gitmodules b/.gitmodules index fb18d61..e9dae76 100644 --- a/.gitmodules +++ b/.gitmodules @@ -9,3 +9,6 @@ [submodule "External/ps4-libjbc"] path = External/ps4-libjbc url = https://github.com/OSM-Made/ps4-libjbc +[submodule "External/LibSQLite-ps4"] + path = External/LibSQLite-ps4 + url = https://github.com/bucanero/libSQLite-ps4 diff --git a/External/LibSQLite-ps4 b/External/LibSQLite-ps4 new file mode 160000 index 0000000..0d55afb --- /dev/null +++ b/External/LibSQLite-ps4 @@ -0,0 +1 @@ +Subproject commit 0d55afbab1b97de9ff4ca486167123044de13c01 diff --git a/External/ps4-libjbc b/External/ps4-libjbc index e155da5..513b6d7 160000 --- a/External/ps4-libjbc +++ b/External/ps4-libjbc @@ -1 +1 @@ -Subproject commit e155da5ce394f2ced2a344f733f9fcf5a064dd35 +Subproject commit 513b6d78eb56c8d5e824de207e6e89c211180473 diff --git a/Misc/libjbc.h b/Misc/libjbc.h index 7c9c564..724ad1e 100644 --- a/Misc/libjbc.h +++ b/Misc/libjbc.h @@ -15,17 +15,11 @@ extern "C" size_t data_size; }; - struct ProcInfo - { - char ProcName[32]; - }; - void jbc_run_as_root(void(*fn)(void* arg), void* arg, int cwd_mode); int jbc_mount_in_sandbox(const char* system_path, const char* mnt_name); int jbc_unmount_in_sandbox(const char* mnt_name); int jbc_set_proc_name(const char* New_Name); int jbc_get_proc_libraries(struct LibraryInfo* out, int maxCount); - uint64_t jbc_get_proc_list(struct ProcInfo* out, int maxCount); struct jbc_cred { diff --git a/Playstation/OrbisLibAPI/Apps.cpp b/Playstation/OrbisLibAPI/Apps.cpp index 3e15798..7a15352 100644 --- a/Playstation/OrbisLibAPI/Apps.cpp +++ b/Playstation/OrbisLibAPI/Apps.cpp @@ -1,6 +1,7 @@ #include "Common.h" #include "Apps.h" #include +#include void Apps::HandleAPI(OrbisNetId Sock, APIPacket* Packet) { @@ -17,6 +18,18 @@ void Apps::HandleAPI(OrbisNetId Sock, APIPacket* Packet) SendAppStatus(Sock, titleId); + break; + + case API_APPS_START: + + StartApp(Sock, titleId); + + break; + + case API_APPS_STOP: + + KillApp(Sock, titleId); + break; } } @@ -64,6 +77,64 @@ void Apps::SendAppStatus(OrbisNetId Sock, const char* TitleId) } } +void Apps::StartApp(OrbisNetId Sock, const char* TitleId) +{ + LaunchAppParam appParam; + appParam.size = sizeof(LaunchAppParam); + + if (auto res = sceUserServiceGetForegroundUser(&appParam.userId) != 0) + { + klog("sceUserServiceGetForegroundUser(): Failed with error %llX\n", res); + + SockSendInt(Sock, 0); + return; + } + + auto res = LncUtil::sceLncUtilLaunchApp(TitleId, nullptr, &appParam); + if (res <= 0) + { + klog("sceLncUtilLaunchApp() : Failed with error % llX\n", res); + + SockSendInt(Sock, 0); + return; + } + + SockSendInt(Sock, res); +} + +void Apps::KillApp(OrbisNetId Sock, const char* TitleId) +{ + int appId = 0; + + // Get the list of running processes. + std::vector processList; + GetProcessList(processList); + + for (const auto& i : processList) + { + // Get the app info using the pid. + OrbisAppInfo appInfo; + sceKernelGetAppInfo(i.pid, &appInfo); + + // Using the titleId match our desired app and return the appId from the appinfo. + if (!strcmp(appInfo.TitleId, TitleId)) + { + appId = appInfo.AppId; + + break; + } + } + + if (appId > 0 && sceSystemServiceKillApp(appId, -1, 0, 0) == 0) + { + SockSendInt(Sock, 1); + } + else + { + SockSendInt(Sock, 0); + } +} + Apps::Apps() { diff --git a/Playstation/OrbisLibAPI/Apps.h b/Playstation/OrbisLibAPI/Apps.h index b0e3a76..b8cae6b 100644 --- a/Playstation/OrbisLibAPI/Apps.h +++ b/Playstation/OrbisLibAPI/Apps.h @@ -12,4 +12,6 @@ public: private: void SendAppStatus(OrbisNetId Sock, const char* TitleId); + void StartApp(OrbisNetId Sock, const char* TitleId); + void KillApp(OrbisNetId Sock, const char* TitleId); }; diff --git a/Playstation/OrbisLibAPI/LncUtil.cpp b/Playstation/OrbisLibAPI/LncUtil.cpp index 486979a..2e3913d 100644 --- a/Playstation/OrbisLibAPI/LncUtil.cpp +++ b/Playstation/OrbisLibAPI/LncUtil.cpp @@ -3,7 +3,7 @@ uint64_t LncUtil::LibraryBaseAddress = 0; int(*LncUtil::_sceLncUtilGetAppId)(const char*); -int(*LncUtil::_GetAppStatusListForShellUIReboot)(AppStatusForShellUIReboot* outStatusList, unsigned int numEntries, unsigned int* outEntries); +int(*LncUtil::_sceLncUtilLaunchApp)(const char* titleId, char* args, LaunchAppParam* appParam); int LncUtil::Init() { @@ -44,7 +44,7 @@ int LncUtil::Init() // Set up Functions. _sceLncUtilGetAppId = (decltype(_sceLncUtilGetAppId))(LibraryBaseAddress + 0x4E10); - _GetAppStatusListForShellUIReboot = (decltype(_GetAppStatusListForShellUIReboot))(LibraryBaseAddress + 0x4FA0); + _sceLncUtilLaunchApp = (decltype(_sceLncUtilLaunchApp))(LibraryBaseAddress + 0x4C10); return 0; } @@ -62,11 +62,11 @@ int LncUtil::sceLncUtilGetAppId(const char* TitleId) } } -int LncUtil::GetAppStatusListForShellUIReboot(AppStatusForShellUIReboot* outStatusList, unsigned int numEntries, unsigned int* outEntries) +int LncUtil::sceLncUtilLaunchApp(const char* titleId, char* args, LaunchAppParam* appParam) { - if ((uint64_t)_GetAppStatusListForShellUIReboot > 0x4FA0) + if ((uint64_t)_sceLncUtilLaunchApp > 0x4C10) { - return _GetAppStatusListForShellUIReboot(outStatusList, numEntries, outEntries); + return _sceLncUtilLaunchApp(titleId, args, appParam); } else { diff --git a/Playstation/OrbisLibAPI/LncUtil.h b/Playstation/OrbisLibAPI/LncUtil.h index c4ecfff..f694a06 100644 --- a/Playstation/OrbisLibAPI/LncUtil.h +++ b/Playstation/OrbisLibAPI/LncUtil.h @@ -20,20 +20,24 @@ struct AppStatus char AppType; }; -struct AppStatusForShellUIReboot +enum Flag { - int appId; - char appType; - char appAttr; - int launchRequestAppId; - int userId; - int isActiveCdlg; - char path[1024]; - int isCoredumped; - int isPrxModuleLoadFailed; - int appLocalPid; - char crashReportMode; - char category[4]; + Flag_None = 0, + SkipLaunchCheck = 1, + SkipResumeCheck = 1, + SkipSystemUpdateCheck = 2, + RebootPatchInstall = 4, + VRMode = 8, + NonVRMode = 16 +}; + +struct LaunchAppParam +{ + unsigned int size; //0x00 + int userId; //0x04 + int appAttr; //0x08 + int enableCrashReport; //0x0C + uint64_t checkFlag; //0x10 }; class LncUtil @@ -41,10 +45,10 @@ class LncUtil public: static int Init(); static int sceLncUtilGetAppId(const char* TitleId); - static int GetAppStatusListForShellUIReboot(AppStatusForShellUIReboot* outStatusList, unsigned int numEntries, unsigned int* outEntries); + static int sceLncUtilLaunchApp(const char* titleId, char* args, LaunchAppParam* appParam); private: static uint64_t LibraryBaseAddress; static int(*_sceLncUtilGetAppId)(const char* titleId); - static int(*_GetAppStatusListForShellUIReboot)(AppStatusForShellUIReboot* outStatusList, unsigned int numEntries, unsigned int* outEntries); + static int(*_sceLncUtilLaunchApp)(const char* titleId, char* args, LaunchAppParam* appParam); }; diff --git a/Playstation/OrbisLibAPI/Version.h b/Playstation/OrbisLibAPI/Version.h index 6c291a5..cd93f95 100644 --- a/Playstation/OrbisLibAPI/Version.h +++ b/Playstation/OrbisLibAPI/Version.h @@ -1,11 +1,11 @@ -#pragma once -#define ORBISLIB_MAJOR 3 -#define ORBISLIB_MINOR 0 -#define ORBISLIB_BUILDVERSION 557 -#define stringify(a) stringify_(a) -#define stringify_(a) #a -#if defined(_DEBUG) -#define ORBISLIB_BUILDSTRING ("[OrbisLib Daemon " stringify(ORBISLIB_MAJOR) "." stringify(ORBISLIB_MINOR) "] Dev Build " stringify(ORBISLIB_BUILDVERSION) " " __DATE__ " " __TIME__) -#else -#define ORBISLIB_BUILDSTRING ("[OrbisLib Daemon " stringify(ORBISLIB_MAJOR) "." stringify(ORBISLIB_MINOR) "] Build " stringify(ORBISLIB_BUILDVERSION) " " __DATE__ " " __TIME__) -#endif +#pragma once +#define ORBISLIB_MAJOR 3 +#define ORBISLIB_MINOR 0 +#define ORBISLIB_BUILDVERSION 577 +#define stringify(a) stringify_(a) +#define stringify_(a) #a +#if defined(_DEBUG) +#define ORBISLIB_BUILDSTRING ("[OrbisLib Daemon " stringify(ORBISLIB_MAJOR) "." stringify(ORBISLIB_MINOR) "] Dev Build " stringify(ORBISLIB_BUILDVERSION) " " __DATE__ " " __TIME__) +#else +#define ORBISLIB_BUILDSTRING ("[OrbisLib Daemon " stringify(ORBISLIB_MAJOR) "." stringify(ORBISLIB_MINOR) "] Build " stringify(ORBISLIB_BUILDVERSION) " " __DATE__ " " __TIME__) +#endif diff --git a/Playstation/OrbisLibAPI/main.cpp b/Playstation/OrbisLibAPI/main.cpp index 48bd769..e546f18 100644 --- a/Playstation/OrbisLibAPI/main.cpp +++ b/Playstation/OrbisLibAPI/main.cpp @@ -85,7 +85,7 @@ int main() sceApplicationInitialize(); // start up the API. NOTE: this is blocking. - //API::Init(); + API::Init(); sceSystemServiceLoadExec("exit", 0); diff --git a/Windows/Libraries/OrbisLib/Classes/Target/Application.cs b/Windows/Libraries/OrbisLib/Classes/Target/Application.cs index dd0c972..84be02f 100644 --- a/Windows/Libraries/OrbisLib/Classes/Target/Application.cs +++ b/Windows/Libraries/OrbisLib/Classes/Target/Application.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Net.Sockets; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; namespace OrbisSuite @@ -20,7 +21,7 @@ namespace OrbisSuite public AppState GetAppState(string TitleId) { - if(TitleId.Length > 10) + if (!Regex.IsMatch(TitleId, @"[a-zA-Z]{4}\d{5}")) { Console.WriteLine($"Invaild titleId format {TitleId}"); return AppState.STATE_ERROR; @@ -48,5 +49,67 @@ namespace OrbisSuite return result; } + + public bool Start(string TitleId) + { + if (!Regex.IsMatch(TitleId, @"[a-zA-Z]{4}\d{5}")) + { + Console.WriteLine($"Invaild titleId format {TitleId}"); + return false; + } + + if (!Target.Info.Details.IsAPIAvailable) + { + return false; + } + + APIResults apiResult = API.CallLong(Target.Info.IPAddress, Settings.CreateInstance().APIPort, new APIPacket() { PacketVersion = Config.PacketVersion, Command = APICommands.API_APP_START }, out Socket Sock); + + if (apiResult != APIResults.API_OK) + return false; + + // Send the titleId of the app. + var bytes = Encoding.ASCII.GetBytes(TitleId.PadRight(9, '\0')).Take(9).ToArray(); + Sock.Send(bytes); + + // Get the state from API. + var result = Sock.RecvInt32(); + + // close socket. + Sock.Close(); + + return (result == 1); + } + + public bool Stop(string TitleId) + { + if (!Regex.IsMatch(TitleId, @"[a-zA-Z]{4}\d{5}")) + { + Console.WriteLine($"Invaild titleId format {TitleId}"); + return false; + } + + if (!Target.Info.Details.IsAPIAvailable) + { + return false; + } + + APIResults apiResult = API.CallLong(Target.Info.IPAddress, Settings.CreateInstance().APIPort, new APIPacket() { PacketVersion = Config.PacketVersion, Command = APICommands.API_APP_STOP }, out Socket Sock); + + if (apiResult != APIResults.API_OK) + return false; + + // Send the titleId of the app. + var bytes = Encoding.ASCII.GetBytes(TitleId.PadRight(9, '\0')).Take(9).ToArray(); + Sock.Send(bytes); + + // Get the state from API. + var result = Sock.RecvInt32(); + + // close socket. + Sock.Close(); + + return (result == 1); + } } } diff --git a/Windows/Libraries/OrbisLib/Common/API/API.cs b/Windows/Libraries/OrbisLib/Common/API/API.cs index 5a4968a..531bc60 100644 --- a/Windows/Libraries/OrbisLib/Common/API/API.cs +++ b/Windows/Libraries/OrbisLib/Common/API/API.cs @@ -14,7 +14,7 @@ namespace OrbisSuite.Common { Sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - return Sock.EasyConnect(IPAddr, Port, 2000); + return Sock.EasyConnect(IPAddr, Port, 4000); } /// diff --git a/Windows/OrbisNeighborHood/Controls/AppPanel.xaml.cs b/Windows/OrbisNeighborHood/Controls/AppPanel.xaml.cs index e8c271a..066804b 100644 --- a/Windows/OrbisNeighborHood/Controls/AppPanel.xaml.cs +++ b/Windows/OrbisNeighborHood/Controls/AppPanel.xaml.cs @@ -122,7 +122,18 @@ namespace OrbisNeighborHood.Controls private void StartStop_Click(object sender, RoutedEventArgs e) { - Console.WriteLine($"{App.titleId} AppStatus: {AppState}"); + Task.Run(() => + { + var currentTarget = OrbisLib.Instance.SelectedTarget; + if (AppState == AppState.STATE_RUNNING || AppState == AppState.STATE_SUSPENDED) + { + currentTarget.Application.Stop(App.titleId); + } + else + { + currentTarget.Application.Start(App.titleId); + } + }); } private void Visibility_Click(object sender, RoutedEventArgs e) diff --git a/Windows/OrbisNeighborHood/Resources/BuildNumber.txt b/Windows/OrbisNeighborHood/Resources/BuildNumber.txt index dec2115..4ac7a82 100644 --- a/Windows/OrbisNeighborHood/Resources/BuildNumber.txt +++ b/Windows/OrbisNeighborHood/Resources/BuildNumber.txt @@ -1 +1 @@ -1831 +1856 diff --git a/Windows/OrbisNeighborHood/Resources/BuildString.txt b/Windows/OrbisNeighborHood/Resources/BuildString.txt index b7f55f7..3e26f93 100644 --- a/Windows/OrbisNeighborHood/Resources/BuildString.txt +++ b/Windows/OrbisNeighborHood/Resources/BuildString.txt @@ -1 +1 @@ -Version 3.0.1831 Debug Build Saturday December 17 2022 2:37 PM +Version 3.0.1856 Debug Build Saturday December 17 2022 6:19 PM