-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
33 lines (29 loc) · 994 Bytes
/
main.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
from argparse import ArgumentParser, FileType
from sisfile import SymbianFileHeader, extract_files
from e32exe import E32ImageHeader, objcopy
from util.binfile import ParseError
headers = [
(E32ImageHeader, objcopy),
(SymbianFileHeader, extract_files),
]
par = ArgumentParser()
par.add_argument('-f', '--format', help="Use this format and do not guess")
par.add_argument('-p', '--parse-only', help="Only parse, do not extract", action='store_true')
par.add_argument('ifile', type=FileType('rb'))
par.add_argument('target_dir')
arg = par.parse_args()
with arg.ifile as fp:
for HeaderType, payloadfunc in headers:
if arg.format and HeaderType.__name__ != arg.format:
continue
try:
hdr = HeaderType(fp)
except ParseError:
if arg.format:
raise
fp.seek(0)
continue
print(hdr)
if not arg.parse_only:
ff = payloadfunc(fp, hdr, arg.target_dir)
break