Files
workphone-sdk/sdk/scripts/phantom_frida_keepalive.sh

34 lines
1.9 KiB
Bash
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
# ==============================================================================
# phantom_frida_keepalive.sh — Phantom-Frida 保活守护FS-6
#
# 背景:微信 8.0.69 反检测会间歇 kill frida-server导致 Hook 掉线、开发中断。
# 本守护在 Mac 主机循环检查设备端 Phantom-Frida 进程,死了就用 Root 重起,
# 并触发 Agent 重连(可选)。不依赖手机端 Termux。
#
# 用法:
# nohup bash phantom_frida_keepalive.sh xgfe65eimrrofyws > logs/phantom_keepalive.log 2>&1 &
# ==============================================================================
set -uo pipefail
SERIAL="${1:-xgfe65eimrrofyws}"
CFG="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/anti_detect/phantom_frida_config.json"
BIN_PATH="$(python3 -c "import json;print(json.load(open('$CFG'))['binary_path'])" 2>/dev/null || echo /data/local/tmp/fs_8e6b0b)"
BIN_NAME="$(basename "$BIN_PATH")"
PORT="$(python3 -c "import json;print(json.load(open('$CFG'))['listen_port'])" 2>/dev/null || echo 24781)"
INTERVAL="${KEEPALIVE_INTERVAL:-12}"
echo "[keepalive] serial=$SERIAL bin=$BIN_PATH port=$PORT (前台持有模式)"
# 前台持有模式Mac 端阻塞运行 fridaadb shell 持有连接 → 子进程不收 SIGHUP
# 实测 `su -c 'nohup X &'` 后台化在本机型失效前台持有最可靠frida 被杀则循环重连。
while true; do
# 清理可能的端口占用残留(旧 frida-server / TIME_WAIT 实例)
adb -s "$SERIAL" shell "su -c 'pidof $BIN_NAME | xargs -r kill -9'" 2>/dev/null
echo "[keepalive $(date '+%H:%M:%S')] 前台启动 Phantom-Frida..."
# 阻塞frida 活着则此行一直挂起;退出(被杀/崩溃)才返回
adb -s "$SERIAL" shell "su -c '$BIN_PATH -l 0.0.0.0:$PORT'" 2>&1
echo "[keepalive $(date '+%H:%M:%S')] Phantom-Frida 退出,${INTERVAL}s 后重连..."
sleep "$INTERVAL"
done