def CalSectCrc(data):
sections = unpack("<I", data[15:15+4])[0]
ptr = 27
print "[+]Patching section CRC..."
for i in range(sections):
section = data[ptr:ptr+10]
type, offset, size = unpack("<HII", section)
# print "0x%04X: at offset 0x%08X, size 0x%08X [ends at 0x%08X]" %\
# (type, offset, size, offset+size)
if type == 0xc002:
print "\tUnknown header type C002 ignored..."
ptr+=10
continue
section_data = data[offset:offset+size]
c = (crc32(section_data[:24] + "\0"*4 + section_data[28:], \
0xFFFFFFFF)^0xFFFFFFFF) & 0xffffffff
print "\tCalculated crc: %s" % ("0x%08X" % c)
section_data = section_data[:24] + pack("<I", c) + section_data[28:]
data = data[:offset] + section_data + data[offset+size:]
ptr+=10
return data
评论列表
文章目录