Skip to content

Commit

Permalink
fix file attributes on fat32
Browse files Browse the repository at this point in the history
exported files on USB
  • Loading branch information
bucanero committed Nov 22, 2023
1 parent 937a8d5 commit 1648b4a
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 49 deletions.
42 changes: 42 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,48 @@ All notable changes to the `apollo-ps3` project will be documented in this file.

## [Unreleased]()


### Added

* Auto-detect `X`/`O` button settings
* New cheat codes
- Assassin's Creed II
- Grand Theft Auto V
- Metal Gear Solid 5: The Phantom Pain
* Custom decryption support
- Metal Gear Solid 5: The Phantom Pain
* Custom checksum support
- Assassin's Creed
- Assassin's Creed II
- Assassin's Creed III
- Assassin's Creed IV: Black Flag
- Assassin's Creed: Brotherhood
- Assassin's Creed: Revelations
- Assassin's Creed Rogue
- Castlevania: Lords Of Shadow
- Castlevania: Lords Of Shadow 2
- Grand Theft Auto V
- Metal Gear Solid 5: The Phantom Pain

### Fixed

* Fix exported file attributes on FAT32 drives
* Fix `BCAS20224` secure file-id key

### Misc

* Network HTTP proxy settings support
* Updated [`apollo-lib`](https://github.com/bucanero/apollo-lib) Patch Engine to v0.6.0
- Add host callbacks (username, system name, wlan mac, psid, account id)
- Add `murmu3_32`, `jhash` hash functions
- Add Patapon 3 PSP decryption
- Add MGS5 decryption (PS3/PS4)
- Add Monster Hunter 2G/3rd PSP decryption
- Add Castlevania:LoS checksum
- Add Rockstar checksum
- Fix SaveWizard Code Type C
- Fix `right()` on little-endian platforms

## [v1.8.4](https://github.com/bucanero/apollo-ps3/releases/tag/v1.8.4) - 2023-04-08

### Added
Expand Down
Binary file modified docs/screenshots/screenshot_main.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ int mkdirs(const char* dir);
int copy_file(const char* input, const char* output);
int copy_directory(const char* startdir, const char* inputdir, const char* outputdir);
int clean_directory(const char* inputdir);
int file_chmod(const char* path);

//----------------------------------------
//CONSOLE ID UTILS
Expand Down
4 changes: 2 additions & 2 deletions include/saves.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ uint64_t get_account_id(uint32_t user_id);

int create_savegame_folder(const char* folder);

void ps2_encrypt_image(uint8_t dex_mode, const char* image_name, const char* data_file, char* msg_update);
void ps2_decrypt_image(uint8_t dex_mode, const char* image_name, const char* data_file, char* msg_update);
void ps2_encrypt_image(uint8_t cfg_file, const char* image_name, const char* data_file);
void ps2_decrypt_image(uint8_t dex_mode, const char* image_name, const char* data_file);
void ps2_crypt_vmc(uint8_t dex_mode, const char* vmc_path, const char* vmc_out, int crypt_mode);
int ps2_add_vmc_ecc(const char* src, const char* dst);
int ps2_remove_vmc_ecc(const char* src, const char* dst);
Expand Down
2 changes: 1 addition & 1 deletion include/settings.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#define APOLLO_VERSION "1.8.8" //Apollo PS3 version (about menu)
#define APOLLO_VERSION "1.8.6" //Apollo PS3 version (about menu)

#define MENU_TITLE_OFF 30 //Offset of menu title text from menu mini icon
#define MENU_ICON_OFF 70 //X Offset to start printing menu mini icon
Expand Down
4 changes: 2 additions & 2 deletions sfo.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" ?>
<sfo>
<value name="APP_VER" type="string">
01.88
01.86
</value>
<value name="ATTRIBUTE" type="integer">
133
Expand Down Expand Up @@ -34,6 +34,6 @@
NP0APOLLO
</value>
<value name="VERSION" type="string">
01.84
01.86
</value>
</sfo>
5 changes: 5 additions & 0 deletions source/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ int copy_file(const char* input, const char* output)
return (read - written);
}

