引用个概念:
图种是一种利用图片文件来传递压缩包的技巧。图种以图像浏览器开启时,就是一张单纯的图片。但可以以压缩软件对其解压缩,获取附加在图片档后的压缩包内容。
例子
- 下面例子引入了本斯蒂勒的白日梦想家电影
原理
- 将二进制的图片和zip压缩包相融合
- 在照片应用打开照片依赖于,文件的文件后缀,但是不仅有这一识别方法,还有依赖于十六进制的文件头。
- 通常png文件为:'89 50 4e 47',还有文件结尾的的iend十六进制'00 00 00 00 49 45 4e 44 ae 42 60 82 '那么到此为止图片应用的识别就结束了(拒绝内卷,从图片识别做起LOL)。
- 那么观察一下图种的十六进制会发现,会有一段'50 4b 03 04',那么这就是zip的文件头,在压缩软件的高效的排错算法可以精准查找到zip文件头并识别。
代码实现
#函数读取两个文件路径并相加
#使用闭包函数获取名称
def twice_process(old_func):
def inner(*args, **kwargs):
res = old_func(**kwargs)
with open(f'{args[0]}.png','wb') as f:
f.write(res)
return inner
@twice_process
def plus_process(pic_path,zip_path):
with open(pic_path,'rb') as f:
pic_bin = f.read()
with open(zip_path,'rb') as f1:
zip_bin = f1.read()
all_bin = pic_bin+zip_bin
return all_bin
#接受用户输入的名称
input_user_input = input('enter your file_name: ')
input_pic_path = input('enter your pic path: ')
input_zip_path = input('enter your zip file path: ')
plus_process(f'{input_user_input}',pic_path=f"{input_pic_path}",zip_path=f"{input_zip_path}")