forked from zss192/CTF-python-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11.根据CRC爆破宽高.py
27 lines (24 loc) · 994 Bytes
/
11.根据CRC爆破宽高.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
##用于根据CRC爆破宽和高,修改相应值使图片正常显示,
##宽高错误时,linux下打不开图片,win可以
import zlib
import struct
filename = 'test.png'
with open(filename, 'rb') as f:
all_b = f.read()
crc32key = int(all_b[29:33].hex(),16)
data = bytearray(all_b[12:29])
n = 4095 #理论上0xffffffff,但考虑到屏幕实际/cpu,0x0fff就差不多了
for w in range(n): #高和宽一起爆破
width = bytearray(struct.pack('>i', w)) #q为8字节,i为4字节,h为2字节
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 = zlib.crc32(data)
if crc32result == crc32key:
print("宽为:",end="")
print(width)
print("高为:",end="")
print(height)
exit(0)