int file_chmod(const char* path)
{
return sysLv2FsChmod(path, S_IFMT | 0777);
}

uint32_t file_crc32(const char* input)
{
char buffer[TMP_BUFF_SIZE];
Expand Down
81 changes: 50 additions & 31 deletions source/exec_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,18 @@ static void _saveOwnerData(const char* path)
sysUtilGetSystemParamString(SYSUTIL_SYSTEMPARAM_ID_CURRENT_USERNAME, buff, SYSUTIL_SYSTEMPARAM_CURRENT_USERNAME_SIZE);
LOG("Saving User '%s'...", buff);
save_xml_owner(path, buff);
file_chmod(path);
}

static uint32_t get_filename_id(const char* dir)
static uint32_t get_filename_id(const char* dir, const char* title_id)
{
char path[128];
uint32_t tid = 0;

do
{
tid++;
snprintf(path, sizeof(path), "%s%08d.zip", dir, tid);
snprintf(path, sizeof(path), "%s%s-%08d.zip", dir, title_id, tid);
}
while (file_exists(path) == SUCCESS);

Expand All @@ -89,9 +90,10 @@ static uint32_t get_filename_id(const char* dir)
static void zipSave(const save_entry_t* entry, int dest)
{
char exp_path[256];
char* export_file;
char export_file[256];
char* tmp;
uint32_t fid;
int ret;

_set_dest_path(exp_path, dest, PS3_EXPORT_PATH);
if (mkdirs(exp_path) != SUCCESS)
Expand All @@ -102,31 +104,39 @@ static void zipSave(const save_entry_t* entry, int dest)

init_loading_screen("Exporting save game...");

fid = get_filename_id(exp_path);
asprintf(&export_file, "%s%08d.zip", exp_path, fid);
fid = get_filename_id(exp_path, entry->title_id);
snprintf(export_file, sizeof(export_file), "%s%s-%08d.zip", exp_path, entry->title_id, fid);

asprintf(&tmp, entry->path);
*strrchr(tmp, '/') = 0;
*strrchr(tmp, '/') = 0;

zip_directory(tmp, entry->path, export_file);
ret = zip_directory(tmp, entry->path, export_file);
free(tmp);

sprintf(export_file, "%s%08d.txt", exp_path, fid);
FILE* f = fopen(export_file, "a");
if (f)
if (ret)
{
fprintf(f, "%08d.zip=[%s] %s\n", fid, entry->title_id, entry->name);
fclose(f);
}

sprintf(export_file, "%s" OWNER_XML_FILE, exp_path);
_saveOwnerData(export_file);
snprintf(export_file, sizeof(export_file), "%s%08d.txt", exp_path, apollo_config.user_id);
FILE* f = fopen(export_file, "a");
if (f)
{
fprintf(f, "%s-%08d.zip=%s\n", entry->title_id, fid, entry->name);
fclose(f);
file_chmod(export_file);
}

free(export_file);
free(tmp);
snprintf(export_file, sizeof(export_file), "%s" OWNER_XML_FILE, exp_path);
_saveOwnerData(export_file);
}

stop_loading_screen();
show_message("Zip file successfully saved to:\n%s%08d.zip", exp_path, fid);
if (!ret)
{
show_message("Error! Can't export save game to:\n%s", exp_path);
return;
}

show_message("Zip file successfully saved to:\n%s%s-%08d.zip", exp_path, entry->title_id, fid);
}

static int _copy_save_usb(const save_entry_t* save, const char* exp_path)
Expand Down Expand Up @@ -157,7 +167,7 @@ static void copySave(const save_entry_t* save, int dst, const char* path)
_copy_save_usb(save, exp_path);
stop_loading_screen();

