first working commit
This commit is contained in:
+7
-2
@@ -34,8 +34,6 @@ target_compile_definitions(${PROJECT_NAME}.elf PRIVATE EZREMOTE_VERSION=${APP_VE
|
|||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME}.elf
|
target_link_libraries(${PROJECT_NAME}.elf
|
||||||
z
|
z
|
||||||
c
|
|
||||||
c++
|
|
||||||
crypto
|
crypto
|
||||||
ssl
|
ssl
|
||||||
json-c
|
json-c
|
||||||
@@ -47,3 +45,10 @@ target_link_libraries(${PROJECT_NAME}.elf
|
|||||||
SceNet
|
SceNet
|
||||||
SceSystemService
|
SceSystemService
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_custom_target(package
|
||||||
|
DEPENDS ${PROJECT_NAME}.elf
|
||||||
|
COMMAND /opt/ps4-payload-sdk/bin/orbis-strip ${PROJECT_NAME}.elf
|
||||||
|
COMMAND cp ${PROJECT_NAME}.elf ${CMAKE_CURRENT_SOURCE_DIR}/../data/daemon/daemon.elf
|
||||||
|
|
||||||
|
)
|
||||||
+1
-2
@@ -11,11 +11,10 @@
|
|||||||
#include "clients/remote_client.h"
|
#include "clients/remote_client.h"
|
||||||
|
|
||||||
#define APP_ID "ezremote-client"
|
#define APP_ID "ezremote-client"
|
||||||
#define DATA_PATH "/data/homebrew/" APP_ID
|
#define DATA_PATH "/data/" APP_ID
|
||||||
#define PKG_INSTALL_HISTORY_PATH DATA_PATH "/pkg_install_history.json"
|
#define PKG_INSTALL_HISTORY_PATH DATA_PATH "/pkg_install_history.json"
|
||||||
#define BG_DOWNLOAD_HISTORY_PATH DATA_PATH "/bg_download_history.json"
|
#define BG_DOWNLOAD_HISTORY_PATH DATA_PATH "/bg_download_history.json"
|
||||||
#define DEBUG_SERVER_LOG_PATH DATA_PATH "/ezremote_server.log"
|
#define DEBUG_SERVER_LOG_PATH DATA_PATH "/ezremote_server.log"
|
||||||
#define CLIENT_ELF_PATH DATA_PATH "/ezremote_client.elf"
|
|
||||||
|
|
||||||
#define HTTP_SERVER_APACHE "Apache"
|
#define HTTP_SERVER_APACHE "Apache"
|
||||||
#define HTTP_SERVER_MS_IIS "Microsoft IIS"
|
#define HTTP_SERVER_MS_IIS "Microsoft IIS"
|
||||||
|
|||||||
@@ -265,12 +265,14 @@ namespace FS
|
|||||||
|
|
||||||
if (dirent->d_type & DT_DIR)
|
if (dirent->d_type & DT_DIR)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
std::vector<std::string> files = FS::ListFiles(path + "/" + dirent->d_name);
|
std::vector<std::string> files = FS::ListFiles(path + "/" + dirent->d_name);
|
||||||
for (std::vector<std::string>::iterator it = files.begin(); it != files.end();)
|
for (std::vector<std::string>::iterator it = files.begin(); it != files.end();)
|
||||||
{
|
{
|
||||||
out.push_back(std::string(dirent->d_name) + "/" + *it);
|
out.push_back(std::string(dirent->d_name) + "/" + *it);
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "server/http_server.h"
|
#include "server/http_server.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "dbglogger.h"
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
@@ -80,6 +81,9 @@ int main(int argc, char *argv[])
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dbglogger_init();
|
||||||
|
dbglogger_log("If you see this you've set up dbglogger correctly.");
|
||||||
|
|
||||||
CONFIG::LoadPackageInstallHostData();
|
CONFIG::LoadPackageInstallHostData();
|
||||||
CONFIG::LoadBgDownloadData();
|
CONFIG::LoadBgDownloadData();
|
||||||
|
|
||||||
|
|||||||
@@ -1,122 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/uio.h>
|
|
||||||
#include <orbis/libkernel.h>
|
|
||||||
#include <libjbc.h>
|
|
||||||
|
|
||||||
#define SYSCALL(nr, fn) __attribute__((naked)) fn\
|
|
||||||
{\
|
|
||||||
asm volatile("mov $" #nr ", %rax\nmov %rcx, %r10\nsyscall\nret");\
|
|
||||||
}
|
|
||||||
|
|
||||||
SYSCALL(22, static int unmount(const char* path, int flags))
|
|
||||||
SYSCALL(378, static int nmount(struct iovec* iov, unsigned int niov, int flags))
|
|
||||||
|
|
||||||
static void build_iovec(struct iovec** iov, int* iovlen, const char* name, const void* val, size_t len) {
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (*iovlen < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
i = *iovlen;
|
|
||||||
*iov = (struct iovec*)realloc(*iov, sizeof **iov * (i + 2));
|
|
||||||
if (*iov == NULL) {
|
|
||||||
*iovlen = -1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
(*iov)[i].iov_base = strdup(name);
|
|
||||||
(*iov)[i].iov_len = strlen(name) + 1;
|
|
||||||
++i;
|
|
||||||
|
|
||||||
(*iov)[i].iov_base = (void*)val;
|
|
||||||
if (len == (size_t)-1) {
|
|
||||||
if (val != NULL)
|
|
||||||
len = strlen((const char*)val) + 1;
|
|
||||||
else
|
|
||||||
len = 0;
|
|
||||||
}
|
|
||||||
(*iov)[i].iov_len = (int)len;
|
|
||||||
|
|
||||||
*iovlen = ++i;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
if (mode) {
|
|
||||||
build_iovec(&iov, &iovlen, "dirmask", mode, -1);
|
|
||||||
build_iovec(&iov, &iovlen, "mask", mode, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return nmount(iov, iovlen, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Variables for (un)jailbreaking
|
|
||||||
jbc_cred g_Cred;
|
|
||||||
jbc_cred g_RootCreds;
|
|
||||||
|
|
||||||
// Verify jailbreak
|
|
||||||
static int is_jailbroken()
|
|
||||||
{
|
|
||||||
FILE *s_FilePointer = fopen("/user/.jailbreak", "w");
|
|
||||||
|
|
||||||
if (!s_FilePointer)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
fclose(s_FilePointer);
|
|
||||||
remove("/user/.jailbreak");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Jailbreaks creds
|
|
||||||
static int jailbreak()
|
|
||||||
{
|
|
||||||
if (is_jailbroken())
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
jbc_get_cred(&g_Cred);
|
|
||||||
g_RootCreds = g_Cred;
|
|
||||||
jbc_jailbreak_cred(&g_RootCreds);
|
|
||||||
jbc_set_cred(&g_RootCreds);
|
|
||||||
|
|
||||||
return (is_jailbroken());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize jailbreak
|
|
||||||
int initialize_jbc()
|
|
||||||
{
|
|
||||||
// Pop notification depending on jailbreak result
|
|
||||||
if (!jailbreak())
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unload libjbc libraries
|
|
||||||
void terminate_jbc()
|
|
||||||
{
|
|
||||||
if (!is_jailbroken())
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Restores original creds
|
|
||||||
jbc_set_cred(&g_Cred);
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#ifndef __ORBIS_JBC_H__
|
|
||||||
#define __ORBIS_JBC_H__
|
|
||||||
|
|
||||||
#define MNT_UPDATE 0x0000000000010000ULL
|
|
||||||
|
|
||||||
int initialize_jbc();
|
|
||||||
void terminate_jbc();
|
|
||||||
int mount_large_fs(const char* device, const char* mountpoint, const char* fstype, const char* mode, unsigned int flags);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -183,11 +183,8 @@ namespace HttpServer
|
|||||||
|
|
||||||
static void DeleteRemoteClient(RemoteClient *tmp_client)
|
static void DeleteRemoteClient(RemoteClient *tmp_client)
|
||||||
{
|
{
|
||||||
if (!dynamic_cast<BaseClient*>(tmp_client))
|
tmp_client->Quit();
|
||||||
{
|
delete tmp_client;
|
||||||
tmp_client->Quit();
|
|
||||||
delete tmp_client;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void *DownloadFilesThread(void *argp)
|
void *DownloadFilesThread(void *argp)
|
||||||
@@ -292,7 +289,9 @@ namespace HttpServer
|
|||||||
void *ServerThread(void *argp)
|
void *ServerThread(void *argp)
|
||||||
{
|
{
|
||||||
svr->Get("/", [&](const Request &req, Response &res)
|
svr->Get("/", [&](const Request &req, Response &res)
|
||||||
{ res.set_redirect("/index.html"); });
|
{
|
||||||
|
res.set_redirect("/index.html");
|
||||||
|
});
|
||||||
|
|
||||||
svr->Post("/store_bg_install_data", [&](const Request &req, Response &res)
|
svr->Post("/store_bg_install_data", [&](const Request &req, Response &res)
|
||||||
{
|
{
|
||||||
@@ -340,6 +339,18 @@ namespace HttpServer
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
svr->Get("/ls", [&](const Request &req, Response &res)
|
||||||
|
{
|
||||||
|
std::vector<std::string> files = FS::ListFiles("/");
|
||||||
|
std::string out;
|
||||||
|
for (int i=0; i < files.size(); i++)
|
||||||
|
{
|
||||||
|
out.append(files[i]).append("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
res.set_content(out, "text/plain");
|
||||||
|
});
|
||||||
|
|
||||||
svr->Get("/bg_install/(.*)", [&](const Request &req, Response &res)
|
svr->Get("/bg_install/(.*)", [&](const Request &req, Response &res)
|
||||||
{
|
{
|
||||||
std::string hash = req.matches[1];
|
std::string hash = req.matches[1];
|
||||||
@@ -352,24 +363,7 @@ namespace HttpServer
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pkg_host_data->host_info.type == CLIENT_TYPE_HTTP_SERVER ||
|
tmp_client = GetRemoteClient(&(pkg_host_data->host_info));
|
||||||
pkg_host_data->host_info.type == CLIENT_TYPE_WEBDAV ||
|
|
||||||
pkg_host_data->host_info.type == CLIENT_TYPE_FILEHOST)
|
|
||||||
{
|
|
||||||
if (pkg_host_data->client == nullptr)
|
|
||||||
{
|
|
||||||
pkg_host_data->client = GetRemoteClient(&(pkg_host_data->host_info));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
tmp_client = pkg_host_data->client;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
tmp_client = GetRemoteClient(&(pkg_host_data->host_info));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tmp_client == nullptr)
|
if (tmp_client == nullptr)
|
||||||
{
|
{
|
||||||
res.status = 500;
|
res.status = 500;
|
||||||
@@ -378,21 +372,57 @@ namespace HttpServer
|
|||||||
|
|
||||||
std::string path = pkg_host_data->path;
|
std::string path = pkg_host_data->path;
|
||||||
|
|
||||||
res.status = 206;
|
/*
|
||||||
size_t range_len = (req.ranges[0].second - req.ranges[0].first) + 1;
|
if (req.method == "HEAD")
|
||||||
|
{
|
||||||
std::pair<ssize_t, ssize_t> range = req.ranges[0];
|
int64_t file_size;
|
||||||
res.set_content_provider(
|
int ret;
|
||||||
range_len, "application/octet-stream",
|
|
||||||
[tmp_client, path, range, range_len](size_t offset, size_t length, DataSink &sink) {
|
|
||||||
int ret;
|
|
||||||
ret = tmp_client->GetRange(path, sink, range_len, range.first);
|
|
||||||
return (ret==1);
|
|
||||||
},
|
|
||||||
[tmp_client](bool success) {
|
|
||||||
DeleteRemoteClient(tmp_client);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
res.status = 204;
|
||||||
|
res.set_header("Content-Length", std::to_string(pkg_host_data->file_size));
|
||||||
|
res.set_header("Accept-Ranges", "bytes");
|
||||||
|
DeleteRemoteClient(tmp_client);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (req.ranges.empty())
|
||||||
|
{
|
||||||
|
res.status = 200;
|
||||||
|
|
||||||
|
res.set_content_provider(
|
||||||
|
(1024*128), "application/octet-stream",
|
||||||
|
[tmp_client, path](size_t offset, size_t length, DataSink &sink) {
|
||||||
|
int ret = tmp_client->GetRange(path, sink, length, offset);
|
||||||
|
return (ret == 1);
|
||||||
|
},
|
||||||
|
[tmp_client, path](bool success) {
|
||||||
|
DeleteRemoteClient(tmp_client);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
res.status = 206;
|
||||||
|
size_t range_len = (req.ranges[0].second - req.ranges[0].first) + 1;
|
||||||
|
if (req.ranges[0].second >= 18000000000000000000ul)
|
||||||
|
{
|
||||||
|
range_len = PKG_INITIAL_REQUEST_SIZE;
|
||||||
|
res.set_header("Content-Length", std::to_string(range_len));
|
||||||
|
res.set_header("Content-Range", std::string("bytes ") + std::to_string(req.ranges[0].first)+"-" + std::to_string(req.ranges[0].first+PKG_INITIAL_REQUEST_SIZE-1) + "/"+std::to_string(range_len));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<ssize_t, ssize_t> range = req.ranges[0];
|
||||||
|
res.set_content_provider(
|
||||||
|
range_len, "application/octet-stream",
|
||||||
|
[tmp_client, path, range, range_len](size_t offset, size_t length, DataSink &sink) {
|
||||||
|
int ret;
|
||||||
|
ret = tmp_client->GetRange(path, sink, range_len, range.first);
|
||||||
|
return (ret==1);
|
||||||
|
},
|
||||||
|
[tmp_client, path, range](bool success) {
|
||||||
|
DeleteRemoteClient(tmp_client);
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
svr->Post("/download_url", [&](const Request &req, Response &res)
|
svr->Post("/download_url", [&](const Request &req, Response &res)
|
||||||
|
|||||||
Reference in New Issue
Block a user