Skip to content

Instantly share code, notes, and snippets.

@polaris-
Last active November 26, 2015 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polaris-/bc05e32601582286d5f0 to your computer and use it in GitHub Desktop.
Save polaris-/bc05e32601582286d5f0 to your computer and use it in GitHub Desktop.
import os
import struct
import sys
def read_short_be(file):
return struct.unpack(">H", file.read(2))[0]
def read_int_be(file):
return struct.unpack(">I", file.read(4))[0]
def dump_text(filename):
file = open(filename, "rb")
if file.read(4) != "SDL2":
print "Invalid SDL2 file"
exit(-1)
# Don't need these for now, but they can be used later to reencrypt the script
# so it might be good to save these if anyone wants to turn this into a serious
# script dumping tool
key = file.read(3)
mul = file.read(1)
unk_table_count = read_short_be(file)
string_table_count = read_short_be(file)
string_table_offset = read_int_be(file)
unk_table_offset = read_int_be(file)
file.seek(-8, 1) # Rewind so we can read the previous entries in a loop
output_filename = filename + ".txt"
output = open(output_filename,"wb")
file.seek(unk_table_count * 8 + 0x0c)
for i in range(0, string_table_count):
string_offset = read_int_be(file)
cur_offset = file.tell()
file.seek(string_offset)
string_len = read_short_be(file)
string = file.read(string_len)
output.write("<%08x> " % string_offset)
output.write(string)
output.write("\r\n")
file.seek(cur_offset)
if __name__ == "__main__":
if len(sys.argv) != 2:
print "usage: %s input_file" % (sys.argv[0])
exit()
dump_text(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment