WeChatMsg/app/Ui/decrypt/decrypt.py

158 lines
4.6 KiB
Python
Raw Normal View History

2023-01-11 13:04:19 +08:00
# -*- coding: utf-8 -*-
"""
@File : decrypt.py
@Author : Shuaikang Zhou
@Time : 2023/1/5 18:13
@IDE : Pycharm
@Version : Python3.10
2023-02-02 00:26:44 +08:00
@comment : ··· 解密数据库导出原始数据库文件
2023-01-11 13:04:19 +08:00
"""
import hashlib
import time
2023-03-31 11:15:44 +08:00
import xml.etree.ElementTree as ET
2023-01-11 13:04:19 +08:00
2023-03-31 11:15:44 +08:00
from PyQt5.QtCore import *
2023-01-11 13:04:19 +08:00
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
2023-03-31 11:15:44 +08:00
2023-01-11 13:04:19 +08:00
from . import decryptUi
from ...DataBase import data
class DecryptControl(QWidget, decryptUi.Ui_Dialog):
DecryptSignal = pyqtSignal(str)
registerSignal = pyqtSignal(str)
def __init__(self, parent=None):
super(DecryptControl, self).__init__(parent)
self.setupUi(self)
self.setWindowTitle('解密')
2023-10-29 23:15:46 +08:00
self.setWindowIcon(QIcon('./app/data/icons/logo.svg'))
2023-01-11 13:04:19 +08:00
self.btn_db.clicked.connect(self.get_db)
self.btn_xml.clicked.connect(self.get_xml)
self.pushButton_3.clicked.connect(self.decrypt)
2023-11-03 23:24:23 +08:00
self.xml_path: str = None
self.db_path: str = None
2023-01-11 13:04:19 +08:00
def db_exist(self):
2023-11-03 23:24:23 +08:00
if data.is_db_exist():
2023-01-11 13:04:19 +08:00
self.btnEnterClicked()
self.close()
def get_xml(self):
self.xml_path, _ = QFileDialog.getOpenFileName(self, 'Open file', r'..', "Xml files (*.xml)")
if self.xml_path:
self.label_xml.setText('xml已就绪')
key = self.parser_xml()
self.label_key.setText(f'数据库密钥:{key}')
return self.xml_path
return False
def get_db(self):
self.db_path, _ = QFileDialog.getOpenFileName(self, 'Open file', r'..', "Database files (*.db)")
if self.db_path:
2023-11-03 23:24:23 +08:00
if self.db_path.isascii():
self.label_db.setText('数据库已就绪')
return self.db_path
else:
self.label_db.setText('数据库未就绪')
QMessageBox.critical(self, "错误", "db文件请不要带有中文路径\n可以放在D:\\\\data 目录下")
self.db_path = ''
2023-01-11 13:04:19 +08:00
return False
def decrypt(self):
if not (self.xml_path and self.db_path):
QMessageBox.critical(self, "错误", "请把两个文件加载进来")
return
key = self.parser_xml()
self.label_key.setText(f'数据库密钥:{key}')
self.thread1 = MyThread()
self.thread1.signal.connect(self.progressBar_view)
self.thread1.start()
self.thread2 = DecryptThread(self.db_path, key)
self.thread2.signal.connect(self.progressBar_view)
self.thread2.start()
def parser_xml(self):
if not self.xml_path:
return False
pid = self.pid(self.xml_path)
if not pid:
return False
key = self.key(pid)
return key
def pid(self, xml_path):
tree = ET.parse(xml_path)
# 根节点
root = tree.getroot()
# 标签名
for stu in root:
if stu.attrib["name"] == '_auth_uin':
return stu.attrib['value']
return False
def key(self, uin, IMEI='1234567890ABCDEF'):
m = hashlib.md5()
m.update(bytes((IMEI + uin).encode('utf-8')))
psw = m.hexdigest()
return psw[:7]
def btnEnterClicked(self):
2023-10-29 23:15:46 +08:00
# print("enter clicked")
2023-01-11 13:04:19 +08:00
# 中间可以添加处理逻辑
self.DecryptSignal.emit('ok')
2023-10-29 23:15:46 +08:00
self.close()
2023-01-11 13:04:19 +08:00
def progressBar_view(self, value):
"""
进度条显示
:param value: 进度0-100
:return: None
"""
self.progressBar.setProperty('value', value)
2023-11-03 23:24:23 +08:00
if value == '99':
QMessageBox.information(self, "温馨提示", "我知道你很急\n但你先别急")
2023-01-11 13:04:19 +08:00
if value == '100':
QMessageBox.information(self, "解密成功", "请退出该界面",
QMessageBox.Yes)
self.btnExitClicked()
2023-10-29 23:15:46 +08:00
data.init_database()
2023-01-11 13:04:19 +08:00
def btnExitClicked(self):
2023-10-29 23:15:46 +08:00
# print("Exit clicked")
self.DecryptSignal.emit('ok')
self.close()
2023-01-11 13:04:19 +08:00
class DecryptThread(QThread):
signal = pyqtSignal(str)
def __init__(self, db_path, key):
super(DecryptThread, self).__init__()
self.db_path = db_path
self.key = key
self.textBrowser = None
def __del__(self):
pass
def run(self):
data.decrypt(self.db_path, self.key)
self.signal.emit('100')
class MyThread(QThread):
signal = pyqtSignal(str)
def __init__(self):
super(MyThread, self).__init__()
def __del__(self):
pass
def run(self):
for i in range(100):
self.signal.emit(str(i))
time.sleep(0.1)