132 lines
4.0 KiB
Python
132 lines
4.0 KiB
Python
"""
|
|
企业微信聊天记录导出 - 一键工具
|
|
自动完成: 检测进程 → 提取密钥 → 解密数据库 → 导出CSV
|
|
|
|
用法:
|
|
python wxwork_export_all.py [--output <输出目录>]
|
|
"""
|
|
|
|
import json
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
|
|
# 模块路径
|
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
sys.path.insert(0, BASE_DIR)
|
|
|
|
|
|
def check_wxwork_running():
|
|
"""检查企业微信是否在运行"""
|
|
try:
|
|
result = subprocess.run(
|
|
["tasklist", "/FI", "IMAGENAME eq WXWork.exe"],
|
|
capture_output=True, text=True, timeout=10
|
|
)
|
|
if "WXWork.exe" in result.stdout:
|
|
return True
|
|
# 也检查其他可能的进程名
|
|
for name in ["WXWorkMain.exe", "WXWorkWeb.exe", "WXWork.exe"]:
|
|
result = subprocess.run(
|
|
["tasklist", "/FI", f"IMAGENAME eq {name}"],
|
|
capture_output=True, text=True, timeout=10
|
|
)
|
|
if name in result.stdout:
|
|
return True
|
|
return False
|
|
except Exception:
|
|
return False
|
|
|
|
|
|
def main():
|
|
print("=" * 60)
|
|
print(" 企业微信聊天记录导出工具 v1.0")
|
|
print("=" * 60)
|
|
|
|
# 步骤 1: 检查企业微信是否运行
|
|
print("\n[步骤 1/4] 检查企业微信进程...")
|
|
if not check_wxwork_running():
|
|
print(" [提示] 企业微信未运行!")
|
|
print(" " + "=" * 50)
|
|
print(" 请按以下步骤操作:")
|
|
print(" 1. 启动企业微信 (WXWork)")
|
|
print(" 2. 登录你的账号")
|
|
print(" 3. 保持企业微信在运行状态")
|
|
print(" 4. 然后按 Enter 键继续...")
|
|
print(" " + "=" * 50)
|
|
try:
|
|
input()
|
|
except EOFError:
|
|
pass
|
|
|
|
# 再次检查
|
|
if not check_wxwork_running():
|
|
print("\n[-] 仍未检测到企业微信进程, 请确认已启动并登录")
|
|
return 1
|
|
|
|
print(" [OK] 企业微信正在运行")
|
|
|
|
# 步骤 2: 提取密钥
|
|
print("\n[步骤 2/4] 从企业微信进程内存中提取密钥...")
|
|
from wxwork_find_key import extract_wxwork_key
|
|
result = extract_wxwork_key()
|
|
|
|
if result is None:
|
|
print("\n[-] 密钥提取失败!")
|
|
print(" 请尝试:")
|
|
print(" 1. 以管理员身份运行此脚本")
|
|
print(" 2. 确认企业微信已完全启动 (不是最小化到托盘)")
|
|
return 1
|
|
|
|
key_bytes, pid, key_info = result
|
|
key_hex = key_bytes.hex()
|
|
print(f"\n [OK] 密钥提取成功!")
|
|
print(f" Raw Key: {key_hex}")
|
|
|
|
# 保存密钥
|
|
keys_file = os.path.join(BASE_DIR, "wxwork_keys.json")
|
|
with open(keys_file, "w") as f:
|
|
json.dump({"global_key": key_hex, "pid": pid, "source": key_info}, f, indent=2)
|
|
print(f" 密钥已保存到: {keys_file}")
|
|
|
|
# 步骤 3: 解密数据库
|
|
print("\n[步骤 3/4] 解密数据库...")
|
|
from wxwork_export import decrypt_all_databases
|
|
|
|
db_base = os.path.join(os.path.expanduser("~"), "Documents", "WXWork")
|
|
out_dir = os.path.join(BASE_DIR, "wxwork_export")
|
|
|
|
decrypted_dbs = decrypt_all_databases(db_base, os.path.join(out_dir, "decrypted"), key_bytes)
|
|
|
|
if not decrypted_dbs:
|
|
print("\n[-] 没有成功解密的数据库!")
|
|
return 1
|
|
|
|
print(f"\n [OK] 成功解密 {len(decrypted_dbs)} 个数据库文件")
|
|
|
|
# 步骤 4: 导出聊天记录
|
|
print("\n[步骤 4/4] 导出聊天记录为 CSV...")
|
|
from wxwork_export import export_messages_to_csv
|
|
|
|
csv_path = export_messages_to_csv(decrypted_dbs, out_dir)
|
|
|
|
if csv_path:
|
|
print("\n" + "=" * 60)
|
|
print(" 导出完成!")
|
|
print("=" * 60)
|
|
print(f"\n 聊天记录文件: {csv_path}")
|
|
print(f" 输出目录: {out_dir}")
|
|
print("\n 提示: 打开CSV文件时如果中文乱码,")
|
|
print(" 请使用 Excel 的 '数据 > 从文本/CSV导入',")
|
|
print(" 编码选择 UTF-8 (带 BOM)。")
|
|
return 0
|
|
else:
|
|
print("\n[-] 导出失败")
|
|
return 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|