Skip to content

Commit

Permalink
fw agnostic save mounting (#155)
Browse files Browse the repository at this point in the history
* fw agnostic save mounting
from https://github.com/hzhreal/PS4-save-utils , based on cecie
* remove sandbox
* integration
  • Loading branch information
bucanero authored Dec 14, 2024
1 parent 6874a72 commit f4eeb09
Show file tree
Hide file tree
Showing 11 changed files with 568 additions and 1,075 deletions.
3 changes: 1 addition & 2 deletions include/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ int reset_app_settings(app_config_t* config);

int initialize_jbc(void);
void terminate_jbc(void);
int patch_save_libraries(void);
int unpatch_SceShellCore(void);
int initVshDataMount(void);
int get_max_pfskey_ver(void);
char* get_fw_by_pfskey_ver(int key_ver);

Expand Down
484 changes: 0 additions & 484 deletions include/orbis_patches.h

This file was deleted.

13 changes: 6 additions & 7 deletions include/saves.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
#define LOG dbglogger_log

#define APOLLO_PATH "/data/apollo/"
#define APOLLO_SANDBOX_PATH "/data/apollo/mount/%s/"

#ifdef APOLLO_ENABLE_LOGGING
#define APOLLO_APP_PATH "/data/apollo/debug/"
#define APOLLO_SANDBOX_PATH "/mnt/sandbox/LOAD00044_000%s/"
#define APOLLO_SETTING_PATH "/mnt/sandbox/LOAD00044_000%s/"
#else
#define APOLLO_APP_PATH "/mnt/sandbox/APOL00004_000/app0/assets/"
#define APOLLO_SANDBOX_PATH "/mnt/sandbox/APOL00004_000%s/"
#define APOLLO_SETTING_PATH "/mnt/sandbox/APOL00004_000%s/"
#endif

#define APOLLO_USER_PATH APOLLO_PATH "%08x/"
Expand Down Expand Up @@ -141,15 +142,15 @@ enum cmd_code_enum
};

// Save flags
#define SAVE_FLAG_LOCKED 1
#define SAVE_FLAG_ONLINE 1
#define SAVE_FLAG_OWNER 2
#define SAVE_FLAG_SELECTED 4
#define SAVE_FLAG_ZIP 8
#define SAVE_FLAG_PS2 16
#define SAVE_FLAG_PS1 32
#define SAVE_FLAG_PSV 64
#define SAVE_FLAG_TROPHY 128
#define SAVE_FLAG_ONLINE 256
#define SAVE_FLAG_LOCKED 256
#define SAVE_FLAG_PS4 512
#define SAVE_FLAG_HDD 1024
#define SAVE_FLAG_VMC 2048
Expand Down Expand Up @@ -297,7 +298,6 @@ void end_progress_bar(void);

int init_loading_screen(const char* message);
void stop_loading_screen(void);
void disable_unpatch(void);

void execCodeCommand(code_entry_t* code, const char* codecmd);

Expand All @@ -310,11 +310,10 @@ int regMgr_GetUserName(int userNumber, char* outString);
int regMgr_GetAccountId(int userNumber, uint64_t* psnAccountId);
int regMgr_SetAccountId(int userNumber, uint64_t* psnAccountId);

int create_savegame_folder(const char* folder);
int get_save_details(const save_entry_t *save, char** details);
int orbis_SaveUmount(const char* mountPath);
int orbis_SaveMount(const save_entry_t *save, uint32_t mode, char* mountPath);
int orbis_UpdateSaveParams(const char* mountPath, const char* title, const char* subtitle, const char* details, uint32_t up);
int orbis_UpdateSaveParams(const save_entry_t* save, const char* title, const char* subtitle, const char* details, uint32_t up);

int vmc_export_psv(const char* save, const char* out_path);
int vmc_export_psu(const char* path, const char* output);
Expand Down
43 changes: 43 additions & 0 deletions include/sd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef SD_H
#define SD_H

#include <stdint.h>
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

#define ENC_SEALEDKEY_LEN 0x60
#define DEC_SEALEDKEY_LEN 0x20

#define UNUSED(x) (void)(x)

typedef struct {
int blockSize;
uint8_t idk[2];
} CreatePfsSaveDataOpt;

typedef struct {
bool readOnly;
char *budgetid;
} MountSaveDataOpt;

typedef struct {
bool dummy;
} UmountSaveDataOpt;

