Skip to content

Commit

Permalink
完善解密错误提示
Browse files Browse the repository at this point in the history
  • Loading branch information
LC044 committed Dec 5, 2023
1 parent 6d6b355 commit 346dfe5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
8 changes: 5 additions & 3 deletions app/decrypt/decrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from Cryptodome.Cipher import AES

from app.log import log
from app.log import log, logger

# from Crypto.Cipher import AES # 如果上面的导入失败,可以尝试使用这个

Expand All @@ -24,7 +24,8 @@ def decrypt(key: str, db_path, out_path):
if not os.path.exists(os.path.dirname(out_path)):
return f"[-] out_path:'{out_path}' File not found!"
if len(key) != 64:
return f"[-] key:'{key}' Error!"
logger.error(f"[-] key:'{key}' Error!")
return -1
password = bytes.fromhex(key.strip())
with open(db_path, "rb") as file:
blist = file.read()
Expand All @@ -39,7 +40,8 @@ def decrypt(key: str, db_path, out_path):
hash_mac.update(b'\x01\x00\x00\x00')

if hash_mac.digest() != first[-32:-12]:
return f"[-] Password Error! (key:'{key}'; db_path:'{db_path}'; out_path:'{out_path}' )"
logger.error(f"[-] Password Error! (key:'{key}'; db_path:'{db_path}'; out_path:'{out_path}' )")
return -1

newblist = [blist[i:i + DEFAULT_PAGESIZE] for i in range(DEFAULT_PAGESIZE, len(blist), DEFAULT_PAGESIZE)]

Expand Down
18 changes: 15 additions & 3 deletions app/ui_pc/tool/pc_decrypt/pc_decrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,17 @@ def decrypt(self):
if not os.path.exists(db_dir):
QMessageBox.critical(self, "错误", "文件夹选择错误\n一般以wxid_xxx结尾")
return
if self.info.get('key') == 'none':
QMessageBox.critical(self, "错误", "密钥错误\n请检查微信版本是否为最新")
self.label_tip.setVisible(True)
self.label_tip.setText('点我之后没有反应那就多等儿吧,不要再点了')
self.thread2 = DecryptThread(db_dir, self.info['key'])
self.thread2.maxNumSignal.connect(self.setProgressBarMaxNum)
self.thread2.signal.connect(self.progressBar_view)
self.thread2.okSignal.connect(self.btnExitClicked)
self.thread2.errorSignal.connect(
lambda x: QMessageBox.critical(self, "错误", "密钥错误\n请检查微信版本是否为最新")
)
self.thread2.start()

def btnEnterClicked(self):
Expand Down Expand Up @@ -171,11 +176,14 @@ def btnExitClicked(self):
# 目标数据库文件
target_database = "app/DataBase/Msg/MSG.db"
# 源数据库文件列表
source_databases = [f"app/DataBase/Msg/MSG{i}.db" for i in range(1,20)]
source_databases = [f"app/DataBase/Msg/MSG{i}.db" for i in range(1, 20)]
import shutil
shutil.copy("app/DataBase/Msg/MSG0.db", target_database) # 使用一个数据库文件作为模板
# 合并数据库
merge_databases(source_databases, target_database)
try:
merge_databases(source_databases, target_database)
except FileNotFoundError:
QMessageBox.critical(self, "错误", "数据库不存在\n请检查微信版本是否为最新")
self.DecryptSignal.emit(True)
self.close()

Expand All @@ -184,6 +192,7 @@ class DecryptThread(QThread):
signal = pyqtSignal(str)
maxNumSignal = pyqtSignal(int)
okSignal = pyqtSignal(str)
errorSignal = pyqtSignal(bool)

def __init__(self, db_path, key):
super(DecryptThread, self).__init__()
Expand All @@ -206,13 +215,16 @@ def run(self):
for root, dirs, files in os.walk(self.db_path):
for file in files:
if '.db' == file[-3:]:
if 'xInfo.db' == file:
continue
inpath = os.path.join(root, file)
# print(inpath)
output_path = os.path.join(output_dir, file)
tasks.append([self.key, inpath, output_path])
self.maxNumSignal.emit(len(tasks))
for i, task in enumerate(tasks):
decrypt.decrypt(*task)
if decrypt.decrypt(*task) == -1:
self.errorSignal.emit(True)
self.signal.emit(str(i))
# print(self.db_path)
self.okSignal.emit('ok')
Expand Down
2 changes: 1 addition & 1 deletion requirements_pc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ silk-python
pyaudio
fuzzywuzzy
python-Levenshtein
pillow
pillow==9.5.0
requests
flask==3.0.0
pyecharts==2.0.1
Expand Down

0 comments on commit 346dfe5

Please sign in to comment.