diff --git a/appdata/BLES02152.ps3savepatch b/appdata/BLES02152.ps3savepatch new file mode 100644 index 0000000..18a8feb --- /dev/null +++ b/appdata/BLES02152.ps3savepatch @@ -0,0 +1,82 @@ +; "Tales of Zestiria" +; BLES02152 + +:SAVE + +[999999999 Gald] +200001D4 3B9AC9FF + +[Sorey LV 200] +2001F3DC 000000C8 + +[Super Soray code] +2001F440 0000270F +2001F44C 0000270F +2001F450 0000270F +2001F454 0000270F +2001F458 0000270F +2001F45C 0000270F + +[Super Rose code] +20027440 0000270F +2002744C 0000270F +20027450 0000270F +20027454 0000270F +20027458 0000270F +2002745C 0000270F + +[Super Mikurio code] +2002F440 0000270F +2002F44C 0000270F +2002F450 0000270F +2002F454 0000270F +2002F458 0000270F +2002F45C 0000270F + +[Lyra Super code] +20037440 0000270F +2003744C 0000270F +20037450 0000270F +20037454 0000270F +20037458 0000270F +2003745C 0000270F + +[Super Edna code] +2003F440 0000270F +2003F44C 0000270F +2003F450 0000270F +2003F454 0000270F +2003F458 0000270F +2003F45C 0000270F + +[Super Zabida code] +20047440 0000270F +2004744C 0000270F +20047450 0000270F +20047454 0000270F +20047458 0000270F +2004745C 0000270F + +[Super Alisha code] +2004F440 0000270F +2004F44C 0000270F +2004F450 0000270F +2004F454 0000270F +2004F458 0000270F +2004F45C 0000270F + +[Super Dezeru code] +20057440 0000270F +2005744C 0000270F +20057450 0000270F +20057454 0000270F +20057458 0000270F +2005745C 0000270F + +; custom checksum +; by bucanero +[Update Custom Checksum (Required)] +; hash len 637440 bytes +set range:0x01D0,0x9BBCF +set [hash]:toz_checksum +write at 0x0C:[hash] diff --git a/appdata/BLUS31533.ps3savepatch b/appdata/BLUS31533.ps3savepatch new file mode 100644 index 0000000..c0cc1fe --- /dev/null +++ b/appdata/BLUS31533.ps3savepatch @@ -0,0 +1,82 @@ +; "Tales of Zestiria" +; BLUS31533 + +:SAVE + +[999999999 Gald] +200001D4 3B9AC9FF + +[Sorey LV 200] +2001F3DC 000000C8 + +[Super Soray code] +2001F440 0000270F +2001F44C 0000270F +2001F450 0000270F +2001F454 0000270F +2001F458 0000270F +2001F45C 0000270F + +[Super Rose code] +20027440 0000270F +2002744C 0000270F +20027450 0000270F +20027454 0000270F +20027458 0000270F +2002745C 0000270F + +[Super Mikurio code] +2002F440 0000270F +2002F44C 0000270F +2002F450 0000270F +2002F454 0000270F +2002F458 0000270F +2002F45C 0000270F + +[Lyra Super code] +20037440 0000270F +2003744C 0000270F +20037450 0000270F +20037454 0000270F +20037458 0000270F +2003745C 0000270F + +[Super Edna code] +2003F440 0000270F +2003F44C 0000270F +2003F450 0000270F +2003F454 0000270F +2003F458 0000270F +2003F45C 0000270F + +[Super Zabida code] +20047440 0000270F +2004744C 0000270F +20047450 0000270F +20047454 0000270F +20047458 0000270F +2004745C 0000270F + +[Super Alisha code] +2004F440 0000270F +2004F44C 0000270F +2004F450 0000270F +2004F454 0000270F +2004F458 0000270F +2004F45C 0000270F + +[Super Dezeru code] +20057440 0000270F +2005744C 0000270F +20057450 0000270F +20057454 0000270F +20057458 0000270F +2005745C 0000270F + +; custom checksum +; by bucanero +[Update Custom Checksum (Required)] +; hash len 637440 bytes +set range:0x01D0,0x9BBCF +set [hash]:toz_checksum +write at 0x0C:[hash] diff --git a/appdata/NPUB31675.ps3savepatch b/appdata/NPUB31675.ps3savepatch new file mode 100644 index 0000000..7a43115 --- /dev/null +++ b/appdata/NPUB31675.ps3savepatch @@ -0,0 +1,82 @@ +; "Tales of Zestiria" +; NPUB31675 + +:SAVE + +[999999999 Gald] +200001D4 3B9AC9FF + +[Sorey LV 200] +2001F3DC 000000C8 + +[Super Soray code] +2001F440 0000270F +2001F44C 0000270F +2001F450 0000270F +2001F454 0000270F +2001F458 0000270F +2001F45C 0000270F + +[Super Rose code] +20027440 0000270F +2002744C 0000270F +20027450 0000270F +20027454 0000270F +20027458 0000270F +2002745C 0000270F + +[Super Mikurio code] +2002F440 0000270F +2002F44C 0000270F +2002F450 0000270F +2002F454 0000270F +2002F458 0000270F +2002F45C 0000270F + +[Lyra Super code] +20037440 0000270F +2003744C 0000270F +20037450 0000270F +20037454 0000270F +20037458 0000270F +2003745C 0000270F + +[Super Edna code] +2003F440 0000270F +2003F44C 0000270F +2003F450 0000270F +2003F454 0000270F +2003F458 0000270F +2003F45C 0000270F + +[Super Zabida code] +20047440 0000270F +2004744C 0000270F +20047450 0000270F +20047454 0000270F +20047458 0000270F +2004745C 0000270F + +[Super Alisha code] +2004F440 0000270F +2004F44C 0000270F +2004F450 0000270F +2004F454 0000270F +2004F458 0000270F +2004F45C 0000270F + +[Super Dezeru code] +20057440 0000270F +2005744C 0000270F +20057450 0000270F +20057454 0000270F +20057458 0000270F +2005745C 0000270F + +; custom checksum +; by bucanero +[Update Custom Checksum (Required)] +; hash len 637440 bytes +set range:0x01D0,0x9BBCF +set [hash]:toz_checksum +write at 0x0C:[hash] diff --git a/include/crc_util.h b/include/crc_util.h index 53c9197..d19d869 100644 --- a/include/crc_util.h +++ b/include/crc_util.h @@ -159,17 +159,24 @@ int sw4_hash(const uint8_t* data, uint32_t size, uint32_t* crcs); /** * This function makes MGS2 hash calculation on Length data bytes * - * RETURN VALUE: 32 bit result array of CRC calculation + * RETURN VALUE: 32 bit result of CRC calculation */ int mgs2_hash(const uint8_t* data, uint32_t len); /** * This function makes Tears to Tiara 2 hash calculation on Length data bytes * - * RETURN VALUE: 32 bit result array of CRC calculation + * RETURN VALUE: 32 bit result of CRC calculation */ uint32_t tiara2_hash(const uint8_t* data, uint32_t len); +/** + * This function makes Tales of Zestiria hash calculation on Length data bytes + * + * RETURN VALUE: 20 byte result array of SHA1 calculation + */ +void toz_hash(const uint8_t* data, uint32_t len, uint8_t* sha_hash); + #ifdef __cplusplus } #endif diff --git a/source/crc_util.c b/source/crc_util.c index 1f3c3c6..577b843 100644 --- a/source/crc_util.c +++ b/source/crc_util.c @@ -16,6 +16,7 @@ **********************************************************************/ #include +#include #include "crc_util.h" #define SW4_OFF_1 0x00004 @@ -313,6 +314,29 @@ uint32_t tiara2_hash(const uint8_t* data, uint32_t len) return (crc); } +void _toz_sha1(const uint8_t* data, uint32_t length, const char* key, uint8_t* hash_out) +{ + sha1_context ctx; + + sha1_starts(&ctx); + sha1_update(&ctx, data, length); + sha1_update(&ctx, (const unsigned char*)key, strlen(key)); + sha1_finish(&ctx, hash_out); +} + +// https://github.com/bucanero/ps3-save-decrypters/blob/master/toz-checksum-fixer/samples/Crypto.txt +void toz_hash(const uint8_t* data, uint32_t len, uint8_t* hash) +{ + const char array[8][4] = {"SRA", "ROS", "MIC", "LAI", "EDN", "DEZ", "ZAB", "ALI"}; + + _toz_sha1(data, len, "TO12", hash); + + for (int i = 0; i < 100; i++) + _toz_sha1(hash, 20, array[i % 8], hash); + + return; +} + uint16_t adler16(const uint8_t *data, size_t len) /* where data is the location of the data in physical memory and diff --git a/source/patches.c b/source/patches.c index 81c0603..85bf7af 100644 --- a/source/patches.c +++ b/source/patches.c @@ -1003,6 +1003,19 @@ int apply_bsd_patch_code(const char* filepath, code_entry_t* code) LOG("len %d SW4 HASH = %X %X %X %X", len, hash[0], hash[1], hash[2], hash[3]); } + // set [*]:toz_checksum* + else if (wildcard_match_icase(line, "toz_checksum*")) + { + u8* start = (u8*)data + range_start; + len = range_end - range_start; + + var->len = BSD_VAR_SHA1; + var->data = malloc(var->len); + toz_hash(start, len, var->data); + + LOG("len %d TOZ SHA1 HASH = %llx%llx%x", len, ((uint64_t*)var->data)[0], ((uint64_t*)var->data)[1], ((uint32_t*)var->data)[4]); + } + // set [*]:tiara2_checksum* else if (wildcard_match_icase(line, "tiara2_checksum*")) {