当前位置:网站首页>Computer wechat user picture decoded into picture in DAT format (TK version)
Computer wechat user picture decoded into picture in DAT format (TK version)
2022-06-25 02:50:00 【Fingertip magician】
Recent learning TK, Want to write a small project . It's just that the original theme has been improved .
Let's see the effect in the figure above :

The design idea is as follows :
1. Select the path of wechat picture folder
2. Read the files in the folder , Load into Treeview in ( You can learn Treeview Use )
3. When a row is selected ,TK Label Show pictures in
Difficulty one :(TK, I won't support it jpg, So we need to use PIL To deal with it )
Difficulty 2 : Nature is the key part of wechat image transposition pictures
4. Add the save picture button , You can generate pictures in the original path . Delete picture button , You can delete what you don't need dat file , To reduce the space
The source code can be generated exe file , Links are as follows :
Wechat pictures DAT Format decoded to picture
The complete code is as follows , Not organized , Just for learning :
#!/usr/bin/env python
# Author:Veray Zhou
import tkinter as tk
from tkinter.filedialog import *
from tkinter.ttk import *
import os
from PIL import Image, ImageTk
from io import BytesIO
window = tk.Tk()
window.title(' Pictures of wechat users on the computer side DAT Format decoded to picture ')
window.geometry('450x750')
files = []
dir_path = ''
newfile_path = ''
def showFiles(dir_path):
inFiles = os.listdir(dir_path)
i = 1
files.clear()
for file in inFiles:
# Get file type
filetype = os.path.splitext(file)[1]
if filetype == '.dat':
# Get file size
filesize = os.path.getsize(os.path.join(dir_path, file))
# Serial number file name file size
files.append((i, file, '{:.2f}KB'.format(filesize/float(1024))))
i += 1
# print(files)
return files
def select_path():
global dir_path
dir_path = askdirectory()
e.delete(0, 'end')
e.insert(0, dir_path)
delete_all()
if dir_path:
files = showFiles(dir_path)
insert()
def insert():
print(files)
for index, file in enumerate(files):
datagrid.insert('', END, values=file)
print(files)
# The first line is selected by default
if files:
datagrid.selection_set(datagrid.get_children()[0])
def delete_all():
items = datagrid.get_children()
for item in items:
datagrid.delete(item)
def select(*args):
print(datagrid.selection())
selectItem = datagrid.item(datagrid.selection())['values']
filename = selectItem[1]
showImage(filename)
def showImage(filename):
createTempPic(dir_path, filename)
def createTempPic(files_dir_path, filename):
filePath = os.path.join(files_dir_path, filename)
f1 = open(filePath, 'rb')
infilebytes = f1.read()
newfile = []
global newfile_path
#print(os.path.join(os.path.dirname(filePath), 'temp.jpg'))
# Judge the type of picture JPG, Determine by XOR
if (infilebytes[0] ^ 0xFF) == (infilebytes[1] ^ 0xD8):
y1 = infilebytes[0] ^ 0xFF
print('%s, File is JPG picture , Each byte is based on 0x%X XOR encrypts ' % (filePath, y1))
# # Bytes are XOR converted , Combine into a new file
for i in infilebytes:
newbyte = i ^ y1
newfile.append(newbyte)
newfile2 = bytes(newfile)
# display picture
show(newfile2)
# Judge the type of picture PNG, Determine by XOR
elif (infilebytes[0] ^ 0x89) == (infilebytes[1] ^ 0x50):
y1 = infilebytes[0] ^ 0x89
print('%s, File is PNG picture , Each byte is based on 0x%X XOR encrypts ' % (filePath, y1))
for i in infilebytes:
newbyte = i ^ y1
newfile.append(newbyte)
newfile2 = bytes(newfile)
# display picture
show(newfile2)
# Judge the type of picture GIF, Determine by XOR
elif (infilebytes[0] ^ 0x47) == (infilebytes[1] ^ 0x49):
y1 = infilebytes[0] ^ 0x47
print('%s, File is GIF picture , Each byte is based on 0x%X XOR encrypts ' % (filePath, y1))
for i in infilebytes:
newbyte = i ^ y1
newfile.append(newbyte)
newfile2 = bytes(newfile)
# display picture
show(newfile2)
else:
print('%s Unrecognized type !' % filePath)
newfile_path = ''
print(' Picture displayed !')
# Save the picture
def SavePic(files_dir_path, filename):
filePath = os.path.join(files_dir_path, filename)
f1 = open(filePath, 'rb')
infilebytes = f1.read()
newfile = []
global newfile_path
# Judge the type of picture JPG, Determine by XOR
if (infilebytes[0] ^ 0xFF) == (infilebytes[1] ^ 0xD8):
y1 = infilebytes[0] ^ 0xFF
print('%s, File is JPG picture , Each byte is based on 0x%X XOR encrypts ' % (filePath, y1))
# # Bytes are XOR converted , Combine into a new file
for i in infilebytes:
newbyte = i ^ y1
newfile.append(newbyte)
newfile2 = bytes(newfile)
# Write new file
f2 = open(os.path.join(files_dir_path, filename.lower().replace('.dat', '.jpg')), 'wb')
f2.write(newfile2)
# Judge the type of picture PNG, Determine by XOR
elif (infilebytes[0] ^ 0x89) == (infilebytes[1] ^ 0x50):
y1 = infilebytes[0] ^ 0x89
print('%s, File is PNG picture , Each byte is based on 0x%X XOR encrypts ' % (filePath, y1))
for i in infilebytes:
newbyte = i ^ y1
newfile.append(newbyte)
newfile2 = bytes(newfile)
f2 = open(os.path.join(files_dir_path , filename.lower().replace('.dat', '.png')), 'wb')
f2.write(newfile2)
# Judge the type of picture GIF, Determine by XOR
elif (infilebytes[0] ^ 0x47) == (infilebytes[1] ^ 0x49):
y1 = infilebytes[0] ^ 0x47
print('%s, File is GIF picture , Each byte is based on 0x%X XOR encrypts ' % (filePath, y1))
for i in infilebytes:
newbyte = i ^ y1
newfile.append(newbyte)
newfile2 = bytes(newfile)
f2 = open(os.path.join(files_dir_path, filename.lower().replace('.dat', '.gif')), 'wb')
f2.write(newfile2)
else:
print('%s Unrecognized type !' % filePath)
print(' End of generation ')
def show(newfile2):
w_box=423
h_box=310
bytes_stream = BytesIO(newfile2)
img_open = Image.open(bytes_stream)
img_open_resize = img_open.resize((w_box,h_box))
# print(img_open)
img = ImageTk.PhotoImage(image=img_open_resize)
# print(img)
label_show.config(image=img,width=w_box, height=h_box)
label_show.image =img
# def show():
# w_box=422
# h_box=400
# aa = os.path.join(dir_path, 'temp.png')
# print(aa)
# img_open = Image.open(aa)
# img_open_resize = img_open.resize((w_box,h_box))
# print(img_open)
# img = ImageTk.PhotoImage(image=img_open_resize)
# print(img)
# label_show.config(image=img,width=w_box, height=h_box)
# label_show.image =img
e = tk.Entry(window, width=40 )
e.place(x=10, y=20)
var1 = tk.StringVar()
b = tk.Button(window, text=' Open folder ', width=10, command=select_path)
b.place(x=310, y=16)
ybar = Scrollbar(window, orient="vertical")
ybar.place(x=420, y=49, height=329)
datagrid = Treeview(window, height=15, show='headings', column=('no', 'filename', 'filesize'), yscrollcommand=ybar.set)
ybar['command'] = datagrid.yview
datagrid.heading('no', text=' order ')
datagrid.heading('filename', text=' file name ')
datagrid.heading('filesize', text=' file size ')
datagrid.column('no', width=30, minwidth=30, anchor=CENTER)
datagrid.column('filename', width=300, minwidth=280, anchor=CENTER)
datagrid.column('filesize', width=80, minwidth=80, anchor=CENTER)
datagrid.place(x=10, y=50)
datagrid.bind('<<TreeviewSelect>>',select)
label_show = tk.Label(window,borderwidth=1,bg='black',width=60,height=18)
label_show.place(x=10,y=380)
def preSel():
preItem = datagrid.prev(datagrid.selection())
if preItem:
datagrid.selection_set(preItem)
else:
print(' It is already the first record ')
preButton = tk.Button(window,text=' Previous ',width=10, command=preSel)
preButton.place(x=20, y=700)
def nextSel():
nextItem = datagrid.next(datagrid.selection())
if nextItem:
datagrid.selection_set(nextItem)
else:
print(' This is the last record ')
nextButton = tk.Button(window,text=' Next ',width=10, command=nextSel)
nextButton.place(x=120, y=700)
def save():
selectItem = datagrid.item(datagrid.selection())['values']
filename = selectItem[1]
SavePic(dir_path, filename)
saveButton = tk.Button(window,text=' Save the picture ',width=10,command=save)
saveButton.place(x=220, y=700)
def deletePic(files_dir_path, filename):
filePath = os.path.join(files_dir_path, filename)
print(filePath)
if os.path.isfile(filePath):
os.remove(filePath)
print(' Delete successful ')
else:
print(' file does not exist ')
def delete():
selectItem = datagrid.item(datagrid.selection())['values']
filename = selectItem[1]
deletePic(dir_path, filename)
datagrid.delete(datagrid.selection())
delButton = tk.Button(window,text=' Delete pictures ',width=10, command=delete)
delButton.place(x=320, y=700)
window.mainloop()
边栏推荐
- doak-cms 文章管理系统 推荐
- jwt
- It's 2022, and you still don't know what performance testing is?
- Groovy之高级用法
- 14 bs对象.节点名称.name attrs string 获取节点名称 属性 内容
- Migrate Oracle database from windows system to Linux Oracle RAC cluster environment (2) -- convert database to cluster mode
- internship:svn的使用
- 一线城市软件测试工资——你拖后腿了吗
- Of the seven levels of software testers, it is said that only 1% can achieve level 7
- yarn : 无法加载文件 C:\Users\xxx\AppData\Roaming\npm\yarn.ps1,因为在此系统上禁止运行脚本
猜你喜欢

left join on和 join on的区别

14 BS object Node name Name attrs string get node name attribute content

分布式事务解决方案和代码落地

PyTorch学习笔记(七)------------------ Vision Transformer

UnityShader入门精要——表面着色器

Leetcode 210: curriculum II (topological sorting)

random list随机生成不重复数

Once beego failed to find bee after passing the go get command Exe's pit

数组-一口气冲完快慢指针

高数 | 精通中值定理 解题套路汇总
随机推荐
AOSP ~ default attribute value
Migrate Oracle database from windows system to Linux Oracle RAC cluster environment (4) -- modify the scanip of Oracle11g RAC cluster
Computing service network: a systematic revolution of multi integration
算力服务网络:一场多元融合的系统革命
微信小程序获取扫描二维码后携带的参数
Charles packet capturing tool
Summary of stack frame in arm assembly
internship:svn的使用
背了八股文,六月赢麻了……
Rod and Schwartz cooperated with ZhongGuanCun pan Lianyuan Institute to carry out 6G technology research and early verification
計網 | 【四 網絡層】知識點及例題
PSQL column to row
ProcessOn制作ER过程(自定义)
Migrate Oracle database from windows system to Linux Oracle RAC cluster environment (1) -- migrate data to node 1
Transformers Roberta如何添加tokens
分布式事务解决方案和代码落地
运行时修改Universal Render Data
Can automate - 10k, can automate - 20K, do you understand automated testing?
After reciting the eight part essay, I won the hemp in June
Software testing weekly (issue 77): giving up once will breed the habit of giving up, and the problems that could have been solved will become insoluble.