Skip to content

Instantly share code, notes, and snippets.

@x1nixmzeng
Last active December 22, 2020 17:38
Show Gist options
  • Save x1nixmzeng/3c1346d6abb5729598505533254cbe34 to your computer and use it in GitHub Desktop.
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)
//--------------------------------------
//--- 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");
@x1nixmzeng
Copy link
Author

All the tb_* structures has been extracted here - in this gist

There is also a python script to help dump any future changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment