当前位置:网站首页>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()
边栏推荐
- love
- 3 years of testing experience. I don't even understand what I really need on my resume. I need 20K to open my mouth?
- NPM package publishing tutorial
- Charles 抓包工具
- 怎么开户打新债 开户是安全的吗
- ProcessOn制作ER过程(自定义)
- It is said that Yijia will soon update the product line of TWS earplugs, smart watches and bracelets
- automated testing
- ida中交叉引用的解析
- UnityShader入门精要——PBS基于物理的渲染
猜你喜欢

【STL源码剖析】配置器(待补充)

It is said that Yijia will soon update the product line of TWS earplugs, smart watches and bracelets

DSPACE的性能渲染问题

UnityShader入门精要——PBS基于物理的渲染

Transformers Roberta如何添加tokens

计网 | 【四 网络层】知识点及例题

automated testing

LeetCode 210:课程表 II (拓扑排序)

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

ProcessOn制作ER过程(自定义)
随机推荐
AOSP ~ default attribute value
Mall project pc--- product details page
E - Average and Median(二分)
LINQ 查询(3)
Distributed transaction solutions and code implementation
ProcessOn制作ER过程(自定义)
Jetson Nano 从入门到实战(案例:Opencv配置、人脸检测、二维码检测)
jwt
调用系统函数安全方案
【STL源码剖析】配置器(待补充)
Uncaught Error: [About] is not a <Route> component. All component children of <Routes> must be a <Ro
ACL access control of squid proxy server
AOSP ~ 默认属性值
把 Oracle 数据库从 Windows 系统迁移到 Linux Oracle Rac 集群环境(1)——迁移数据到节点1
Detailed explanation of cache (for the postgraduate entrance examination of XD)
automated testing
高数 | 精通中值定理 解题套路汇总
分布式事务解决方案和代码落地
Call system function security scheme
PyTorch学习笔记(七)------------------ Vision Transformer