当前位置:网站首页>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()
边栏推荐
- 李宏毅《机器学习》丨6. Convolutional Neural Network(卷积神经网络)
- npm包发布详细教程
- MySQL command backup
- Migrate Oracle database from windows system to Linux Oracle RAC cluster environment (4) -- modify the scanip of Oracle11g RAC cluster
- 使用ShaderGraph制作边缘融合粒子Shader的启示
- 背了八股文,六月赢麻了……
- qt打包exe文件,解决“无法定位程序输入点_ZdaPvj于动态链接库Qt5Cored.dll”
- Is it out of reach to enter Ali as a tester? Here may be the answer you want
- Modifying universal render data at runtime
- jwt
猜你喜欢

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

When they are in private, they have a sense of propriety

Refresh mechanism of vie

I've been doing software testing for two years. I'd like to give some advice to girls who are still hesitating

Pit entry machine learning: I. Introduction

Leetcode 210: curriculum II (topological sorting)

How transformers Roberta adds tokens

记一次beego通过go get命令后找不到bee.exe的坑

电脑端微信用户图片DAT格式解码为图片(TK版)

计网 | 【四 网络层】知识点及例题
随机推荐
202112-2 序列查询新解
vie的刷新机制
运行时修改Universal Render Data
折叠屏将成国产手机分食苹果市场的重要武器
如何卸载cuda
Modifying universal render data at runtime
Is it out of reach to enter Ali as a tester? Here may be the answer you want
ProcessOn制作ER过程(自定义)
ACL access control of squid proxy server
[STL source code analysis] configurator (to be supplemented)
Overview of AOSP ~ WiFi architecture
計網 | 【四 網絡層】知識點及例題
Computing service network: a systematic revolution of multi integration
Unity存档系统——Json格式的文件
Groovy之高级用法
Can the polardb database be connected to the data source through MySQL
random list随机生成不重复数
PyTorch学习笔记(七)------------------ Vision Transformer
UnityShader入门精要——表面着色器
Advanced usage of groovy