Files
botAffilate/serverPython/zalo_find_group.py
T

65 lines
3.0 KiB
Python

import os
import subprocess
import logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def run_adb_command(command: str):
"""Chạy lệnh ADB shell và trả về kết quả"""
full_cmd = f"adb -s 192.168.1.193:5555 shell {command}"
try:
result = subprocess.run(full_cmd, shell=True, check=True, capture_output=True, text=True)
return result.stdout.strip()
except subprocess.CalledProcessError as e:
return None
def find_group():
target_id = "7173734528992370154"
zalo_db_path = "/data/data/com.zing.zalo/databases"
logging.info(f"Đang tìm kiếm Group ID {target_id} trong {zalo_db_path}...")
# Dùng lệnh find để tìm kiếm đệ quy
output = run_adb_command(f"su -c 'find {zalo_db_path} -name \"*{target_id}*\"'")
if output:
logging.info("TÌM THẤY! Kết quả:")
logging.info(output)
# Nếu tìm thấy DB, thử trích xuất về
for path in output.split('\n'):
if path.endswith('.db'):
logging.info(f"Đang kéo DB {path} về...")
filename = os.path.basename(path)
run_adb_command(f"su -c 'cp {path} /sdcard/temp_{filename}'")
run_adb_command(f"su -c 'chmod 666 /sdcard/temp_{filename}'")
subprocess.run(f"adb -s 192.168.1.193:5555 pull /sdcard/temp_{filename} .", shell=True)
run_adb_command(f"su -c 'rm /sdcard/temp_{filename}'")
logging.info(f"Đã lưu file: {filename}")
break
else:
logging.warning(f"Không tìm thấy file nào chứa {target_id}. Có thể Zalo lưu tin nhắn trong 1 file DB chung.")
# Nếu không tìm thấy file riêng, thử tìm chuỗi ID này bên trong các DB lớn
logging.info("Đang dò tìm chuỗi ID bên trong các file DB chung (quá trình này mất khoảng 1 phút)...")
# Quét các thư mục UID
uid_folders_out = run_adb_command(f"su -c 'ls -l {zalo_db_path}'")
uid_folders = [line.split()[-1] for line in uid_folders_out.split('\n') if line.startswith('d') and line.split()[-1].isdigit()]
for uid in uid_folders:
logging.info(f"Đang quét UID: {uid}...")
# Dùng grep để tìm chuỗi trong file nhị phân
grep_out = run_adb_command(f"su -c 'grep -r -a \"{target_id}\" {zalo_db_path}/{uid}/'")
if grep_out:
logging.info(f"-> PHÁT HIỆN: Chuỗi ID {target_id} tồn tại bên trong các file thuộc UID {uid}!")
# In ra 5 dòng đầu tiên chứa kết quả để phỏng đoán tên file DB
for line in grep_out.split('\n')[:5]:
logging.info(" " + line[:100] + "...")
logging.info("Vui lòng gửi lại cho tôi những dòng log trên để tôi xác định đúng file DB chứa tin nhắn!")
return
if __name__ == "__main__":
find_group()