show_message("Files successfully copied to:\n%s", exp_path);
show_message("Files successfully copied to:\n%s%s", exp_path, save->dir_name);
}

static void copyAllSavesUSB(const save_entry_t* save, int dst, int all)
Expand Down Expand Up @@ -536,6 +546,7 @@ static void exportLicensesZip(int dst)

sprintf(export_file, "%s" "idps.hex", exp_path);
write_buffer(export_file, (u8*) apollo_config.idps, 16);
file_chmod(export_file);

free(export_file);
free(lic_path);
Expand Down Expand Up @@ -567,6 +578,7 @@ static void exportFlashZip(int dst)

sprintf(export_file, "%s" "idps.hex", exp_path);
write_buffer(export_file, (u8*) apollo_config.idps, 16);
file_chmod(export_file);

free(export_file);

Expand All @@ -576,6 +588,7 @@ static void exportFlashZip(int dst)

static void exportTrophiesZip(int dst)
{
int ret;
char* export_file;
char* trp_path;
char* tmp;
Expand All @@ -596,7 +609,7 @@ static void exportTrophiesZip(int dst)
tmp = strdup(trp_path);
*strrchr(tmp, '/') = 0;

zip_directory(tmp, trp_path, export_file);
ret = zip_directory(tmp, trp_path, export_file);

sprintf(export_file, "%s" OWNER_XML_FILE, exp_path);
_saveOwnerData(export_file);
Expand All @@ -606,6 +619,12 @@ static void exportTrophiesZip(int dst)
free(tmp);

stop_loading_screen();
if (!ret)
{
show_message("Error! Failed to export Trophies to Zip");
return;
}

show_message("Trophies successfully saved to:\n%strophies_%08d.zip", exp_path, apollo_config.user_id);
}

Expand Down Expand Up @@ -872,6 +891,7 @@ static void exportVM2raw(const char* vm2_path, const char* vm2_file, int dst)

init_loading_screen("Exporting PS2 .VM2 memory card...");
ps2_remove_vmc_ecc(vm2file, dstfile);
file_chmod(dstfile);
stop_loading_screen();

show_message("File successfully saved to:\n%s", dstfile);
Expand All @@ -887,9 +907,9 @@ static void importPS2classicsCfg(const char* cfg_path, const char* cfg_file)
*strrchr(outfile, '.') = 0;
strcat(outfile, ".ENC");

init_loading_screen("Encrypting PS2 CONFIG...");
ps2_encrypt_image(1, ps2file, outfile, NULL);
stop_loading_screen();
init_progress_bar("Encrypting PS2 CONFIG...", cfg_file);
ps2_encrypt_image(1, ps2file, outfile);
end_progress_bar();

show_message("File successfully saved to:\n%s", outfile);
}
Expand All @@ -898,16 +918,15 @@ static void importPS2classics(const char* iso_path, const char* iso_file)
{
char ps2file[256];
char outfile[256];
char msg[128] = "Encrypting PS2 ISO...";

snprintf(ps2file, sizeof(ps2file), "%s%s", iso_path, iso_file);
snprintf(outfile, sizeof(outfile), PS2ISO_PATH_HDD "%s", iso_file);
*strrchr(outfile, '.') = 0;
strcat(outfile, ".BIN.ENC");

init_loading_screen(msg);
ps2_encrypt_image(0, ps2file, outfile, msg);
stop_loading_screen();
init_progress_bar("Encrypting PS2 ISO...", iso_file);
ps2_encrypt_image(0, ps2file, outfile);
end_progress_bar();

show_message("File successfully saved to:\n%s", outfile);
}
Expand All @@ -917,7 +936,6 @@ static void exportPS2classics(const char* enc_path, const char* enc_file, uint8_
char path[256];
char ps2file[256];
char outfile[256];
char msg[128] = "Decrypting PS2 BIN.ENC...";

if (dst != STORAGE_HDD)
_set_dest_path(path, dst, PS2ISO_PATH);
Expand All @@ -935,9 +953,10 @@ static void exportPS2classics(const char* enc_path, const char* enc_file, uint8_
return;
}

init_loading_screen(msg);
ps2_decrypt_image(0, ps2file, outfile, msg);
stop_loading_screen();
init_progress_bar("Decrypting PS2 BIN.ENC...", enc_file);
ps2_decrypt_image(0, ps2file, outfile);
file_chmod(outfile);
end_progress_bar();

show_message("File successfully saved to:\n%s", outfile);
}
Expand Down
5 changes: 5 additions & 0 deletions source/pfd_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,12 @@ int decrypt_save_file(const char* path, const char* fname, const char* outpath,

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

free(file_data);
}
return 1;
}
Expand Down
17 changes: 12 additions & 5 deletions source/ps2classic.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "ps2_data.h"
#include "settings.h"
#include "common.h"
#include "saves.h"

