-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathunmetallib.py
43 lines (33 loc) · 986 Bytes
/
unmetallib.py
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
import sys
def u32(a, i):
return a[i] | a[i+1] << 8 | a[i+2] << 16 | a[i+3] << 24
def u16(a, i):
return a[i] | a[i+1] << 8
with open(sys.argv[1], "rb") as infile:
indata = infile.read()
dir_off = u32(indata, 0x18)
num_entries = u32(indata, dir_off)
curoff = dir_off + 4
entries = []
for i in range(num_entries):
curoff += 4 # size of entry
while True:
tag_type = indata[curoff:curoff + 4]
if tag_type == b"ENDT":
curoff += 4
break
tag_len = u16(indata, curoff + 4)
if tag_type == b"NAME":
# null terminated string.
entry_name = indata[curoff + 6:curoff + 6 + tag_len - 1].decode("utf-8")
elif tag_type == b"MDSZ":
entry_size = u32(indata, curoff + 6)
curoff += 6 + tag_len
entries.append((entry_name, entry_size))
print(entries)
payload_off = u32(indata, 0x48)
for entry in entries:
outdata = indata[payload_off:payload_off + entry[1]]
with open("out_" + entry[0] + ".air", "wb") as outfile:
outfile.write(outdata)
payload_off += entry[1]