还原图片真实宽高(python3)
import binascii import struct import sys file = input("图片地址:") fr = open(file,'rb').read() data: bytearray = bytearray(fr[0x0c:0x1d]) crc32key = eval('0x'+str(binascii.b2a_hex(fr[0x1d:0x21]))[2:-1]) #原来的代码: crc32key = eval(str(fr[29:33]).replace('\\x','').replace("1b'",'0x').replace("'",'')) n = 4095 for w in range(n): width = bytearray(struct.pack('>i', w)) for h in range(n): height = bytearray(struct.pack('>i', h)) for x in range(4): data[x+4] = width[x] data[x+8] = height[x] crc32result = binascii.crc32(data) & 0xffffffff if crc32result == crc32key: print(width,height) newpic = bytearray(fr) for x in range(4): newpic[x+16] = width[x] newpic[x+20] = height[x] fw = open(file+'.png','wb') fw.write(newpic) fw.close file.close()
相关文章
没有相关内容!
暂无评论...