#include <stdio.h>
#include <string.h>
Expand Down Expand Up @@ -516,7 +517,7 @@ static void build_ps2_header(u8 * buffer, int npd_type, const char* content_id,

}

void ps2_decrypt_image(u8 dex_mode, const char* image_name, const char* data_file, char* msg_update)
void ps2_decrypt_image(u8 dex_mode, const char* image_name, const char* data_file)
{
FILE * in;
FILE * data_out;
Expand Down Expand Up @@ -556,6 +557,9 @@ void ps2_decrypt_image(u8 dex_mode, const char* image_name, const char* data_fil
total_size = data_size;
flush_size = total_size / 100;

for (i = 0; i < 0x20; c++)
update_progress_bar(0, total_size, image_name);

LOG("segment size: %x\ndata_size: %lx\n", segment_size, data_size);

//alloc buffers
Expand Down Expand Up @@ -596,7 +600,7 @@ void ps2_decrypt_image(u8 dex_mode, const char* image_name, const char* data_fil
if(c >= flush_size) {
percent += 1;
decr_size = decr_size + c;
sprintf(msg_update, "Decrypted: %ld%% (%d Blocks)", (100*decr_size)/total_size, percent);
update_progress_bar(decr_size, total_size, image_name);
LOG("Decrypted: %d Blocks 0x%08lx", percent, decr_size);
c = 0;
}
Expand All @@ -619,7 +623,7 @@ static int64_t get_fsize(const char* fname)
return st.st_size;
}

void ps2_encrypt_image(u8 cfg_mode, const char* image_name, const char* data_file, char* msg_update)
void ps2_encrypt_image(u8 cfg_mode, const char* image_name, const char* data_file)
{
FILE * in;
FILE * data_out;
Expand Down Expand Up @@ -658,6 +662,9 @@ void ps2_encrypt_image(u8 cfg_mode, const char* image_name, const char* data_fil
total_size = data_size;
flush_size = total_size / 100;

for (i = 0; i < 0x20; c++)
update_progress_bar(0, total_size, image_name);

/* limg section */
if (!cfg_mode)
ps2_build_limg(image_name, data_size);
Expand Down Expand Up @@ -713,10 +720,10 @@ void ps2_encrypt_image(u8 cfg_mode, const char* image_name, const char* data_fil
fwrite(data_buffer, segment_size, num_child_segments, data_out);

c += read;
if(msg_update && c >= flush_size) {
if(c >= flush_size) {
percent += 1;
encr_size = encr_size + c;
sprintf(msg_update, "Encrypted: %ld%% (%d Blocks)", (100*encr_size)/data_size, percent);
update_progress_bar(encr_size, total_size, image_name);
LOG("Encrypted: %d Blocks 0x%08lx", percent, encr_size);
c = 0;
}
Expand Down
Loading

0 comments on commit 1648b4a

Please sign in to comment.