网站首页 > 教程文章 正文
电脑越来越慢,发现硬盘空间被大量占用,发现是微信自己账号下的Image文件夹引起的,因不清楚里面的图片有些是否有用,想清理一下。
会代码的朋友可以看一下代码,自己做一下。
不会代码的朋友可以看一下最后的结果,是否是自己想要的结果。如果是就去sdxlp.cn/tool/wechatdat这个地方看一下,是工具可以帮到你,比较糙,但好用。
进去后发现都是dat格式,无法打开。修改后缀后仍无法打开,被加密了。
二进制方式打开文件后发现是这样的。通过异或运算加密了。
解码代码如下(批量操作):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
def main():
indir = r'G:\wx\2019-06'
outdir = r'G:\wx\out2019-06'
# 获取文件夹下所有文件
infiles = os.listdir(indir)
# 计数成功的文件个数
count = 0
# 循环每个文件进行判断、转换
for infile in infiles:
# 获取文件名
filename = infile[0:infile.find('.')]
# 二进制读取文件
f1 = open(os.path.join(indir, infile), 'rb')
infilebytes = f1.read()
newfile = []
# 判断图片类型JPG,通过异或判定
if (infilebytes[0] ^ 0xFF) == (infilebytes[1] ^ 0xD8):
y1 = infilebytes[0] ^ 0xFF
print('%s,文件是JPG图片,每个字节是根据0x%X异或进行加密' % (infile, y1))
# 字节进行异或转换,组合成新的文件
for i in infilebytes:
newbyte = i ^ y1
newfile.append(newbyte)
newfile2 = bytes(newfile)
# 写入新文件
f2 = open(os.path.join(outdir, filename+'.jpg'), 'wb')
f2.write(newfile2)
count += 1
# 判断图片类型PNG,通过异或判定
elif (infilebytes[0] ^ 0x89) == (infilebytes[1] ^ 0x50):
y1 = infilebytes[0] ^ 0x89
print('%s,文件是PNG图片,每个字节是根据0x%X异或进行加密' % (infile, y1))
for i in infilebytes:
newbyte = i ^ y1
newfile.append(newbyte)
newfile2 = bytes(newfile)
f2 = open(os.path.join(outdir, filename+'.png'), 'wb')
f2.write(newfile2)
count += 1
# 判断图片类型GIF,通过异或判定
elif (infilebytes[0] ^ 0x47) == (infilebytes[1] ^ 0x49):
y1 = infilebytes[0] ^ 0x47
print('%s,文件是GIF图片,每个字节是根据0x%X异或进行加密' % (infile, y1))
for i in infilebytes:
newbyte = i ^ y1
newfile.append(newbyte)
newfile2 = bytes(newfile)
f2 = open(os.path.join(outdir, filename+'.gif'), 'wb')
f2.write(newfile2)
count += 1
else:
print('%s无法识别的类型!' % infile)
print('识别出图片%d张' % count)
if __name__ == '__main__':
main()
运行结果:
猜你喜欢
- 2025-04-11 手把手教你开发智能备份神器,小白也能30分钟搞定!
- 2025-04-11 画像笔记23- 作业流程调度(2)(作业流程图怎么画)
- 2025-04-11 Python接口自动化之常见用例读取方法介绍
- 2025-04-11 AI办公自动化:批量合并多个Excel表格的数据并汇总
- 2025-04-11 Python自动化脚本应用与示例(pythonui自动化脚本)
- 2025-04-11 21-02-Python-文件操作下(python文件操作方法)
- 2025-04-11 Python定时任务,三步实现自动化(python定时任务,三步实现自动化效果)
- 2025-04-11 自动下载邮箱里未阅读的发票,并用邮件标题里指定的几个字命名
- 2025-04-11 照片整理很繁琐?3个python脚本帮你快速整理照片
- 2025-04-11 Python语言的12个基础知识点小结(python 语言基础)
- 06-18CentOS7安装Mongodb 4.x.x(centos7安装openstack)
- 06-18Window环境配置Mongodb(mongodb默认配置文件路径)
- 06-18FineReport如何连接和使用MongoDB数据库
- 06-18nosql之mongodb(nosql怎么读正确发音)
- 06-18Mongodb centos7安装(mongodb4.4.2安装教程)
- 06-18群晖(Synology)NAS 安装 MongoDB(群晖安装nat123)
- 06-18MongoDB 安装及实践(mongodb的安装过程和操作命令)
- 06-18MongoDB最全详解(万字图文总结)(mongodb lsm)
- 最近发表
-
- CentOS7安装Mongodb 4.x.x(centos7安装openstack)
- Window环境配置Mongodb(mongodb默认配置文件路径)
- FineReport如何连接和使用MongoDB数据库
- nosql之mongodb(nosql怎么读正确发音)
- Mongodb centos7安装(mongodb4.4.2安装教程)
- 群晖(Synology)NAS 安装 MongoDB(群晖安装nat123)
- MongoDB 安装及实践(mongodb的安装过程和操作命令)
- MongoDB最全详解(万字图文总结)(mongodb lsm)
- CentOS安装MongoDB教程(centos安装mpich)
- MongoDB入门指南:下载、安装和配置一款强大的NoSQL数据库
- 标签列表
-
- location.href (44)
- document.ready (36)
- git checkout -b (34)
- 跃点数 (35)
- 阿里云镜像地址 (33)
- qt qmessagebox (36)
- mybatis plus page (35)
- vue @scroll (38)
- 堆栈区别 (33)
- 什么是容器 (33)
- sha1 md5 (33)
- navicat导出数据 (34)
- 阿里云acp考试 (33)
- 阿里云 nacos (34)
- redhat官网下载镜像 (36)
- srs服务器 (33)
- pico开发者 (33)
- https的端口号 (34)
- vscode更改主题 (35)
- 阿里云资源池 (34)
- os.path.join (33)
- redis aof rdb 区别 (33)
- 302跳转 (33)
- http method (35)
- js array splice (33)