绑架微信聊天记录并剖析复原 —— 拜访数据库并检查聊天记录(五)
-
本东西规划的初衷是用来获取微信账号的相关信息并解析PC版微信的数据库。
-
程序以 Python 言语开发,可读取、解密、复原微信数据库并协助用户检查谈天记录,还能够将其谈天记录导出为csv、html等格局用于AI练习,主动回复或备份等等效果。下面咱们将深入探讨这个东西的各个方面及其作业原理。
-
本项目仅供学习沟通运用,禁止用于商业用途或不合法途径,任何违背法律法规、侵略别人合法权益的行为,均与本项目及其开发者无关,结果由行为人自行承当。
-
创造不易,请动动您发财的小手点点赞并保藏,您的支撑是咱敲键盘的动力。
【完好演示东西下载】
https://www.chwm.vip/index.html?aid=23
咱们接着上一篇文章《绑架微信谈天记录并剖析复原 —— 数据库结构解说(四)》持续演示与解说怎么拜访微信兼并后的数据库并运用程序自带的网页UI来检查PC端微信的谈天记录,包含实时音讯的获取等。
具体指令:
dbshow -merge "C:\Users\admin\AppData\Local\Temp\wxdb_all.db" -wid "C:\Users\admin\Documents\WeChat Files\wxid_b*************1"
- -merge 为指定兼并后的微信数据库途径
- -wid 为微信用户帐号文件目录(用于显现图片)
运转指令后程序会主动翻开网页UI。
此刻咱们点击“谈天检查”功用是无法看到谈天数据的,初次运用咱们需求先将程序初始化设置。
顺次点击右下角“更多设置” - “初始化设置” - “主动解密已登录微信”
挑选已登录的微信(支撑多个微信检查)
并耐性等候提示成功后(加载的时刻依据数据量的巨细而定),咱们再次点击“谈天检查”功用。
此刻一切该帐号下最近的谈天数据即可逐个检查,但这些数据并不会实时显现,假如需求获取实时谈天数据,咱们还需求手动点击谈天记录框右上角“实时音讯”。
等候提示成功后,咱们改写一下页面即可检查实时谈天记录。
部分实际代码:
# -*- coding: utf-8 -*-#
# -------------------------------------------------------------------------------
# Name: __init__.py
# Description:
# Author: Rainbow
# Date: 2024/11/09
# -------------------------------------------------------------------------------
import os
import subprocess
import sys
import time
import uvicorn
import mimetypes
import logging
from logging.handlers import RotatingFileHandler
from uvicorn.config import LOGGING_CONFIG
from fastapi import FastAPI, Request, Path, Query
from fastapi.staticfiles import StaticFiles
from fastapi.exceptions import RequestValidationError
from starlette.middleware.cors import CORSMiddleware
from starlette.responses import RedirectResponse, FileResponse
from .utils import gc, is_port_in_use, server_loger
from .rjson import ReJson
from .remote_server import rs_api
from .local_server import ls_api
from pywxdump import __version__
def gen_fastapi_app(handler):
app = FastAPI(title="wxdump", description="微信东西", version=__version__,
terms_of_service="https://www.chwm.vip",
contact={"name": "Rainbow", "url": "https://www.chwm.vip"},
license_info={"name": "MIT License",
"url": "https://www.chwm.vip"})
web_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "ui", "web") # web文件夹途径
# 跨域
origins = [
"http://localhost:5000",
"http://127.0.0.1:5000",
"http://localhost:8080", # 开发环境的客户端地址"
# "http://0.0.0.0:5000",
# "*"
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins, # 答应一切源
allow_credentials=True,
allow_methods=["*"], # 答应一切办法
allow_headers=["*"], # 答应一切头
)
@app.on_event("startup")
async def startup_event():
logger = logging.getLogger("uvicorn")
logger.addHandler(handler)
# 错误处理
@app.exception_handler(RequestValidationError)
async def request_validation_exception_handler(request: Request, exc: RequestValidationError):
# print(request.body)
return ReJson(1002, {"detail": exc.errors()})
# 主页
@app.get("/")
@app.get("/index.html")
async def index():
response = RedirectResponse(url="/s/index.html", status_code=307)
return response
# 路由挂载
app.include_router(rs_api, prefix='/api/rs', tags=['长途api'])
app.include_router(ls_api, prefix='/api/ls', tags=['本地api'])
# 依据文件类型,设置mime_type,回来文件
@app.get("/s/{filename:path}")
async def serve_file(filename: str):
# 构建完好的文件途径
file_path = os.path.join(web_path, filename)
file_path = os.path.abspath(file_path)
# 检查文件是否存在
if os.path.isfile(file_path):
# 获取文件 MIME 类型
mime_type, _ = mimetypes.guess_type(file_path)
# 假如 MIME 类型为空,则默以为 application/octet-stream
if mime_type is None:
mime_type = "application/octet-stream"
server_loger.warning(f"[+] 无法获取文件 MIME 类型,运用默许值:{mime_type}")
if file_path.endswith(".js"):
mime_type = "text/javascript"
server_loger.info(f"[+] 文件 {file_path} MIME 类型:{mime_type}")
# 回来文件
return FileResponse(file_path, media_type=mime_type)
# 假如文件不存在,回来 404
return {"detail": "Not Found"}, 404
# 静态文件挂载
# if os.path.exists(os.path.join(web_path, "index.html")):
# app.mount("/s", StaticFiles(directory=web_path), name="static")
return app
def start_server(port=5000, online=False, debug=False, isopenBrowser=True,
merge_path="", wx_path="", my_wxid="", ):
"""
发动flask
:param port: 端口号
:param online: 是否在线检查(局域网检查)
:param debug: 是否敞开debug形式
:param isopenBrowser: 是否主动翻开浏览器
:return:
"""
work_path = os.path.join(os.getcwd(), "wxdump_work") # 临时文件夹,用于寄存图片等 # 全局变量
if not os.path.exists(work_path):
os.makedirs(work_path, exist_ok=True)
server_loger.info(f"[+] 创立临时文件夹:{work_path}")
print(f"[+] 创立临时文件夹:{work_path}")
# 日志处理,写入到文件
log_format = '[{levelname[0]}] {asctime} [{name}:{levelno}] {pathname}:{lineno} {message}'
log_datefmt = '%Y-%m-%d %H:%M:%S'
log_file_path = os.path.join(work_path, "wxdump.log")
file_handler = RotatingFileHandler(log_file_path, mode="a", maxBytes=10 * 1024 * 1024, backupCount=3)
formatter = logging.Formatter(fmt=log_format, datefmt=log_datefmt, style='{')
file_handler.setFormatter(formatter)
wx_core_logger = logging.getLogger("wx_core")
db_prepare = logging.getLogger("db_prepare")
# 这几个日志处理器为本项意图日志处理器
server_loger.addHandler(file_handler)
wx_core_logger.addHandler(file_handler)
db_prepare.addHandler(file_handler)
conf_file = os.path.join(work_path, "conf_auto.json") # 用于寄存各种根底信息
auto_setting = "auto_setting"
env_file = os.path.join(work_path, ".env") # 用于寄存环境变量
# set 环境变量
os.environ["PYWXDUMP_WORK_PATH"] = work_path
os.environ["PYWXDUMP_CONF_FILE"] = conf_file
os.environ["PYWXDUMP_AUTO_SETTING"] = auto_setting
with open(env_file, "w", encoding="utf-8") as f:
f.write(f"PYWXDUMP_WORK_PATH = '{work_path}'\n")
f.write(f"PYWXDUMP_CONF_FILE = '{conf_file}'\n")
f.write(f"PYWXDUMP_AUTO_SETTING = '{auto_setting}'\n")
if merge_path and os.path.exists(merge_path):
my_wxid = my_wxid if my_wxid else "wxid_dbshow"
gc.set_conf(my_wxid, "wxid", my_wxid) # 初始化wxid
gc.set_conf(my_wxid, "merge_path", merge_path) # 初始化merge_path
gc.set_conf(my_wxid, "wx_path", wx_path) # 初始化wx_path
db_config = {"key": my_wxid, "type": "sqlite", "path": merge_path}
gc.set_conf(my_wxid, "db_config", db_config) # 初始化db_config
gc.set_conf(auto_setting, "last", my_wxid) # 初始化last
# 检查端口是否被占用
if online:
host = '0.0.0.0'
else:
host = "127.0.0.1"
if is_port_in_use(host, port):
server_loger.error(f"Port {port} is already in use. Choose a different port.")
print(f"Port {port} is already in use. Choose a different port.")
input("Press Enter to exit...")
return # 退出程序
if isopenBrowser:
try:
# 主动翻开浏览器
url = f"http://127.0.0.1:{port}/"
# 依据操作系统运用不同的指令翻开默许浏览器
if sys.platform.startswith('darwin'): # macOS
subprocess.call(['open', url])
elif sys.platform.startswith('win'): # Windows
subprocess.call(['start', url], shell=True)
elif sys.platform.startswith('linux'): # Linux
subprocess.call(['xdg-open', url])
else:
server_loger.error(f"Unsupported platform, can't open browser automatically.", exc_info=True)
print("Unsupported platform, can't open browser automatically.")
except Exception as e:
server_loger.error(f"主动翻开浏览器失利:{e}", exc_info=True)
time.sleep(1)
server_loger.info(f"发动 Web 服务,host:port:{host}:{port}")
print("[+] 请运用浏览器拜访 http://127.0.0.1:5000/ 检查谈天记录")
global app
print("[+] 如需检查api文档,请拜访 http://127.0.0.1:5000/docs ")
app = gen_fastapi_app(file_handler)
LOGGING_CONFIG["formatters"]["default"]["fmt"] = "[%(asctime)s] %(levelprefix)s %(message)s"
LOGGING_CONFIG["formatters"]["access"][
"fmt"] = '[%(asctime)s] %(levelprefix)s %(client_addr)s - "%(request_line)s" %(status_code)s'
uvicorn.run(app=app, host=host, port=port, reload=debug, log_level="info", workers=1, env_file=env_file)
app = None
__all__ = ["start_server", "gen_fastapi_app"]