int loadPrivLibs(void);
int generateSealedKey(uint8_t data[ENC_SEALEDKEY_LEN]);
int decryptSealedKey(uint8_t enc_key[ENC_SEALEDKEY_LEN], uint8_t dec_key[DEC_SEALEDKEY_LEN]);
int decryptSealedKeyAtPath(const char *keyPath, uint8_t decryptedSealedKey[DEC_SEALEDKEY_LEN]);
int createSave(const char *folder, const char *saveName, int blocks);
int mountSave(const char *folder, const char *saveName, const char *mountPath);
int umountSave(const char *mountPath, int handle, bool ignoreErrors);
uint16_t getMaxKeySet(void);

#ifdef __cplusplus
}
#endif

#endif // SD_H
53 changes: 27 additions & 26 deletions source/exec_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static void copySave(const save_entry_t* save, const char* exp_path)
show_message("Files successfully copied to:\n%s", exp_path);
}

static int _update_save_details(const char* sys_path, const char* mount)
static int _update_save_details(const char* sys_path, const save_entry_t* save)
{
char file_path[256];
uint8_t* iconBuf;
Expand All @@ -169,7 +169,7 @@ static int _update_save_details(const char* sys_path, const char* mount)
sfo_context_t* sfo = sfo_alloc();
if (sfo_read(sfo, file_path) == SUCCESS)
{
orbis_UpdateSaveParams(mount,
orbis_UpdateSaveParams(save,
(char*) sfo_get_param_value(sfo, "MAINTITLE"),
(char*) sfo_get_param_value(sfo, "SUBTITLE"),
(char*) sfo_get_param_value(sfo, "DETAIL"),
Expand All @@ -180,16 +180,11 @@ static int _update_save_details(const char* sys_path, const char* mount)
snprintf(file_path, sizeof(file_path), "%s" "icon0.png", sys_path);
if (read_buffer(file_path, &iconBuf, &iconSize) == SUCCESS)
{
OrbisSaveDataMountPoint mp;
OrbisSaveDataIcon icon;
snprintf(file_path, sizeof(file_path), PS4_SAVES_PATH_HDD "%s/%s_icon0.png", apollo_config.user_id, save->title_id, save->dir_name);
mkdirs(file_path);

strlcpy(mp.data, mount, sizeof(mp.data));
memset(&icon, 0x00, sizeof(icon));
icon.buf = iconBuf;
icon.bufSize = iconSize;
icon.dataSize = iconSize; // Icon data size

if (sceSaveDataSaveIcon(&mp, &icon) < 0) {
if (write_buffer(file_path, iconBuf, iconSize) < 0)
{
// Error handling
LOG("ERROR sceSaveDataSaveIcon");
}
Expand All @@ -203,7 +198,7 @@ static int _update_save_details(const char* sys_path, const char* mount)
static int _copy_save_hdd(const save_entry_t* save)
{
char copy_path[256];
char mount[32];
char mount[ORBIS_SAVE_DATA_DIRNAME_DATA_MAXSIZE];

if (!orbis_SaveMount(save, ORBIS_SAVE_DATA_MOUNT_MODE_RDWR | ORBIS_SAVE_DATA_MOUNT_MODE_CREATE2 | ORBIS_SAVE_DATA_MOUNT_MODE_COPY_ICON, mount))
return 0;
Expand All @@ -214,7 +209,7 @@ static int _copy_save_hdd(const save_entry_t* save)
copy_directory(save->path, save->path, copy_path);

snprintf(copy_path, sizeof(copy_path), "%s" "sce_sys/", save->path);
_update_save_details(copy_path, mount);
_update_save_details(copy_path, save);

orbis_SaveUmount(mount);
return 1;
Expand Down Expand Up @@ -371,7 +366,7 @@ void exportTrophiesZip(const char* exp_path)

static void dumpAllFingerprints(const save_entry_t* save)
{
char mount[32];
char mount[ORBIS_SAVE_DATA_DIRNAME_DATA_MAXSIZE];
uint64_t progress = 0;
list_node_t *node;
save_entry_t *item;
Expand Down Expand Up @@ -434,7 +429,7 @@ static void copySavePFS(const save_entry_t* save)
{
char src_path[256];
char hdd_path[256];
char mount[32];
char mount[ORBIS_SAVE_DATA_DIRNAME_DATA_MAXSIZE];
sfo_patch_t patch = {
.user_id = apollo_config.user_id,
.account_id = apollo_config.account_id,
Expand Down Expand Up @@ -485,7 +480,7 @@ static void copySavePFS(const save_entry_t* save)
patch_sfo(hdd_path, &patch);

*strrchr(hdd_path, 'p') = 0;
_update_save_details(hdd_path, mount);
_update_save_details(hdd_path, save);
orbis_SaveUmount(mount);

show_message("Encrypted save copied successfully!\n%s/%s", save->title_id, save->dir_name);
Expand Down Expand Up @@ -618,7 +613,7 @@ static int webReqHandler(dWebRequest_t* req, dWebResponse_t* res, void* list)
if (wildcard_match(req->resource, "/zip/\?\?\?\?\?\?\?\?/\?\?\?\?\?\?\?\?\?_*.zip") ||
wildcard_match(req->resource, "/PS4/\?\?\?\?\?\?\?\?\?/*.zip"))
{
char mount[32];
char mount[ORBIS_SAVE_DATA_DIRNAME_DATA_MAXSIZE];
char *base, *path;
int id = 0;

Expand Down Expand Up @@ -707,7 +702,7 @@ static void copyAllSavesUSB(const save_entry_t* save, const char* dst_path, int
{
char copy_path[256];
char save_path[256];
char mount[32];
char mount[ORBIS_SAVE_DATA_DIRNAME_DATA_MAXSIZE];
uint64_t progress = 0;
list_node_t *node;
save_entry_t *item;
Expand Down Expand Up @@ -889,15 +884,20 @@ static void import_save2vmc(const char* src, int type)
show_message("Error importing save:\n%s", src);
}

static void deleteVmcSave(const save_entry_t* save)
static int deleteVmcSave(const save_entry_t* save)
{
int ret;

if (!show_dialog(DIALOG_TYPE_YESNO, "Do you want to delete %s?", save->dir_name))
return;
return 0;

if ((save->flags & SAVE_FLAG_PS1) ? formatSave(save->blocks) : vmc_delete_save(save->dir_name))
ret = (save->flags & SAVE_FLAG_PS1) ? formatSave(save->blocks) : vmc_delete_save(save->dir_name);
if (ret)
show_message("Save successfully deleted:\n%s", save->dir_name);
else
show_message("Error! Couldn't delete save:\n%s", save->dir_name);

return ret;
}

static void exportVM2raw(const char* vm2_file, int dst, int ecc)
Expand Down Expand Up @@ -1291,11 +1291,11 @@ static void toggleBrowserHistory(int usr)

void execCodeCommand(code_entry_t* code, const char* codecmd)
{
char *tmp, mount[32];
char *tmp, mount[ORBIS_SAVE_DATA_DIRNAME_DATA_MAXSIZE];

if (selected_entry->flags & SAVE_FLAG_HDD)
{
if (!orbis_SaveMount(selected_entry, ORBIS_SAVE_DATA_MOUNT_MODE_RDWR, mount))
if (!orbis_SaveMount(selected_entry, (selected_entry->flags & SAVE_FLAG_TROPHY), mount))
{
LOG("Error Mounting Save! Check Save Mount Patches");
return;
Expand Down Expand Up @@ -1481,9 +1481,10 @@ void execCodeCommand(code_entry_t* code, const char* codecmd)
break;

case CMD_DELETE_VMCSAVE:
deleteVmcSave(selected_entry);
selected_entry->flags |= SAVE_FLAG_UPDATED;
code->activated = 0;
if (deleteVmcSave(selected_entry))
selected_entry->flags |= SAVE_FLAG_UPDATED;
else
code->activated = 0;
break;

case CMD_EXP_PS2_VM2:
Expand Down
11 changes: 4 additions & 7 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,6 @@ static void terminate(void)
{
LOG("Exiting...");
sceAudioOutClose(audio);
// Unload loaded libraries
if (unpatch_SceShellCore())
notify_popup(NOTIFICATION_ICON_DEFAULT, "PS4 Save patches removed from memory");

terminate_jbc();
sceSystemServiceLoadExec("exit", NULL);
Expand Down Expand Up @@ -588,8 +585,11 @@ s32 main(s32 argc, const char* argv[])
}

// Initialize jailbreak
if (!initialize_jbc())
if (!initialize_jbc() || !initVshDataMount())
{
notify_popup(NOTIFICATION_ICON_BAN, "Failed to initialize jailbreak!");
terminate();
}

mkdirs(APOLLO_DATA_PATH);
mkdirs(APOLLO_LOCAL_CACHE);
Expand Down Expand Up @@ -654,9 +654,6 @@ s32 main(s32 argc, const char* argv[])
drawSplashLogo(1);
#endif

// Apply save-mounter patches
patch_save_libraries();

// Setup font
SetExtraSpace(-15);
SetCurrentFont(font_adonais_regular);
Expand Down
7 changes: 7 additions & 0 deletions source/menu_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,13 @@ static void doPatchMenu(void)
return;
}

if (selected_centry->codes[0] == CMD_DELETE_VMCSAVE)
{
selected_centry->activated = 0;
SetMenu(last_menu_id[MENU_PATCHES]);
return;
}

if (selected_centry->codes[0] == CMD_VIEW_RAW_PATCH)
{
selected_centry->activated = 0;
Expand Down
Loading

0 comments on commit f4eeb09

Please sign in to comment.