Last active
December 22, 2020 17:38
-
-
Save x1nixmzeng/3c1346d6abb5729598505533254cbe34 to your computer and use it in GitHub Desktop.
Binary template to parse and validate "th_Achievement.res" (from Soul Worker Online)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//-------------------------------------- | |
//--- 010 Editor v5.0 Binary Template | |
// | |
// File: Soul_Worker_Example.bt | |
// Author: WRS/x1nixmzeng | |
// Revision: 1 | |
// Purpose: Reading of th_Achievement.res | |
//-------------------------------------- | |
local int64 read_sum = 0; | |
local int i=0; | |
local int j=0; | |
struct Achievement | |
{ | |
uint id; read_sum += id; | |
ubyte b1;read_sum += b1; | |
ushort s1; read_sum += s1; | |
ubyte b2; read_sum += b2; | |
ushort s2; read_sum += s2; | |
ushort len; read_sum += len; | |
// update: the checksum works per-byte- but this is just a wchar_t array | |
ubyte name[len*2]; | |
for(j=0;j<len*2;++j) read_sum += name[j]; | |
ushort s3; read_sum += s3; | |
uint i1; read_sum += i1; | |
uint i2; read_sum += i2; | |
uint i3; read_sum += i3; | |
uint i4; read_sum += i4; | |
uint i5; read_sum += i5; | |
uint i6; read_sum += i6; | |
uint i7; read_sum += i7; | |
uint i8; read_sum += i8; | |
ubyte b3; read_sum += b3; | |
ubyte b4; read_sum += b4; | |
uint i9; read_sum += i9; | |
uint i10; read_sum += i10; | |
ubyte b5; read_sum += b5; | |
ubyte b6; read_sum += b6; | |
}; | |
uint Count; | |
for(i = 0; i < Count; ++i) | |
{ | |
Achievement arch; | |
} | |
local string hash = ""; | |
local string result = ""; | |
// Convert the sum of bytes read to a 64-bit string | |
SPrintf(hash, "%Ld", read_sum); | |
// MD5 the running read total | |
ChecksumAlgArrayStr(CHECKSUM_MD5, result, hash, Strlen(hash)); | |
// Convert to lower-case (file has it in lower case) | |
for(i = 0; i < 32; ++i) { | |
result[i] = ToLower(result[i]); | |
} | |
struct Checksum | |
{ | |
ushort Length; | |
ubyte Hash[Length]; | |
}; | |
Checksum Tail; | |
Printf("Parse total: %Ld\n", read_sum); | |
Printf("Expected hash: %s\n", result); | |
Printf("Read hash: %s\n", Tail.Hash); | |
// Check out checksums matched | |
Assert(Tail.Hash == result); | |
// And we're at the end of the file | |
Assert(FEof()); | |
Printf("-- SUCCESS--\n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
All the
tb_*
structures has been extracted here - in this gistThere is also a python script to help dump any future changes