-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbinu8_dump.py
More file actions
80 lines (68 loc) · 1.95 KB
/
binu8_dump.py
File metadata and controls
80 lines (68 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import struct,os
def walk(adr):
mylist=[]
for root,dirs,files in os.walk(adr):
for name in files:
if name[-6:] != '.binu8':
continue
if name == '__global.binu8':
continue
adrlist=os.path.join(root, name)
mylist.append(adrlist)
return mylist
def byte2int(byte):
long_tuple=struct.unpack('<L',byte)
long = long_tuple[0]
return long
def int2byte(num):
return struct.pack('L',num)
def FormatString(string, count):
res = "○%08d○\n%s\n●%08d●\n%s\n\n"%(count, string, count, string)
return res
def dumpstr(src):
bstr = b''
len = src.read(4)
c = src.read(1)
while c != b'\x00':
bstr += c
c = src.read(1)
return bstr.decode('utf-8')
def dumptxt(src, offset, count):
src.seek(offset)
str_list = []
for i in range(0, count):
str_list.append(dumpstr(src).replace('\n', '\\n').replace('\r', '\\r'))
return str_list
def main():
f_lst = walk('Script')
for fn in f_lst:
src = open(fn, 'rb')
dstname = fn[:-6] + '.txt'
dst = open(dstname, 'w', encoding='utf-8')
version = src.read(9)
# does it start with version (no length prefix)
if version[0] == 0x56 and version[1] == 0x45 and version[2] == 0x52: # VER
src.seek(9, 0)
unk_count = byte2int(src.read(4))
src.seek(unk_count * 4, 1)
# does it start with version (length prefixed)
elif version[0] == 9 and version[4] == 0x56 and version[5] == 0x45 and version[6] == 0x52:
src.seek(13, 0)
unk_count = byte2int(src.read(4))
src.seek(unk_count * 4, 1)
# if it doesnt start with version
else:
src.seek(0)
init_code_count = byte2int(src.read(4))
src.seek(init_code_count * 8, 1)
code_count = byte2int(src.read(4))
src.seek(code_count * 8, 1)
str_count = byte2int(src.read(4))
str_list = dumptxt(src, src.tell()+5, str_count-1)
i = 0
for string in str_list:
dst.write(FormatString(string, i))
i += 1
src.close()
dst.close()
main()