Skip to content

Commit

Permalink
fix #129
Browse files Browse the repository at this point in the history
  • Loading branch information
bucanero committed Nov 19, 2023
1 parent 45ae653 commit 937a8d5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions include/pfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ int pfd_util_setup_keys(void);
u8* get_secure_file_id(const char* game_id, const char* filename);
char* get_game_title_ids(const char* game_id);

int decrypt_save_file(const char* path, const char* fname, const char* outpath, u8* secure_file_key);
int encrypt_save_file(const char* path, const char* fname, u8* secure_file_key);
int decrypt_save_file(const char* path, const char* fname, const char* outpath, const u8* secure_file_key);
int encrypt_save_file(const char* path, const char* fname, const u8* secure_file_key);

int decrypt_trophy_trns(const char* path);
int encrypt_trophy_trns(const char* path);
Expand Down
18 changes: 15 additions & 3 deletions source/pfd_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ static int games_config_handler(void *user, const char *section, const char *nam
return 0;
}

int pfd_util_setup_keys() {
int pfd_util_setup_keys(void) {
int result = 0;

setup_key(config.authentication_id, PFD_AUTHENTICATION_ID_SIZE);
Expand Down Expand Up @@ -393,7 +393,7 @@ static int _update_details_pfd(const char* path, const char* filename)
return 1;
}

int decrypt_save_file(const char* path, const char* fname, const char* outpath, u8* secure_file_key)
int decrypt_save_file(const char* path, const char* fname, const char* outpath, const u8* secure_file_key)
{
u8 entry_key[PFD_ENTRY_KEY_SIZE];
u64 file_size, aligned_file_size;
Expand All @@ -417,6 +417,18 @@ int decrypt_save_file(const char* path, const char* fname, const char* outpath,
{
// The requested file is not listed in PARAM.PFD, so we assume is not encrypted
LOG("Error getting AES keys");

// make clean copy if requested
if (outpath)
{
snprintf(file_path, sizeof(file_path), "%s%s", path, fname);
if (read_buffer(file_path, &file_data, &file_size) < 0)
return 0;

snprintf(file_path, sizeof(file_path), "%s%s", outpath, fname);
if (write_buffer(file_path, file_data, file_size) < 0)
return 0;
}
return 1;
}

Expand Down Expand Up @@ -467,7 +479,7 @@ int decrypt_save_file(const char* path, const char* fname, const char* outpath,
return 1;
}

int encrypt_save_file(const char* path, const char* fname, u8* secure_file_key)
int encrypt_save_file(const char* path, const char* fname, const u8* secure_file_key)
{
u8 entry_key[PFD_ENTRY_KEY_SIZE];
u64 file_size, aligned_file_size;
Expand Down

0 comments on commit 937a8d5

Please sign in to comment.