-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextract.py
executable file
·148 lines (120 loc) · 4.78 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python3
import os
import lzma
from zipfile import ZipFile
import shutil
import tarfile
from argparse import ArgumentParser, RawDescriptionHelpFormatter, Action
def usage():
print("""extract.py
-stock: extracted stock image location
-out : extracted super contents location""")
def parse_arguments():
parser = ArgumentParser(formatter_class=RawDescriptionHelpFormatter, epilog=usage())
parser.add_argument("-stock", required=False, type=str, default=None)
parser.add_argument("-out", required=False, type=str, default=None)
return parser.parse_args()
def main():
args = parse_arguments()
here = os.path.dirname(os.path.realpath(__file__))
stock_rom_path = ""
for file in os.listdir(here):
if file.endswith(".zip"):
stock_rom_path = file
break
if args.stock is not None:
stock_rom_path = args.stock
if stock_rom_path == "":
print("No Stock Rom Found.")
quit()
else:
print("Stock Rom Found:'" + stock_rom_path + "'")
stock_rom_folder = os.path.splitext(stock_rom_path)[0]
if args.stock is None:
print("Unzipping Stock rom to " + stock_rom_folder)
with ZipFile(stock_rom_path) as zObject:
zObject.extract(stock_rom_folder + "/super.img", here)
zObject.extract(stock_rom_folder + "/boot.img", here)
zObject.extract(stock_rom_folder + "/vbmeta.img", here)
zObject.extract(stock_rom_folder + "/vbmeta_system.img", here)
zObject.extract(stock_rom_folder + "/vbmeta_vendor.img", here)
try:
zObject.extract(stock_rom_folder + "/vendor_boot.img", here)
except:
""
zObject.close();
try:
os.system("rm -rf super")
os.mkdir(here + "/super")
except OSError as error:
error
try:
os.mkdir(here + "/super/stock")
except OSError as error:
error
try:
os.mkdir(here + "/super/custom")
except OSError as error:
error
print("Copying super to super/stock")
stock_rom_location = here + "/" + stock_rom_folder
if args.stock is not None:
stock_rom_location = stock_rom_folder
shutil.copyfile(stock_rom_location + "/super.img", here + "/super/stock/super.img")
print("Unpacking super.img to ext4.img")
os.system(here + "/bin/simg2img super/stock/super.img super/stock/super.ext4.img")
print("Unpacking super.ext4.img")
os.system("cd super/stock/;" + here + "/bin/lpunpack super.ext4.img; cd ../..;")
is_seamless_update = False
if os.path.isfile("super/stock/system_a.img"):
is_seamless_update = True
print("Copying images to super/custom")
if not is_seamless_update:
# Titan Pocket
# Atom L
shutil.copyfile("super/stock/vendor.img", "super/custom/vendor.img")
shutil.copyfile("super/stock/product.img", "super/custom/product.img")
else:
# Tank
# Jelly 2E
# Tank Mini
shutil.copyfile("super/stock/vendor_a.img", "super/custom/vendor_a.img")
shutil.copyfile("super/stock/vendor_b.img", "super/custom/vendor_b.img")
shutil.copyfile("super/stock/product_a.img", "super/custom/product_a.img")
shutil.copyfile("super/stock/product_b.img", "super/custom/product_b.img")
try: #Tank Mini and Tank
shutil.copyfile("super/stock/odm_dlkm_a.img", "super/custom/odm_dlkm_a.img")
shutil.copyfile("super/stock/odm_dlkm_b.img", "super/custom/odm_dlkm_b.img")
shutil.copyfile("super/stock/vendor_dlkm_a.img", "super/custom/vendor_dlkm_a.img")
shutil.copyfile("super/stock/vendor_dlkm_b.img", "super/custom/vendor_dlkm_b.img")
except :
""
if args.out is not None:
print("Copying super to '" + args.out + "'")
os.system("cp -r super " + args.out + "; rm -rf super")
# Get Compressed File
compressed_file = ""
tar = False
xz = False
for file in os.listdir(here):
if file.endswith(".tar.gz"):
compressed_file = file
tar = True
break
if file.endswith(".xz"):
compressed_file = file
xz = True
break
# Uncompress compressed_file
if not compressed_file == "" and tar:
print("Extracting gargoyle GSI '" + compressed_file + "'")
with tarfile.open(compressed_file, "r") as tf:
tf.extractall(path=here + "/")
elif not compressed_file == "" and xz:
print("Extracting gargoyle GSI '" + compressed_file + "'")
with lzma.open(compressed_file) as f, open(here + "/" + compressed_file.strip(".xz"), 'wb') as fout:
file_content = f.read()
fout.write(file_content)
print("Script Complete")
if __name__ == '__main__':
main()