当前位置:网站首页>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()
边栏推荐
- 打新债是不是骗局 开户是安全的吗
- JS regular matching numbers, upper and lower case letters, underscores, midlines and dots [easy to understand]
- 算力服务网络:一场多元融合的系统革命
- js正则匹配数字、大小写字母、下划线、中线和点[通俗易懂]
- Can automate - 10k, can automate - 20K, do you understand automated testing?
- Intranet learning notes (7)
- 调用系统函数安全方案
- 把 Oracle 数据库从 Windows 系统迁移到 Linux Oracle Rac 集群环境(3)—— 把数据库设置为归档模式
- Network planning | [four network layers] knowledge points and examples
- 当他们在私域里,掌握了分寸感
猜你喜欢

【STL源码剖析】STL六大组件功能与运用(目录)

Distributed transaction solutions and code implementation

Rod and Schwartz cooperated with ZhongGuanCun pan Lianyuan Institute to carry out 6G technology research and early verification

折叠屏将成国产手机分食苹果市场的重要武器

Redis

random list随机生成不重复数

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

QT package the EXE file to solve the problem that "the program input point \u zdapvj cannot be located in the dynamic link library qt5cored.dll"

保险也能拼购?个人可以凑够人数组团购买医疗保险的4大风险
![Network planning | [four network layers] knowledge points and examples](/img/c3/d7f382409e99eeee4dcf4f50f1a259.png)
Network planning | [four network layers] knowledge points and examples
随机推荐
AOSP ~ default attribute value
It's 2022, and you still don't know what performance testing is?
消息称一加将很快更新TWS耳塞、智能手表和手环产品线
PE file infrastructure sorting
Uncaught Error: [About] is not a <Route> component. All component children of <Routes> must be a <Ro
都2022年了,你还不了解什么是性能测试?
vie的刷新机制
Processon producer process (customized)
高速缓存Cache详解(西电考研向)
ACL access control of squid proxy server
Leecode learning notes - the shortest path for a robot to reach its destination
ACM. HJ75 公共子串计算 ●●
Summary of knowledge points of computer level III (database) test preparation topics
使用ShaderGraph制作边缘融合粒子Shader的启示
Insurance can also be bought together? Four risks that individuals can pool enough people to buy Medical Insurance in groups
Of the seven levels of software testers, it is said that only 1% can achieve level 7
Transformers Roberta如何添加tokens
ARM汇编中的栈桢小结
internship:svn的使用
Advanced mathematics | proficient in mean value theorem problem solving routines summary