def ChkMainCrc(filename):
'''
check main CRC
'''
data = open(filename,'rb').read()
for i in range(0, len(data)-4):
# these 4 bytes are the CRC embedded in the FirmwareUpdate.bin
block = data[i:i+4]
# calculate CRC for the rest of the data (replace the 4 bytes with 0's)
c = (crc32(data[:i] + "\0"*4 + data[i+4:],0xFFFFFFFF)^0xFFFFFFFF) & 0xffffffff
if pack("<I", c) in block:
print "Found at offset dec=%d hex=%08X" % (i,i)
print "CRC=%08X" % c
break
评论列表
文章目录