Files
workphone-sdk/debug_contacts.py

77 lines
3.0 KiB
Python

#!/usr/bin/env python3
"""快速调试:检查联系人/群组/标签/朋友圈问题"""
import frida, json, time, subprocess, re
PHONE_IP = '192.168.110.80'
JS_FILE = '/Users/karuo/Documents/开发/2、私域银行/工作手机/sdk/agent/hook/wechat_api_v8_fix.js'
def camel_to_snake(name):
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
def c(ex, method, *args):
snake = camel_to_snake(method)
return getattr(ex, snake)(*args)
subprocess.run(['adb', '-s', f'{PHONE_IP}:5555', 'forward', 'tcp:27042', 'tcp:27042'], timeout=5, capture_output=True)
result = subprocess.run(['adb', '-s', f'{PHONE_IP}:5555', 'shell', 'ps -A'], capture_output=True, text=True, timeout=5)
pid = None
for line in result.stdout.split('\n'):
if 'com.tencent.mm' in line and ':push' not in line and ':sandbox' not in line and ':tools' not in line and ':appbrand' not in line:
parts = line.split()
if len(parts) >= 2:
try: pid = int(parts[1]); break
except: pass
print(f"微信PID: {pid}")
dm = frida.get_device_manager()
device = dm.add_remote_device('localhost:27042')
session = device.attach(pid)
with open(JS_FILE, 'r', encoding='utf-8') as f:
js_code = f.read()
script = session.create_script(js_code)
script.load()
time.sleep(3)
ex = script.exports_sync
# 1. 检查verifyFlag分布
print("\n=== verifyFlag分布 ===")
r = c(ex, 'rawQuery', 'main', 'SELECT verifyFlag, COUNT(*) as cnt FROM rcontact WHERE type=3 GROUP BY verifyFlag ORDER BY cnt DESC LIMIT 10')
print(json.dumps(r, ensure_ascii=False, indent=2))
# 2. 检查type=3的前5条数据
print("\n=== type=3前5条 ===")
r = c(ex, 'rawQuery', 'main', 'SELECT username, nickName, type, verifyFlag FROM rcontact WHERE type=3 LIMIT 5')
print(json.dumps(r, ensure_ascii=False, indent=2))
# 3. 检查chatroom表
print("\n=== chatroom表前3条 ===")
r = c(ex, 'rawQuery', 'main', 'SELECT chatroomname, memberCount, owner FROM chatroom LIMIT 3')
print(json.dumps(r, ensure_ascii=False, indent=2))
# 4. 检查label表
print("\n=== label相关表 ===")
r = c(ex, 'rawQuery', 'main', "SELECT name FROM sqlite_master WHERE type='table' AND name LIKE '%label%' OR name LIKE '%Label%'")
print(json.dumps(r, ensure_ascii=False, indent=2))
# 5. 检查contactLabelIds
print("\n=== contactLabelIds分布 ===")
r = c(ex, 'rawQuery', 'main', "SELECT contactLabelIds, COUNT(*) as cnt FROM rcontact WHERE type=3 AND contactLabelIds != '' GROUP BY contactLabelIds LIMIT 5")
print(json.dumps(r, ensure_ascii=False, indent=2))
# 6. 触发朋友圈DB加载
print("\n=== 触发朋友圈DB加载 ===")
subprocess.run(['adb', '-s', f'{PHONE_IP}:5555', 'shell',
'am start -n com.tencent.mm/.plugin.sns.ui.SnsTimeLineUI'], timeout=5, capture_output=True)
time.sleep(5)
r = c(ex, 'getSnsDbInfo')
print(json.dumps(r, ensure_ascii=False, indent=2))
# 7. 再次检查朋友圈
print("\n=== 朋友圈列表 ===")
r = c(ex, 'getMoments', 5)
print(json.dumps(r, ensure_ascii=False, indent=2))
print("\n完成!")