Skip to content

Commit

Permalink
Add Tales of Zestiria checksum fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bucanero committed Jul 19, 2021
1 parent a9ee3c3 commit e919f33
Show file tree
Hide file tree
Showing 6 changed files with 292 additions and 2 deletions.
82 changes: 82 additions & 0 deletions appdata/BLES02152.ps3savepatch
Original file line number Diff line number Diff line change
@@ -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]
82 changes: 82 additions & 0 deletions appdata/BLUS31533.ps3savepatch
Original file line number Diff line number Diff line change
@@ -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]
82 changes: 82 additions & 0 deletions appdata/NPUB31675.ps3savepatch
Original file line number Diff line number Diff line change
@@ -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]
11 changes: 9 additions & 2 deletions include/crc_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions source/crc_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
**********************************************************************/

#include <stdio.h>
#include <polarssl/sha1.h>
#include "crc_util.h"

#define SW4_OFF_1 0x00004
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions source/patches.c
Original file line number Diff line number Diff line change
Expand Up @@ -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*"))
{
Expand Down

0 comments on commit e919f33

Please sign in to comment.