增加导出加密数据库的方式
This commit is contained in:
1 parent
7dd740d45f
commit
10767f2abe
4 files changed
+113
-65
No files matched your search
@@ -8,4 +8,4 @@
|
||||
from .get_wx_info import read_info, get_wechat_db
|
||||
from .get_bias_addr import BiasAddr
|
||||
from .decryption import batch_decrypt, encrypt, decrypt
|
||||
from .merge_db import merge_msg_db, merge_copy_db, merge_media_msg_db, merge_db
|
||||
from .merge_db import merge_msg_db, merge_copy_db, merge_media_msg_db, merge_db, decrypt_merge
|
||||
@@ -199,7 +199,7 @@ def execute_sql(connection, sql, params=None):
|
||||
return None
|
||||
|
||||
|
||||
def merge_db(db_paths, save_path="merge.db", CreateTime: int = 0):
|
||||
def merge_db(db_paths, save_path="merge.db", CreateTime: int = 0, endCreateTime: int = 0):
|
||||
"""
|
||||
合并数据库 会忽略主键以及重复的行。
|
||||
:param db_paths:
|
||||
@@ -277,3 +277,62 @@ def merge_db(db_paths, save_path="merge.db", CreateTime: int = 0):
|
||||
outdb.commit()
|
||||
outdb.close()
|
||||
return save_path
|
||||
|
||||
|
||||
def decrypt_merge(wx_path, key, outpath="", CreateTime: int = 0) -> (bool, str):
|
||||
"""
|
||||
解密合并数据库 msg.db, microMsg.db, media.db
|
||||
:param wx_path: 微信路径 eg: C:\*******\WeChat Files\wxid_*********
|
||||
:param key: 解密密钥
|
||||
:return: (true,解密后的数据库路径) or (false,错误信息)
|
||||
"""
|
||||
from .decryption import batch_decrypt
|
||||
from .get_wx_info import get_wechat_db
|
||||
|
||||
outpath = outpath if outpath else "decrypt_merge_tmp"
|
||||
merge_save_path = os.path.join(outpath, "merge_all.db")
|
||||
decrypted_path = os.path.join(outpath, "decrypted")
|
||||
|
||||
if not wx_path or not key:
|
||||
return True, "参数错误"
|
||||
|
||||
# 分割wx_path的文件名和父目录
|
||||
msg_dir = os.path.dirname(wx_path)
|
||||
my_wxid = os.path.basename(wx_path)
|
||||
|
||||
# 解密
|
||||
WxDbPath = get_wechat_db('all', msg_dir, wxid=my_wxid, is_logging=False) # 获取微信数据库路径
|
||||
if isinstance(WxDbPath, str): # 如果返回的是字符串,则表示出错
|
||||
return False, WxDbPath
|
||||
wxdbpaths = [path for user_dir in WxDbPath.values() for paths in user_dir.values() for path in paths]
|
||||
if len(wxdbpaths) == 0:
|
||||
return False, "未获取到数据库路径"
|
||||
|
||||
wxdbpaths = [i for i in wxdbpaths if "MicroMsg" in i or "MediaMSG" in i or r"Multi\MSG" in i] # 过滤掉无需解密的数据库
|
||||
|
||||
# 判断out_path是否为空目录
|
||||
if os.path.exists(decrypted_path) and os.listdir(decrypted_path):
|
||||
for root, dirs, files in os.walk(decrypted_path, topdown=False):
|
||||
for name in files:
|
||||
os.remove(os.path.join(root, name))
|
||||
for name in dirs:
|
||||
os.rmdir(os.path.join(root, name))
|
||||
|
||||
if not os.path.exists(decrypted_path):
|
||||
os.makedirs(decrypted_path)
|
||||
|
||||
# 调用 decrypt 函数,并传入参数 # 解密
|
||||
code, ret = batch_decrypt(key, wxdbpaths, decrypted_path, False)
|
||||
if not code:
|
||||
return False, ret
|
||||
|
||||
out_dbs = []
|
||||
for code1, ret1 in ret:
|
||||
if code1:
|
||||
out_dbs.append(ret1[1])
|
||||
|
||||
parpare_merge_db_path = [i for i in out_dbs if "de_MicroMsg" in i or "de_MediaMSG" in i or "de_MSG" in i]
|
||||
|
||||
merge_save_path = merge_db(parpare_merge_db_path, merge_save_path, CreateTime=CreateTime)
|
||||
|
||||
return True, merge_save_path
|
||||
Reference in new issue
Block a user