好奇心促使我到google固件发现它在MI论坛上出现的Uboot图片头和随后被证明相当不错的数据
,我只是煮一个python脚本翻录压缩BLOB出来的固件,并用7zip的产量没有错误测试斑点
脚本
import struct
import binascii
import datetime
fileext = { 0:'none',1:'gzip',2:'bzip2',3:'lzma',4:'lzo'}
fin = open("tf_recovery.img" , "rb")
uimghdr = fin.read(64)
magic, = struct.unpack("!i" , uimghdr[ 0:4 ] )
headercrc32, = struct.unpack("!i" , uimghdr[ 4:8 ] )
timestamp, = struct.unpack("!i" , uimghdr[ 8:12] )
datasize, = struct.unpack("!i" , uimghdr[12:16] )
LoadAddress, = struct.unpack("!i" , uimghdr[16:20] )
EntryPtAddr, = struct.unpack("!i" , uimghdr[20:24] )
Datacrc32, = struct.unpack("!i" , uimghdr[24:28] )
OperatingSys, = struct.unpack("!b" , uimghdr[28:29] )
Architecture, = struct.unpack("!b" , uimghdr[29:30] )
ImageType, = struct.unpack("!b" , uimghdr[30:31] )
CompressType, = struct.unpack("!b" , uimghdr[31:32] )
ImageName, = struct.unpack("!32s" , uimghdr[32:64] )
uimgdata = fin.read(datasize)
fin.close()
copy = list(uimghdr)
copy[4:8] = '\x00\x00\x00\x00'
crcdata = ''.join(copy)
realhdrcrc32 = binascii.crc32(crcdata)
realdatacrc32 = binascii.crc32(uimgdata)
assert ( realhdrcrc32 == headercrc32 )
assert ( realdatacrc32 == Datacrc32 )
print ("UBoot Header Magic %s" ) % hex(magic)
print ("UBoot Header crc32 %s" ) % hex( realhdrcrc32)
print ("UBoot Header Tstmp %s" ) % datetime.datetime.fromtimestamp(timestamp)
print ("UBoot Header DSize %s" ) % hex(datasize)
print ("Uboot Compression %s" ) % fileext[CompressType]
fout = open('out.xz' , 'wb')
fout.write(uimgdata)
fout.close()
结果是
:\>ubootimgdump.py
UBoot Header Magic 0x27051956
UBoot Header crc32 0x5799cfc3
UBoot Header Tstmp 2018-06-06 12:32:07
UBoot Header DSize 0x1a4ffc
Uboot Compression lzma
:\>e:\7Z\7z.exe t out.xz
7-Zip [32] 15.14 : Copyright (c) 1999-2015 Igor Pavlov : 2015-12-31
Scanning the drive for archives:
1 file, 1724412 bytes (1684 KiB)
Testing archive: out.xz
--
Path = out.xz
Type = xz
Physical Size = 1724412
Method = LZMA2:23 CRC64
Streams = 1
Blocks = 1
Everything is Ok
Size: 3590624
Compressed: 1724412
:\>