forked from dipcore/mstar-bin-tool
-
Notifications
You must be signed in to change notification settings - Fork 1
/
extract.py
38 lines (30 loc) · 862 Bytes
/
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
import sys
import os
import re
import shutil
import subprocess
import utils
# Vars
DEBUG = False
# Parse args
if len(sys.argv) == 1:
print ("Usage: extract.py <firmware> <output folder [default: ./unpacked/]>")
quit()
inputFile = sys.argv[1]
if not os.path.exists(inputFile):
print ("No such file: {}".format(inputFile))
quit()
if len(sys.argv) == 3:
outputDirectory = sys.argv[2]
else:
outputDirectory = 'unpacked'
subprocess.run("unpack.py {} {}".format(inputFile, outputDirectory), shell=True)
if not os.path.exists(outputDirectory):
print ("No such folder: {}".format(outputDirectory))
quit()
files = os.listdir(outputDirectory)
images = filter(lambda x: x.endswith('.img'), files)
for img in images:
path = os.path.join(outputDirectory, os.path.splitext(img)[0])
os.mkdir(path)
utils.unpackImg(os.path.join(outputDirectory, img), path)