当前位置:网站首页>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()
边栏推荐
- Getting started with unityshader - Surface Shader
- 爱
- Call system function security scheme
- It's 2022, and you still don't know what performance testing is?
- F - Spices(线性基)
- PE文件基础结构梳理
- Charles 抓包工具
- Is it out of reach to enter Ali as a tester? Here may be the answer you want
- 【STL源码剖析】配置器(待补充)
- Solution of separating matlab main window and editor window into two interfaces
猜你喜欢

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.

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

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

自动化测试

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

Advanced mathematics | proficient in mean value theorem problem solving routines summary

Leecode learning notes - the shortest path for a robot to reach its destination

Intranet learning notes (7)

Application of TSDB in civil aircraft industry

Sumati gamefi ecological overview, element design in the magical world
随机推荐
PE文件基础结构梳理
Modifying universal render data at runtime
leecode学习笔记-机器人走到终点的最短路径
GO同步等待组
Transformers Roberta如何添加tokens
调用系统函数安全方案
ACL access control of squid proxy server
202112-2 序列查询新解
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.
ARM汇编中的栈桢小结
Once beego failed to find bee after passing the go get command Exe's pit
vim的Dirvish中文文档
Planification du réseau | [quatre couches de réseau] points de connaissance et exemples
14 bs对象.节点名称.name attrs string 获取节点名称 属性 内容
Software testing salary in first tier cities - are you dragging your feet
Tell you about mvcc sequel
Error log format and precautions
The Oracle 11g RAC cluster database cannot be started due to directory permission errors
DSPACE的性能渲染问题
Jetson Nano 从入门到实战(案例:Opencv配置、人脸检测、二维码检测)