李成笔记网

专注域名、站长SEO知识分享与实战技巧

解码微信 .dat文件为图片格式.jpg

异或,英文为exclusive OR,缩写成xor

异或(xor)是一个数学运算符。它应用于逻辑运算。异或的数学符号为“⊕”,计算机符号为“xor”。异或也叫半加运算,其运算法则相当于不带进位的二进制加法:二进制下用1表示真,0表示假,则异或的运算法则为:0⊕0=0,1⊕0=1,0⊕1=1,1⊕1=0(同为0,异为1),这些法则与加法是相同的,只是不带进位,所以异或常被认作不进位加法。例如:

十六进制(简写为hex或HEX下标16):

C语言、C++、Shell、Python、Java语言及其他相近的语言使用字首“0x”,例如“0x5A3”。开头的“0”令解析器更易辨认数,而“x”则代表十六进制(就如“O”代表八进制)。在“0x”中的“x”可以大写或小写。对于字符量C语言中则以x+两位十六进制数的方式表示,如xFF。

.dat文件16进制解码

.jpg文件16进制解码


异或运算结果:0x8

转码程序:

import os

#微信image文件路径

into_path=r'F:\Python\file\weixin'

#微信图片转码后的保存位置

out_path = r'F:\Python\file\weixin\weixin_picture/'#或写成F:\Python\file\weixin\weixin_picture\\


def imageDecode(f,fn):

"""

解码

param f: 微信图片路径

param fn:微信图片目录下的.bat

return:

"""

# 读取.bat

dat_read = open(f,"rb")

# 图片输出路径

out = out_path + fn + ".jpg"

# 图片写入

png_write = open(out,"wb")

# 循环字节

for now in dat_read:

for nowByte in now:

# 转码计算

newByte = nowByte ^ 0x8

# 转码后重新写入

png_write.write(bytes([newByte]))

dat_read.close()

png_write.close()

# pass


def findFile(f):

"""

寻找文件

param f:微信图片路径

return:

"""

# 把路径文件夹下的文件以列表呈现

fsinfo = os.listdir(f)

# 逐步读取文件

for fn in fsinfo:

# 拼接路径:微信图片路径+图片名

temp_path = os.path.join(f,fn)

# 判断目录还是.bat

if os.path.isfile(temp_path): #temp_path需为绝对路径,判断是否为文件,也可 if not os.path.isdir(temp_path):

print('文件路径:{}'.format(temp_path))

print(fn)

# 转码函数

imageDecode(temp_path,fn)

else:

pass


# 运行

findFile(into_path)

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言