CRC修复

main
amuliang 2024-03-20 16:24:25 +08:00
parent 6fa426711b
commit 7cad780156
1 changed files with 9 additions and 0 deletions

View File

@ -149,6 +149,15 @@ class PNG:
data[height_begin: height_begin+4] = height.to_bytes(4, byteorder='big') data[height_begin: height_begin+4] = height.to_bytes(4, byteorder='big')
print(f'[*] 已将图片高度设置为{height}') print(f'[*] 已将图片高度设置为{height}')
changed = True changed = True
chunk_data = data[data_begin: data_begin+length]
if not PNG.test_ihdr_chunk(ctype + chunk_data, crc):
print('[x] 修复CRC校验码')
chunk = ctype + chunk_data
crc32 = binascii.crc32(chunk) & 0xffffffff
data[data_begin+length:data_begin+length+4] = crc32.to_bytes(4, byteorder='big')
changed = True
b = True
return changed, data, width, height return changed, data, width, height
@staticmethod @staticmethod