惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Security Affairs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Jina AI
Jina AI
P
Palo Alto Networks Blog
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Blog — PlanetScale
Blog — PlanetScale
S
Schneier on Security
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
雷峰网
雷峰网
T
Tenable Blog
人人都是产品经理
人人都是产品经理
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
AWS News Blog
AWS News Blog
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
Scott Helme
Scott Helme
SecWiki News
SecWiki News
C
CERT Recently Published Vulnerability Notes
Recorded Future
Recorded Future
I
InfoQ
Security Archives - TechRepublic
Security Archives - TechRepublic
Help Net Security
Help Net Security
Cloudbric
Cloudbric
C
Check Point Blog
Engineering at Meta
Engineering at Meta
TaoSecurity Blog
TaoSecurity Blog
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
N
News and Events Feed by Topic
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
腾讯CDC
量子位
Application and Cybersecurity Blog
Application and Cybersecurity Blog
K
Kaspersky official blog
Vercel News
Vercel News
F
Full Disclosure
T
Troy Hunt's Blog
Forbes - Security
Forbes - Security
S
Security @ Cisco Blogs

博客园 - 润之

关于 Excel 中导入 JSON 文件 Git Bash 在使用 pacman 安装软件包时的报错问题处理 .NET 操作 RabbitMQ 踩坑记录 Git Bash 中 pacman 安装软件包失败的问题处理 深度操作系统 deepin 20.8 定制的 SSH 安全模块问题 关于在WSL中使用RabbitMQ的问题 PowerShell脚本编写踩坑记 访问局域网资源,出现“指定的网络密码不正确” 关于禅道的白屏问题 Python处理编码汉字的一些方法收集 使用xrdp远程管理debian的一些记录 安利一个分支版本的Notepad2 匿名类对象的相关测试 关于 Win10 下使用 IETester 的问题 关于 Windows 10 字体安装目录的问题 关于 NPOI 导出的 Excel 出现“部分内容有问题” 的解决方法 解决美图看看不出现在“Open with”的子菜单中的问题 关于BLOB/TEXT字段存储设计及性能的简单研究 Win10 远程服务器版
微信图片缓存中的 dat 文件处理
润之 · 2022-04-10 · via 博客园 - 润之

不太能搞懂微信的图片过期机制,有的图片在缓存目录中明明有相应的 dat 文件,它却提示“文件已过期或被清理”,真让人很郁闷。正好最近又确实有个重要的图片文件需要恢复,于是就搜索了一下相关的资料,发现微信的这个图片 dat 文件其实就是简单的异或处理了一下,关键是要找出来这个异或值,其实也不复杂,用 HEX 编辑器打开任意一个 dat 文件,取前 2 个字节的值,与常见的图片文件头进行 XOR 运算(Windows计算器,程序员模式),若结果是两个相同的字节,就取这个字节值。常见图片文件头:JPG 格式是 FFD8,GIF 格式是 4749,PNG 格式是 8950,其它格式的可以自行找一个其格式的正常文件用 HEX 编辑器打开看看。

尝试用 Python 写了个脚本,经过本人测试,工作基本正常:

 1 # -*- coding: utf-8 -*-
 2 
 3 import io
 4 import os
 5 
 6 code = 0x00
 7 jpg_code = bytearray([0xFF, 0xD8])
 8 gif_code = bytearray([0x47, 0x49])
 9 png_code = bytearray([0x89, 0x50])
10 
11 # 这里修改为要处理的 dat 文件所在文件夹
12 base_dir = "D:\\wechat_dat"
13 
14 def imageDecode(path, filename):
15   if filename.endswith(".dat"):
16     print(path, "/", filename)
17     with open(os.path.join(path, filename), "rb") as dat:
18         heads = bytearray(dat.read(2))
19 
20         # 判断是否为 GIF 格式
21         if heads[0] ^ gif_code[0] == heads[1] ^ gif_code[1]:
22           code = heads[0] ^ gif_code[0]
23         # 判断是否为 PNG 格式
24         elif heads[0] ^ png_code[0] == heads[1] ^ png_code[1]:
25           code = heads[0] ^ png_code[0]
26         # 默认都按 JPG 格式处理
27         else:
28           code = heads[0] ^ jpg_code[0]
29 
30         out = open(os.path.join(path, filename + ".jpg"), "wb")
31         dat.seek(0)
32         for now in dat:
33             for new_byte in now:
34                 new_byte = new_byte ^ code
35                 out.write(bytes([new_byte]))
36         dat.close()
37         out.close()
38 
39 for filename in os.listdir(base_dir):
40   if not os.path.isdir(os.path.join(base_dir, filename)):
41     imageDecode(base_dir, filename)

PS. 刚发现,输出的时候都按 jpg 扩展名输出了,不太严谨,不过我是用 ACDSee 看图,各种格式都能正确识别和显示,所以这块就不处理了,有兴趣的朋友可以自行改进代码。