Created
June 1, 2020 21:04
-
-
Save shinyquagsire23/ba0f6209592d50fb8e4166620228aaa5 to your computer and use it in GitHub Desktop.
Nexus 5 imagedata extraction
This file contains hidden or 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
import struct | |
import imageio | |
import numpy as np | |
import sys | |
if len(sys.argv) < 2: | |
print ("Usage: image-extract.py [imgdata.image]") | |
exit(0) | |
f = open(sys.argv[1], "rb") | |
header = f.read(0x18) | |
magic, unk, res_table_cnt, unk2, unk3 = struct.unpack("<8sLLLL", header) | |
magic = magic.rstrip(bytes([0x00])).decode('utf-8') | |
print(magic, unk, res_table_cnt, unk2, unk3) | |
res_table_offs = 0x18 | |
f.seek(res_table_offs) | |
for i in range(0, res_table_cnt): | |
f.seek(res_table_offs + i * 0x28) | |
res_ent = f.read(0x28) | |
name, width, height, offs_x, offs_y, offset, size = struct.unpack("<16sLLLLLL", res_ent) | |
name = name.rstrip(bytes([0x00])).decode('utf-8') | |
print(name, hex(offset), hex(size), width, height, offs_x, offs_y) | |
f.seek(offset) | |
image_rle = f.read(size) | |
image_array = np.zeros((height,width,3), dtype=np.uint8) | |
xpos = 0 | |
ypos = 0 | |
for j in range(0, size>>2): | |
num, r, g, b = image_rle[j*4:(j+1)*4]#struct.unpack("<BBBB", f.read(4)) | |
for k in range(0, num): | |
image_array[ypos][xpos] = (r,g,b) | |
xpos += 1 | |
if (xpos >= width): | |
xpos = 0 | |
ypos += 1 | |
imageio.imwrite(name + '.png', image_array) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment