forked from foone/podextract
-
Notifications
You must be signed in to change notification settings - Fork 0
/
podextract.py
45 lines (44 loc) · 1.14 KB
/
podextract.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
44
45
import sys,struct,os,fnmatch
files=[]
if len(sys.argv)!=3:
print('Usage: {} <filepattern>'.format(sys.argv[0]))
print('Example: {} "*.MOD"'.format(sys.argv[0]))
sys.exit()
else:
podfile=sys.argv[1]
pattern=sys.argv[2].upper()
with open(podfile,'rb') as f:
f.seek(0)
header=f.read(4)
if header=='POD2':
print('This is a POD2 file: They are not supported!')
sys.exit()
num_files = struct.unpack('<L',header)[0]
f.seek(0x54)
for i in range(num_files):
parts=struct.unpack('<32sLL',f.read(0x28))
name,length,offset=parts
nameparts=name.split('\0',1)
if len(nameparts)==1:
main_name=nameparts[0].rstrip('\0')
sub_name=''
else:
main_name,sub_name=nameparts
sub_name=sub_name.rstrip('\0')
print(main_name, sub_name, length,offset)
files.append({
'name':main_name,
'sub_name':sub_name,
'length':length,
'offset':offset,
})
for file in files:
if fnmatch.fnmatch(file['name'].upper(),pattern):
f.seek(file['offset'])
data=f.read(file['length'])
name = file['name']
dirpath=os.path.dirname(name)
if not os.path.exists(dirpath):
os.makedirs(dirpath)
with open(name,'wb') as outf:
outf.write(data)