-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract.py
More file actions
39 lines (35 loc) · 1.43 KB
/
Copy pathextract.py
File metadata and controls
39 lines (35 loc) · 1.43 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
"""Extract every file from the data track, decompressing the RNC ones.
python tools/extract.py <track1.iso> <outdir>
Writes the raw file next to a `.raw` sibling when it was compressed, so both
the on-disc bytes and the unpacked payload are available for inspection.
"""
import os, sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from isofs import Iso
import rnc
def main(iso_path, outdir):
iso = Iso(iso_path)
os.makedirs(outdir, exist_ok=True)
for e in iso.walk():
if e.is_dir:
os.makedirs(os.path.join(outdir, e.path.strip('/')), exist_ok=True)
continue
name = e.path.strip('/').replace(';1', '')
dst = os.path.join(outdir, name)
os.makedirs(os.path.dirname(dst) or '.', exist_ok=True)
blob = iso.read(e)
open(dst, 'wb').write(blob)
if blob[:3] == b'RNC':
i = rnc.info(blob)
try:
out = rnc.unpack(blob)
open(dst + '.bin', 'wb').write(out)
print('%-16s %7d -> %7d ratio %5.1f%% chunks %d leeway %d' %
(name, e.size, len(out), 100.0 * e.size / len(out),
i['chunks'], i['leeway']))
except Exception as ex:
print('%-16s %7d RNC FAILED: %s' % (name, e.size, ex))
else:
print('%-16s %7d (stored)' % (name, e.size))
if __name__ == '__main__':
main(sys.argv[1], sys.argv[2])