start to dissect the update header itself..

This commit is contained in:
Holger Hans Peter Freyther 2016-12-11 23:11:28 +01:00
parent c5b91afaa9
commit edb07ccd98
1 changed files with 36 additions and 16 deletions

View File

@ -31,15 +31,44 @@ rstr = io.BytesIO(data)
# of thr file and not accounted for in the len. See the
# dsp2.diff as an example?
common_hdr = b'\x50\x40\x01\x00\x80\x38\x01\x00\x00\x00\x00'
fs_hdr = common_hdr + b'\x80\x80\x02\x00\x00'
def dissect_upgrade(upd):
"""
50 40 01 00 80 38 01 00 00 00 00 80 -- general header...
The specific header...followed after fs_hdr
c8000200 -- ram size
00000400 -- sector size
c80d0000 -- dic_sz
b5040000 -- compress_sz
22000200 -- 0x22 min_alloc_ram_use | ext_info_sz 2
00005f00 -- 0x0000=num_copy 0x5f00==num_diff
03000000 -- 0x0300=num_insert 0x000==num_delete
00000000 -- 0x0000=num_delete_dirs 0x0000==num_dirs
00000400 -- 0x0000=num_del_link 0x0400=num_link
5f000300 -- 0x5f00=num_cri_update .. 0x0300=num_crit_inser
lzma now?
"""
if fs_hdr != upd[0:len(fs_hdr)]:
print("No fs type update with type: 0x%.2x" % upd[12])
return 0
assert fs_hdr == upd[0:len(fs_hdr)]
upd_hdr = upd[len(fs_hdr):64]
upd_dat = upd[64:]
print(hexstring(upd_hdr))
#print(hexstring(upd_dat))
# Parse the chunk..
checksum = rstr.read(4)
blen = rstr.read(4)
flen = struct.unpack("<I", blen)[0]
chunk1 = rstr.read(flen - 8)
print("Guessing CRC to match {} {}".format(
struct.unpack("<I", checksum)[0],
crc32.calculate(blen+chunk1)))
assert struct.unpack("<I", checksum)[0] == crc32.calculate(blen+chunk1)
assert chunk1[0:len(common_hdr)] == common_hdr
dissect_upgrade(chunk1)
# read padding
if len(chunk1) % 4 > 2:
@ -51,18 +80,9 @@ t_blen = rstr.read(4)
t_flen = struct.unpack("<I", t_blen)[0]
t_chnk = rstr.read(t_flen - 8)
assert len(t_chnk) == t_flen - 8
assert struct.unpack("<I", t_chksum)[0] == crc32.calculate(t_blen+t_chnk)
assert t_chnk[0:len(common_hdr)] == common_hdr
print("Guessing CRC to match {} {}".format(
struct.unpack("<I", t_chksum)[0],
crc32.calculate(t_blen+t_chnk)))
print(len(t_chnk)%4)
trailer = rstr.read()
print("REST {} {}".format(len(trailer), hexstring(trailer)))
assert len(trailer) == 0
#wanted_le = struct.unpack("<I", checksum)[0]
#wanted_be = struct.unpack(">I", checksum)[0]
#for i in range(0, len(data)):
# for j in range(0, len(data)):
# crc = crc32.calculate(data[i:j])
# if crc == wanted_le or wanted_be == crc:
# print("Got it with {} {}".format(i, j))