#!/usr/bin/env python3
"""快速探测Frida exports方法名格式"""
import frida, time, sys, os

SCRIPT_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                           "../agent/hook/wechat_hook_v2.js")

device = frida.get_device_manager().add_remote_device("192.168.0.12:27042")
session = device.attach(7239)

with open(SCRIPT_PATH, "r") as f:
    src = f.read()

script = session.create_script(src)
script.on("message", lambda m, d: None)
script.load()
time.sleep(2)

exports = script.exports_sync

# 列出所有方法
methods = sorted([x for x in dir(exports) if not x.startswith("_")])
print(f"Total: {len(methods)}")
for m in methods:
    print(f"  {m}")

# 直接调用ping
print(f"\n--- Test calls ---")
print(f"ping() = {exports.ping()}")

# 尝试不同格式调用getProcessInfo
for name in ["getProcessInfo", "getprocessinfo", "get_process_info"]:
    try:
        fn = getattr(exports, name)
        r = fn()
        print(f"{name}() = OK: {str(r)[:80]}")
        break
    except Exception as e:
        print(f"{name}() = FAIL: {e}")

script.unload()
session.detach()
print("\nDone.")
