Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions splituapp
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ import string
import struct
from subprocess import check_output

def extract(source, flist):
def cmd(command):
def extract(source, output, flist, skipcrc, crcpath):
def cmd(command, argument):
try:
test1 = check_output(command)
test1 = check_output([command, argument])
test1 = test1.strip().decode()
except:
test1 = ''

return test1

bytenum = 4
outdir = 'output'
outdir = output
img_files = []

try:
Expand Down Expand Up @@ -64,31 +64,34 @@ def extract(source, flist):
f.seek(22, 1)
crcdata = f.read(headersize - 98)

img = filename + '.img'
img_path = os.path.join(output, img)

if not flist or filename in flist:
if filename in img_files:
filename = filename+'_2'

print('Extracting '+filename+'.img ...')
print('Extracting '+ img)

chunk = 10240

try:
with open(outdir+os.sep+filename+'.img', 'wb') as o:
with open(img_path, 'wb') as o:
while filesize > 0:
if chunk > filesize:
chunk = filesize

o.write(f.read(chunk))
filesize -= chunk
except:
print('ERROR: Failed to create '+filename+'.img\n')
print('ERROR: Failed to create ' + img +'\n')
return 1

img_files.append(filename)

if os.name != 'nt':
if os.path.isfile('crc'):
print('Calculating crc value for '+filename+'.img ...\n')
if os.path.isfile(crcpath) and not skipcrc:
print('Calculating crc value for ' + img)

crcval = []
if py2:
Expand All @@ -99,11 +102,11 @@ def extract(source, flist):
crcval.append('%02X' % i)

crcval = ''.join(crcval)
crcact = cmd('./crc output/'+filename+'.img')

crcact = cmd(crcpath, os.path.realpath(img_path))

if crcval != crcact:
print('ERROR: crc value for '+filename+'.img does not match\n')
return 1
print('ERROR: CRC for ' + img + '\n')
else:
f.seek(filesize, 1)

Expand All @@ -123,6 +126,15 @@ if __name__ == '__main__':
optional = parser.add_argument_group('Optional')
optional.add_argument("-h", "--help", action="help", help="show this help message and exit")
optional.add_argument("-l", "--list", nargs="*", metavar=('img1', 'img2'), help="List of img files to extract")
optional.add_argument("-o", "--output", action="store", help="Put output in the given folder")
optional.add_argument("-s", "--skip-crc", dest="skip_crc", action="store_true", default=False, help="Do not compute and compare CRC")
args = parser.parse_args()

extract(args.filename, args.list)
splituapp_path = os.path.realpath(__file__)
crc_path = os.path.join(os.path.dirname(splituapp_path), "crc")

output_path = "output"
if (args.output != None):
output = args.output

extract(args.filename, output, args.list, args.skip_crc, crc_path)