当前位置: 首页> 健康> 养生 > python实现微信聊天图片DAT文件还原

python实现微信聊天图片DAT文件还原

时间:2025/7/11 14:25:38来源:https://blog.csdn.net/as604049322/article/details/140852887 浏览次数:0次

完整代码如下:

from glob import glob
import os
from tqdm import tqdmdef get_sign(dat_r):signatures = [(0x89, 0x50, 0x4e), (0x47, 0x49, 0x46), (0xff, 0xd8, 0xff)]mats = [".png", ".gif", ".jpg"]for now in dat_r:for j, xor in enumerate(signatures):res = [nowByte ^ xor_byte for nowByte,xor_byte in zip(now[:3], xor)]if res[0] == res[1] == res[2]:return res[0], mats[j]else:raise Exception("no valid signature is found")def imageDecode(file, root_path, dest_path=None):dat_r = open(file, "rb")try:sign, mat = get_sign(dat_r)dat_r.seek(0)data = bytes(byte ^ sign for byte in dat_r.read())relative_path = os.path.relpath(file, root_path)if dest_path is None:dest_path = os.path.join(root_path, "CovertImage")dest = os.path.join(dest_path,relative_path.replace(".dat", mat))os.makedirs(os.path.dirname(dest), exist_ok=True)with open(dest, "wb") as write:write.write(data)finally:dat_r.close()def main(into_path, out_path=None):for file in tqdm(glob(os.path.join(into_path, "**", "*.dat"), recursive=True)):imageDecode(file, into_path, out_path)if __name__ == '__main__':into_path = r"D:\tmp\wx_icon_dat"
#     out_path = r"D:\tmp\wx_icon_dat"main(into_path, out_path=None)

支持递归处理,不指定结果文件夹时,结果将写入into_path+"CovertImage"目录下。
还原示例:
在这里插入图片描述

关键字:python实现微信聊天图片DAT文件还原

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: