Skip to content

Commit

Permalink
List encrypted saves
Browse files Browse the repository at this point in the history
  • Loading branch information
bucanero committed Jan 23, 2022
1 parent c0dcc26 commit 2e41a34
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package metadata.
TITLE := Apollo Save Tool
VERSION := 0.80
VERSION := 1.00
TITLE_ID := APOL00004
CONTENT_ID := IV0000-APOL00004_00-APOLLO0000000PS4

Expand Down
2 changes: 1 addition & 1 deletion include/saves.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ enum cmd_code_enum
CMD_RESIGN_PSV,
CMD_EXP_FINGERPRINT,
CMD_CONVERT_TO_PSV,
CMD_COPY_DUMMY_PSV,
CMD_COPY_PFS,
CMD_IMPORT_DATA_FILE,

// Bulk commands
Expand Down
2 changes: 1 addition & 1 deletion include/settings.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define APOLLO_VERSION "0.8.0" //Apollo PS4 version (about menu)
#define APOLLO_VERSION "1.0.0" //Apollo PS4 version (about menu)
#define APOLLO_DATA_VERSION 4

#define MENU_TITLE_OFF 45 //Offset of menu title text from menu mini icon
Expand Down
113 changes: 100 additions & 13 deletions source/saves.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,13 +523,13 @@ int set_ps2_codes(save_entry_t* item)

cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_USER " View Save Details", CMD_VIEW_DETAILS);
list_append(item->codes, cmd);

/*
cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_COPY " Copy dummy .PSV Save", CMD_CODE_NULL);
asprintf(&cmd->file, "APOLLO-99PS2.PSV");
cmd->options_count = 1;
cmd->options = _createOptions(2, "Copy APOLLO-99PS2.PSV to USB", CMD_COPY_DUMMY_PSV);
list_append(item->codes, cmd);

*/
return list_count(item->codes);
}

Expand Down Expand Up @@ -1059,7 +1059,93 @@ int sortSaveList_Compare(const void* a, const void* b)
return strcasecmp(((save_entry_t*) a)->name, ((save_entry_t*) b)->name);
}

static void read_usb_savegames(const char* userPath, list_t *list, uint32_t flag)
static void read_usb_encrypted_saves(const char* userPath, list_t *list, uint64_t account)
{
DIR *d, *d2;
struct dirent *dir, *dir2;
save_entry_t *item;
char savePath[256];

d = opendir(userPath);

if (!d)
return;

while ((dir = readdir(d)) != NULL)
{
if (dir->d_type != DT_DIR || strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0)
continue;

snprintf(savePath, sizeof(savePath), "%s%s", userPath, dir->d_name);
d2 = opendir(savePath);

if (!d2)
continue;

LOG("Reading %s...", savePath);

while ((dir2 = readdir(d2)) != NULL)
{
if (dir2->d_type != DT_REG || endsWith(dir2->d_name, ".bin"))
continue;

snprintf(savePath, sizeof(savePath), "%s%s/%s.bin", userPath, dir->d_name, dir2->d_name);
if (file_exists(savePath) != SUCCESS)
continue;

snprintf(savePath, sizeof(savePath), "(Encrypted) %s/%s", dir->d_name, dir2->d_name);
item = _createSaveEntry(SAVE_FLAG_PS4 | SAVE_FLAG_LOCKED, savePath);
item->type = FILE_TYPE_PS4;

asprintf(&item->path, "%s%s/", userPath, dir->d_name);
asprintf(&item->title_id, "%.9s", dir->d_name);
item->dir_name = strdup(dir2->d_name);

if (apollo_config.account_id == account)
item->flags |= SAVE_FLAG_OWNER;

snprintf(savePath, sizeof(savePath), "%s%s/%s", userPath, dir->d_name, dir2->d_name);

uint64_t size = 0;
get_file_size(savePath, &size);
item->blocks = size / ORBIS_SAVE_DATA_BLOCK_SIZE;

LOG("[%s] F(%d) name '%s'", item->title_id, item->flags, item->name);
list_append(list, item);

}
closedir(d2);
}

closedir(d);
}

