MISC图片批量处理jio本


此处以ctfshow中MISC入门题目作为切入点
感兴趣的同学可以一边做题一边参照

  • 批量修改PNG图片的宽
import zlib
import struct

filename = "flag.png"
with open(filename, 'rb') as f:
	all_b = f.read()
	#w = all_b[16:20]
	#h = all_b[20:24]
	for i in range(901, 1200):
		name = str(i) + ".png"	
		f1 = open(name, "wb")
		im = all_b[:16] + struct.pack('>i', i) + all_b[20:]
		f1.write(im)
		f1.close()
  • 批量修改JPG图片的宽
import zlib
import struct

filename = "flag.jpg"
with open(filename, 'rb') as f:
	all_b = f.read()
	#w = all_b[159:161]
	#h = all_b[157:159]
	for i in range(901, 1200):
		name = str(i) + ".jpg"	
		f1 = open(name, "wb")
		im = all_b[:159] + struct.pack('>i', i) + all_b[161:]
		f1.write(im)
		f1.close()
  • 批量修改GIF图片的宽
import zlib
import struct

filename = "flag.gif"
with open(filename, 'rb') as f:
	all_b = f.read()
	#w = all_b[38:40]
	#h = all_b[36:38]
	for i in range(901, 1200):
		name = str(i) + ".gif"	
		f1 = open(name, "wb")
		im = all_b[:38] + struct.pack('>i', i) + all_b[40:]
		f1.write(im)
		f1.close()

相关