diff --git a/.gitignore b/.gitignore index e47028b..525691e 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ CTestTestfile.cmake _deps .vscode build +data/daemon diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..6945b2d --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "ps4-ezremote-server"] + path = ps4-ezremote-server + url = git@github.com:cy33hc/ps4-ezremote-server.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 2bace7d..ec7f66b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ add_executable(ezremote_client source/actions.cpp source/config.cpp source/crypt.c + source/daemon.cpp source/fs.cpp source/gui.cpp source/getentropy.c @@ -68,10 +69,6 @@ add_executable(ezremote_client source/mem_file.cpp ) -add_self(ezremote_client) - -add_pkg(ezremote_client ${CMAKE_SOURCE_DIR}/data "RMTC00001" "ezRemote Client" "01.40" 32 0) - target_link_libraries(ezremote_client dbglogger c @@ -116,4 +113,15 @@ target_link_libraries(ezremote_client SceNet SceBgft SceAppInstUtil + SceLncUtil ) + +add_self(ezremote_client) +add_pkg(ezremote_client ${CMAKE_SOURCE_DIR}/data "RMTC00001" "ezRemote Client" "01.40" 32 0) + +add_custom_target(package + COMMAND mkdir -p ${PROJECT_SOURCE_DIR}/data/daemon + COMMAND cp ${PROJECT_SOURCE_DIR}/ps4-ezremote-server/data/eboot.bin ${PROJECT_SOURCE_DIR}/data/daemon/daemon.self + COMMAND cp ${PROJECT_SOURCE_DIR}/ps4-ezremote-server/data/eboot.md5 ${PROJECT_SOURCE_DIR}/data/daemon/daemon.md5 + COMMAND cp ${PROJECT_SOURCE_DIR}/ps4-ezremote-server/data/sce_sys/param.sfo ${PROJECT_SOURCE_DIR}/data/daemon/param +) \ No newline at end of file diff --git a/ps4-ezremote-server b/ps4-ezremote-server new file mode 160000 index 0000000..4212e37 --- /dev/null +++ b/ps4-ezremote-server @@ -0,0 +1 @@ +Subproject commit 4212e371682cdaf863b836ebddec19113e0dfaf7 diff --git a/source/daemon.cpp b/source/daemon.cpp new file mode 100644 index 0000000..6fcdb21 --- /dev/null +++ b/source/daemon.cpp @@ -0,0 +1,139 @@ +#include +#include "system.h" +#include "fs.h" +#include "dbglogger.h" + +extern "C" +{ +#include "orbis_jbc.h" + int sceLncUtilGetAppId(const char *tid); +} + +#define EZREMOTE_SERVER_TITLEID "EZSR00001" +#define EZREMOTE_CLIENT_TITLEID "RMTC00001" + +#define DAEMON_PATH "/system/vsh/app/" EZREMOTE_SERVER_TITLEID +#define DAEMON_SRC_PATH "/mnt/sandbox/pfsmnt/" EZREMOTE_CLIENT_TITLEID "-app0/daemon" + +namespace Daemon +{ + int copyFile(const char *sourcefile, const char *destfile) + { + int src = sceKernelOpen(sourcefile, 0x0000, 0); + if (src > 0) + { + int out = sceKernelOpen(destfile, 0x0001 | 0x0200 | 0x0400, 0777); + if (out > 0) + { + size_t bytes; + char *buffer = (char *)malloc(65536); + if (buffer != NULL) + { + while (0 < (bytes = sceKernelRead(src, buffer, 65536))) + sceKernelWrite(out, buffer, bytes); + free(buffer); + } + sceKernelClose(out); + } + else + return -1; + + sceKernelClose(src); + return 0; + } + + dbglogger_log("[ELFLOADER] fuxking error"); + dbglogger_log("[Itemz-loader:%s:%i] ----- src fd = %i---", __FUNCTION__, __LINE__, src); + + return -1; + } + + int MD5_hash_compare(const std::string &file1, const std::string &file2) + { + std::vector file1_content = FS::Load(file1); + std::vector file2_content = FS::Load(file2); + + std::string str1 = std::string(file1_content.data(), file1_content.size()); + std::string str2 = std::string(file1_content.data(), file1_content.size()); + + return str1.compare(str2); + } + + bool IsDaemonOutdated(void) + { + bool res = true; + if (FS::FileExists(DAEMON_PATH "/eboot.md5")) + { + res = MD5_hash_compare(DAEMON_PATH "/daemon.md5", DAEMON_SRC_PATH "/deamon.md5"); + dbglogger_log("Daemon Is Outdated?: %s", res ? "Yes" : "No"); + } + + return res; + } + + uint32_t LaunchDaemon(const char *TITLE_ID) + { + uint32_t userId = -1; + + LncAppParam param; + param.size = sizeof(LncAppParam); + param.user_id = userId; + param.app_opt = 0; + param.crash_report = 0; + param.LaunchAppCheck_flag = LaunchApp_SkipSystemUpdate; + + return sceLncUtilLaunchApp(TITLE_ID, NULL, ¶m); + + return 0; + } + + bool BootDaemonServices() + { + dbglogger_log("Booting Daemon Services"); + + if (!FS::FolderExists(DAEMON_PATH) || IsDaemonOutdated()) + { + if (mount_large_fs("/dev/da0x4.crypt", "/system", "exfatfs", "511", MNT_UPDATE) != 0) + { + dbglogger_log("mounting /system failed with %s.", strerror(errno)); + return false; + } + else + { + + dbglogger_log("Remount Successful"); + // Delete the folder and all its files + FS::RmRecursive(DAEMON_PATH); + FS::MkDirs(DAEMON_PATH); + FS::MkDirs(DAEMON_PATH "/sce_sys"); + + if (copyFile(DAEMON_SRC_PATH "/param", DAEMON_PATH "/sce_sys/param.sfo") != -1) + { + if (copyFile(DAEMON_SRC_PATH "/daemon.self", DAEMON_PATH "/eboot.bin") != 0 || + copyFile(DAEMON_SRC_PATH "/daemon.md5", DAEMON_PATH "/daemon.md5") != 0) + { + dbglogger_log("Creating the Daemon eboot failed to create: %s", strerror(errno)); + return false; + } + } + else + { + dbglogger_log("Copying Daemon files failed"); + return false; + } + } + } + + int32_t appid = sceLncUtilGetAppId(EZREMOTE_SERVER_TITLEID); + // Launch Daemon with silent + if ((appid & ~0xFFFFFF) != 0x60000000) + { + appid = LaunchDaemon(EZREMOTE_SERVER_TITLEID); + dbglogger_log("Launched Daemon AppId: %x", appid); + } + else + dbglogger_log("Found Daemon AppId: %x", appid); + + return true; + } +} \ No newline at end of file diff --git a/source/daemon.h b/source/daemon.h new file mode 100644 index 0000000..df464a5 --- /dev/null +++ b/source/daemon.h @@ -0,0 +1,9 @@ +#ifndef EZ_DAEMON_H +#define EZ_DAEMON_H + +namespace Daemon +{ + bool BootDaemonServices(); +} + +#endif \ No newline at end of file diff --git a/source/installer.cpp b/source/installer.cpp index 99433e9..dbca34e 100644 --- a/source/installer.cpp +++ b/source/installer.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -219,6 +220,40 @@ namespace INSTALLER return title; } + std::string StoreBgInstallHostData(RemoteSettings *settings, const std::string &path) + { + std::string hash = Util::UrlHash(settings->server + path + settings->username + settings->password + std::to_string(settings->type)); + json_object *history_item_obj = json_object_new_object(); + json_object_object_add(history_item_obj, "hash", json_object_new_string(hash.c_str())); + json_object_object_add(history_item_obj, "url", json_object_new_string(settings->server)); + json_object_object_add(history_item_obj, "path", json_object_new_string(path.c_str())); + json_object_object_add(history_item_obj, "username", json_object_new_string(settings->username)); + json_object_object_add(history_item_obj, "password", json_object_new_string(settings->password)); + json_object_object_add(history_item_obj, "type", json_object_new_int(settings->type)); + + if (settings->type == CLIENT_TYPE_HTTP_SERVER) + { + json_object_object_add(history_item_obj, "http_server_type", json_object_new_string(settings->http_server_type)); + } + + const char *params_str = json_object_to_json_string(history_item_obj); + + httplib::Client client = httplib::Client(std::string("http://localhost:") + std::to_string(http_int_server_port)); + client.set_connection_timeout(1); + + if (auto res = client.Post("/store_bg_install_data", params_str, "application/json")) + { + if (HTTP_SUCCESS(res->status)) + { + } + else + { + return ""; + } + } + return hash; + } + std::string getRemoteUrl(const std::string path, bool encodeUrl) { if (strlen(remote_settings->username) == 0 && strlen(remote_settings->password) == 0 && @@ -1195,6 +1230,7 @@ namespace INSTALLER std::string EzRemoteServerVersion() { httplib::Client client = httplib::Client(std::string("http://localhost:") + std::to_string(http_int_server_port)); + client.set_connection_timeout(1); if (auto res = client.Get("/version")) { @@ -1290,7 +1326,6 @@ namespace INSTALLER RemoteClient *GetRemoteClient(RemoteSettings *settings) { RemoteClient *tmp_client = nullptr; - ; if (settings->type == CLIENT_TYPE_HTTP_SERVER) { diff --git a/source/main.cpp b/source/main.cpp index 0c92f88..63ee7b5 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -20,6 +20,7 @@ #include "server/http_server.h" #include "clients/gdrive.h" #include "config.h" +#include "daemon.h" #include "lang.h" #include "gui.h" #include "util.h" @@ -324,6 +325,8 @@ int main() terminate(); } + Daemon::BootDaemonServices(); + if (load_sys_modules() != 0) return 0; diff --git a/source/orbis_jbc.c b/source/orbis_jbc.c index dfb4cd6..9c546fa 100644 --- a/source/orbis_jbc.c +++ b/source/orbis_jbc.c @@ -45,25 +45,34 @@ static void build_iovec(struct iovec** iov, int* iovlen, const char* name, const int mount_large_fs(const char* device, const char* mountpoint, const char* fstype, const char* mode, unsigned int flags) { - struct iovec* iov = NULL; - int iovlen = 0; + struct iovec* iov = NULL; + int iovlen = 0; + int ret; - unmount(mountpoint, 0); + build_iovec(&iov, &iovlen, "fstype", fstype, -1); + build_iovec(&iov, &iovlen, "fspath", mountpoint, -1); + build_iovec(&iov, &iovlen, "from", device, -1); + build_iovec(&iov, &iovlen, "large", "yes", -1); + build_iovec(&iov, &iovlen, "timezone", "static", -1); + build_iovec(&iov, &iovlen, "async", "", -1); + build_iovec(&iov, &iovlen, "ignoreacl", "", -1); - build_iovec(&iov, &iovlen, "fstype", fstype, -1); - build_iovec(&iov, &iovlen, "fspath", mountpoint, -1); - build_iovec(&iov, &iovlen, "from", device, -1); - build_iovec(&iov, &iovlen, "large", "yes", -1); - build_iovec(&iov, &iovlen, "timezone", "static", -1); - build_iovec(&iov, &iovlen, "async", "", -1); - build_iovec(&iov, &iovlen, "ignoreacl", "", -1); + if (mode) { + build_iovec(&iov, &iovlen, "dirmask", mode, -1); + build_iovec(&iov, &iovlen, "mask", mode, -1); + } - if (mode) { - build_iovec(&iov, &iovlen, "dirmask", mode, -1); - build_iovec(&iov, &iovlen, "mask", mode, -1); - } + dbglogger_log("##^ [I] Mounting %s \"%s\" to \"%s\"", fstype, device, mountpoint); + ret = nmount(iov, iovlen, flags); + if (ret < 0) { + goto error; + } + else { + dbglogger_log("##^ [I] Success."); + } - return nmount(iov, iovlen, flags); +error: + return ret; } // Variables for (un)jailbreaking diff --git a/source/system.cpp b/source/system.cpp index 6386b29..86a2092 100644 --- a/source/system.cpp +++ b/source/system.cpp @@ -14,6 +14,7 @@ int (*sceRtcFormatRFC3339LocalTime)(char *pszDateTime, const OrbisTick *tick); unsigned int (*sceRtcGetTickResolution)(); int (*sceShellUIUtilLaunchByUri)(const char *uri, SceShellUIUtilLaunchByUriParam *param); int (*sceShellUIUtilInitialize)(); +// int (*sceLncUtilGetAppId)(const char* tid); void convertUtcToLocalTime(const OrbisDateTime *utc, OrbisDateTime *local_time) { @@ -107,6 +108,20 @@ int load_sys_modules() return -1; } + /* + handle = sceKernelLoadStartModule("/system/common/lib/libSceSystemService.sprx", 0, NULL, 0, 0, 0); + if (handle == 0) + { + return -1; + } + + sceKernelDlsym(handle, "sceLncUtilGetAppId", (void **)&sceLncUtilGetAppId); + if (sceLncUtilGetAppId == NULL) + { + return -1; + } + */ + if (sceShellUIUtilInitialize() < 0) return -1; return 0; diff --git a/source/system.h b/source/system.h index 4f1e3e1..0586df8 100644 --- a/source/system.h +++ b/source/system.h @@ -37,6 +37,7 @@ extern int (*sceRtcFormatRFC3339LocalTime)(char *pszDateTime, const OrbisTick *t extern unsigned int (*sceRtcGetTickResolution)(); extern int (*sceShellUIUtilLaunchByUri)(const char *uri, SceShellUIUtilLaunchByUriParam *param); extern int (*sceShellUIUtilInitialize)(); +// extern int (*sceLncUtilGetAppId)(const char* tid); int load_sys_modules(); void convertUtcToLocalTime(const OrbisDateTime *utc, OrbisDateTime *local_time); diff --git a/source/windows.cpp b/source/windows.cpp index 3d2b4ae..1b89f2c 100644 --- a/source/windows.cpp +++ b/source/windows.cpp @@ -139,10 +139,10 @@ namespace Windows overwrite_type = OVERWRITE_PROMPT; local_paste_files.clear(); remote_paste_files.clear(); - //std::string cur_version = INSTALLER::EzRemoteServerVersion(); - //ezremote_server_version_match = cur_version.empty() || (cur_version.compare(EZREMOTE_SERVER_REQUIRED_VERSION) == 0); - show_ezremote_server_warning = false; //!ezremote_server_version_match; - //dbglogger_log("verion=%s, show_warning=%d", cur_version.c_str(), show_ezremote_server_warning); + std::string cur_version = INSTALLER::EzRemoteServerVersion(); + ezremote_server_version_match = cur_version.empty() || (cur_version.compare(EZREMOTE_SERVER_REQUIRED_VERSION) == 0); + show_ezremote_server_warning = !ezremote_server_version_match; + dbglogger_log("verion=%s, show_warning=%d", cur_version.c_str(), show_ezremote_server_warning); Actions::RefreshLocalFiles(false); } @@ -1878,6 +1878,7 @@ namespace Windows { show_bg_download_progress = false; SetModalMode(false); + ImGui::CloseCurrentPopup(); } if (ImGui::IsWindowAppearing()) @@ -1918,7 +1919,7 @@ namespace Windows ImGui::OpenPopup(lang_strings[STR_SETTINGS]); ImGui::SetNextWindowPos(ImVec2(1050, 80)); - ImGui::SetNextWindowSizeConstraints(ImVec2(850, 80), ImVec2(850, 750), NULL, NULL); + ImGui::SetNextWindowSizeConstraints(ImVec2(850, 80), ImVec2(850, 850), NULL, NULL); if (ImGui::BeginPopupModal(lang_strings[STR_SETTINGS], NULL, ImGuiWindowFlags_AlwaysAutoResize)) { char id[192];