static void read_usb_encrypted_savegames(const char* userPath, list_t *list)
{
DIR *d;
struct dirent *dir;
char accPath[256];
uint64_t acc_id;

d = opendir(userPath);

if (!d)
return;

while ((dir = readdir(d)) != NULL)
{
if (dir->d_type != DT_DIR || strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0)
continue;

sscanf(dir->d_name, "%lx", &acc_id);
snprintf(accPath, sizeof(accPath), "%s%s/", userPath, dir->d_name);
read_usb_encrypted_saves(accPath, list, acc_id);
}

closedir(d);
}

static void read_usb_savegames(const char* userPath, list_t *list)
{
DIR *d;
struct dirent *dir;
Expand Down Expand Up @@ -1090,7 +1176,7 @@ static void read_usb_savegames(const char* userPath, list_t *list, uint32_t flag
}

char *sfo_data = (char*) sfo_get_param_value(sfo, "MAINTITLE");
item = _createSaveEntry(flag, sfo_data);
item = _createSaveEntry(SAVE_FLAG_PS4, sfo_data);
item->type = FILE_TYPE_PS4;

sfo_data = (char*) sfo_get_param_value(sfo, "TITLE_ID");
Expand All @@ -1100,9 +1186,6 @@ static void read_usb_savegames(const char* userPath, list_t *list, uint32_t flag
sfo_data = (char*) sfo_get_param_value(sfo, "SAVEDATA_DIRECTORY");
item->dir_name = strdup(sfo_data);

// sfo_data = (char*) sfo_get_param_value(sfo, "ATTRIBUTE");
// item->flags |= (sfo_data[0] ? SAVE_FLAG_LOCKED : 0);

uint64_t* int_data = (uint64_t*) sfo_get_param_value(sfo, "ACCOUNT_ID");
if (int_data && (apollo_config.account_id == *int_data))
item->flags |= SAVE_FLAG_OWNER;
Expand All @@ -1119,7 +1202,7 @@ static void read_usb_savegames(const char* userPath, list_t *list, uint32_t flag
closedir(d);
}

static void read_hdd_savegames(const char* userPath, list_t *list, uint32_t flag)
static void read_hdd_savegames(const char* userPath, list_t *list)
{
save_entry_t *item;
sqlite3_stmt *res;
Expand All @@ -1138,7 +1221,7 @@ static void read_hdd_savegames(const char* userPath, list_t *list, uint32_t flag

while (sqlite3_step(res) == SQLITE_ROW)
{
item = _createSaveEntry(flag, (const char*) sqlite3_column_text(res, 2));
item = _createSaveEntry(SAVE_FLAG_PS4 | SAVE_FLAG_HDD, (const char*) sqlite3_column_text(res, 2));
item->type = FILE_TYPE_PS4;
item->path = strdup(userPath);
item->dir_name = strdup((const char*) sqlite3_column_text(res, 1));
Expand Down Expand Up @@ -1310,16 +1393,19 @@ list_t * ReadUsbList(const char* userPath)
save_entry_t *item;
code_entry_t *cmd;
list_t *list;
char pathEnc[64], pathDec[64];

if (dir_exists(userPath) != SUCCESS)
snprintf(pathDec, sizeof(pathDec), "%sAPOLLO/", userPath);
snprintf(pathEnc, sizeof(pathEnc), "%sSAVEDATA/", userPath);
if (dir_exists(pathDec) != SUCCESS && dir_exists(pathEnc) != SUCCESS)
return NULL;

list = list_alloc();

item = _createSaveEntry(SAVE_FLAG_PS4, CHAR_ICON_COPY " Bulk Save Management");
item->type = FILE_TYPE_MENU;
item->codes = list_alloc();
item->path = strdup(userPath);
item->path = strdup(pathDec);

cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_SIGN " Resign all Saves", CMD_RESIGN_ALL_SAVES);
list_append(item->codes, cmd);
Expand All @@ -1331,7 +1417,8 @@ list_t * ReadUsbList(const char* userPath)
list_append(item->codes, cmd);
list_append(list, item);

read_usb_savegames(userPath, list, SAVE_FLAG_PS4);
read_usb_savegames(pathDec, list);
read_usb_encrypted_savegames(pathEnc, list);

return list;
}
Expand Down Expand Up @@ -1364,7 +1451,7 @@ list_t * ReadUserList(const char* userPath)
list_append(item->codes, cmd);
list_append(list, item);

read_hdd_savegames(userPath, list, SAVE_FLAG_PS4 | SAVE_FLAG_HDD);
read_hdd_savegames(userPath, list);

return list;
}
Expand Down
16 changes: 10 additions & 6 deletions source/sfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ void sfo_grab(sfo_context_t *inout, sfo_context_t *tpl, int num_keys, const sfo_
}
}

/*
void sfo_patch_lock(sfo_context_t *inout, unsigned int flags) {
sfo_context_param_t *p;
Expand All @@ -294,8 +295,9 @@ void sfo_patch_lock(sfo_context_t *inout, unsigned int flags) {
}
}
}
*/

void sfo_patch_account(sfo_context_t *inout, u64 account) {
static void sfo_patch_account(sfo_context_t *inout, u64 account) {
sfo_context_param_t *p;

if (!account)
Expand All @@ -314,7 +316,7 @@ void sfo_patch_account(sfo_context_t *inout, u64 account) {
*/
}

void sfo_patch_user_id(sfo_context_t *inout, u32 userid) {
static void sfo_patch_user_id(sfo_context_t *inout, u32 userid) {
sfo_context_param_t *p;

if (userid == 0)
Expand All @@ -327,8 +329,8 @@ void sfo_patch_user_id(sfo_context_t *inout, u32 userid) {
}
}

void sfo_patch_psid(sfo_context_t *inout, u8* psid) {
/*
void sfo_patch_psid(sfo_context_t *inout, u8* psid) {
sfo_context_param_t *p;
if (!psid)
Expand All @@ -339,7 +341,6 @@ void sfo_patch_psid(sfo_context_t *inout, u8* psid) {
sfo_param_params_t *params = (sfo_param_params_t *)p->value;
memcpy(params->psid, psid, SFO_PSID_SIZE);
}
*/
}
void sfo_patch_directory(sfo_context_t *inout, const char* save_dir) {
Expand All @@ -354,6 +355,7 @@ void sfo_patch_directory(sfo_context_t *inout, const char* save_dir) {
memcpy(p->value, save_dir, strlen(save_dir));
}
}
*/

u8* sfo_get_param_value(sfo_context_t *in, const char* param) {
sfo_context_param_t *p;
Expand All @@ -378,8 +380,8 @@ int patch_sfo(const char *in_file_path, sfo_patch_t* patches) {
// sfo_patch_lock(sfo, patches->flags);
sfo_patch_account(sfo, patches->account_id);
sfo_patch_user_id(sfo, patches->user_id);
sfo_patch_psid(sfo, patches->psid);
sfo_patch_directory(sfo, patches->directory);
// sfo_patch_psid(sfo, patches->psid);
// sfo_patch_directory(sfo, patches->directory);

if (sfo_write(sfo, in_file_path) < 0) {
LOG("Unable to write to '%s'", in_file_path);
Expand Down Expand Up @@ -424,6 +426,7 @@ int build_sfo(const char *in_file_path, const char *out_file_path, const char *t
return 0;
}

/*
int patch_sfo_trophy(const char *in_file_path, const char* account) {
sfo_context_t *sfo;
sfo_context_param_t *p;
Expand Down Expand Up @@ -453,3 +456,4 @@ int patch_sfo_trophy(const char *in_file_path, const char* account) {
LOG("PARAM.SFO was patched successfully");
return 0;
}
*/

0 comments on commit 2e41a34

Please sign in to comment.