Created
February 5, 2018 05:28
-
-
Save auscompgeek/45f2598e5b15b1dd8735786e9f78f9f6 to your computer and use it in GitHub Desktop.
Extract ap51-flash combined ext image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import hashlib | |
import sys | |
f = open(sys.argv[1], 'rb') | |
ce_version = f.read(4) | |
assert ce_version == b'CE01' | |
img_type = f.read(32).strip().decode() | |
print('Image type:', img_type) | |
file_num = int(f.read(2), 16) | |
print('Image contains', file_num, 'files') | |
files = [] | |
for _ in range(file_num): | |
filename = f.read(32).strip().decode() | |
size = int(f.read(8), 16) | |
md5 = f.read(32).decode() | |
files.append((filename, size, md5)) | |
f.seek(0x10000) | |
for filename, size, md5 in files: | |
print('Extracting', filename, 'size', size, 'md5', md5) | |
data = f.read(size) | |
assert hashlib.md5(data).hexdigest() == md5 | |
with open(filename, 'wb') as fw: | |
fw.write(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment