forked from WydD/sf30ac-extractor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextract.py
executable file
·50 lines (40 loc) · 1.61 KB
/
extract.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
46
47
48
49
50
#!/usr/bin/env python3
from bplist import BPListReader
import os
import sys
def extract(root_dir, root_bundles):
if not os.path.exists(root_bundles + 'Manifest.plist'):
print("Cant find the bundles, are you sure you're using this correctly? Read the README.")
exit(2)
if not os.path.exists(root_dir):
os.mkdir(root_dir)
with open(root_bundles + 'Manifest.plist', 'rb') as fp:
read = fp.read()
reader = BPListReader(read)
parsed = reader.parse()
for d, content in parsed["bundles"].items():
extract_dir = root_dir+d.replace(".mbundle", "").replace("bundle", "")
if not os.path.exists(root_bundles + d):
print("Missing bundle", d)
continue
print("Extracting", d)
if not os.path.exists(extract_dir):
os.mkdir(extract_dir)
extract_dir += os.sep
with open(root_bundles + d, "rb") as bundle:
for name, offsets in content["files"].items():
bundle.seek(offsets["offset"])
file_content = bundle.read(offsets["size"])
print("\t", name)
with open(extract_dir+name, "wb") as f:
f.write(file_content)
def main(argc, argv):
if len(sys.argv) != 3:
print("Usage: python extract.py \"...BundleFolder...\" \"...ExtractionFolder...\"")
exit(1)
root_dir = sys.argv[2]+os.sep
root_bundles = sys.argv[1]+os.sep
extract(root_dir, root_bundles)
exit(0)
if __name__ == "__main__":
main(len(sys.argv), sys.argv)