Files
workphone-sdk/sdk/scripts/ensure_ws_agent.sh
Manus AI 42fe10401a 1
1
2026-05-24 17:50:04 +08:00

50 lines
1.7 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# 确保 WebSocket Agent + Phantom Frida 在线存客宝对接口径WS+Frida非 ADB UI
set -euo pipefail
SDK_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
DEVICE_SERIAL="${DEVICE_SERIAL:-192.168.110.80:5555}"
SDK_PORT="${SDK_PORT:-8899}"
PH_CFG="${SDK_ROOT}/scripts/anti_detect/phantom_frida_config.json"
LOG="/tmp/wp_agent_ws.log"
if [[ ! -f "$PH_CFG" ]]; then
echo "缺少 phantom 配置,先运行: bash scripts/frida_workphone_oneclick.sh -d ${DEVICE_SERIAL}"
exit 1
fi
PH_PORT=$(python3 -c "import json; print(json.load(open('${PH_CFG}'))['listen_port'])")
adb -s "${DEVICE_SERIAL}" forward "tcp:${PH_PORT}" "tcp:${PH_PORT}" >/dev/null 2>&1 || true
pkill -f "agent.py -d ${DEVICE_SERIAL} -s ws://127.0.0.1:${SDK_PORT}" 2>/dev/null || true
sleep 1
# Frida attach 需要微信进程
WX_PID="$(adb -s "${DEVICE_SERIAL}" shell pidof com.tencent.mm 2>/dev/null | tr -d '\r' || true)"
if [[ -z "${WX_PID}" ]]; then
echo "拉起微信..."
adb -s "${DEVICE_SERIAL}" shell am start -n com.tencent.mm/.ui.LauncherUI >/dev/null 2>&1 || true
sleep 6
fi
cd "${SDK_ROOT}/agent"
export WP_FRIDA_MODE=remote
export WP_DEVICE_SERIAL="${DEVICE_SERIAL}"
export WP_FRIDA_PORT="${PH_PORT}"
nohup python3 agent.py \
-d "${DEVICE_SERIAL}" \
-s "ws://127.0.0.1:${SDK_PORT}/ws/device" \
--heartbeat 10 >> "${LOG}" 2>&1 &
echo "Agent pid=$! device=${DEVICE_SERIAL} frida_port=${PH_PORT}"
for _i in $(seq 1 20); do
if grep -q "RPC ping: pong" "${LOG}" 2>/dev/null; then
echo "frida_rpc_ready"
break
fi
sleep 2
done
curl -s "http://127.0.0.1:${SDK_PORT}/api/v3/connection/status" | python3 -c "
import sys,json
d=json.load(sys.stdin).get('data',{})
print('ws_online', d.get('online_ws_count'), d.get('online_device_ids'))
"