-
Notifications
You must be signed in to change notification settings - Fork 3
/
splitasound.py
41 lines (36 loc) · 1.19 KB
/
splitasound.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
import sys, struct
def dumpsection(name, fin, offset, size):
oldpos = fin.tell()
fin.seek(offset)
open(name, 'wb').write(fin.read(size))
fin.seek(oldpos)
fin = open(sys.argv[1], 'rb')
i = 0
while True:
s = fin.read(4)
if len(s) == 0: break
chunkid, = struct.unpack('>I', s)
if chunkid in (1, 4, 5, 6, 7):
offset, size = struct.unpack('>II4x', fin.read(12))
if chunkid == 4: name = "BARC"
elif chunkid == 5: name = "strm"
else: name = str(chunkid)
print(i, chunkid, hex(offset), hex(size))
dumpsection(name+"-"+str(i)+".bin", fin, offset, size)
i += 1
elif chunkid in (2, 3):
while True:
s = fin.read(4)
if len(s) == 0: break
offset, = struct.unpack('>I', s)
if offset == 0: break
size, id = struct.unpack('>II', fin.read(8))
if chunkid == 3: name = "WSYS"
elif chunkid == 2: name = "IBNK"
else: name = str(chunkid)
print(i, chunkid, hex(offset), hex(size))
dumpsection(name+"-"+str(id)+"-"+str(i)+".bin", fin, offset, size)
i += 1
elif chunkid == 0:
break
fin.close()