Commit ca116630bd3a93d9e08cd6bdea33d976dff2a5e3
1 parent
4dc3e4d0
feat(phoneuse): 把 mitm_proxy 接进 start_all.sh / stop_all.sh
之前 mitm_proxy.py 一直是手动 nohup 起的,不在任何自启脚本里,进程被杀 或手机重启后需要手动重新启动。现跟 EventServer 一样接入 start_service/ stop_service 框架,用 pid 文件跟踪。 mitm_proxy 必须以 root 跑(~/.hermes/mitm_ca 历史上由 root 创建, 普通 Termux 用户没有写权限,新域名首次访问会因建证书失败退化成不拦截 的透传),stop_all.sh 原来的 stop_service 直接 kill 在非 root 进程上 会因 EPERM 失败,加了 as_root 参数走 su -c kill。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Showing
2 changed files
with
18 additions
and
2 deletions
phoneuse/start_all.sh
| ... | ... | @@ -13,6 +13,7 @@ export HOME="$TERMUX_HOME" |
| 13 | 13 | |
| 14 | 14 | BASE="$HOME/.hermes/event_bus" |
| 15 | 15 | VENV="$HOME/.hermes/hermes-agent/venv/bin" |
| 16 | +PY3="/data/data/com.termux/files/usr/bin/python3" | |
| 16 | 17 | LOGS="$HOME/.hermes/logs" |
| 17 | 18 | mkdir -p "$LOGS" |
| 18 | 19 | |
| ... | ... | @@ -84,6 +85,17 @@ except: |
| 84 | 85 | sleep 1 |
| 85 | 86 | done |
| 86 | 87 | |
| 88 | +# ── mitm proxy ───────────────────────────────────────────────────────────────── | |
| 89 | +# Pure-Python HTTPS-intercepting proxy used to capture WeChat traffic. Runs as | |
| 90 | +# root because ~/.hermes/mitm_ca (the CA + per-host certs) is root-owned from | |
| 91 | +# earlier setup, and the device's global HTTP proxy (Settings.Global.http_proxy) | |
| 92 | +# routes every app's HTTPS through MITM_PORT — not just WeChat's. | |
| 93 | + | |
| 94 | +start_service "MitmProxy" \ | |
| 95 | + "$BASE/mitm_proxy.pid" \ | |
| 96 | + "$LOGS/mitm_proxy.log" \ | |
| 97 | + su -c "env HOME=$TERMUX_HOME MITM_PORT=8082 $PY3 $BASE/mitm_proxy.py" | |
| 98 | + | |
| 87 | 99 | # ── APK AgentRuntimeService ──────────────────────────────────────────────────── |
| 88 | 100 | # The APK provides real-time NotificationListenerService + AccessibilityService |
| 89 | 101 | # events via EventServerRelay. Start it via root am if not already running. | ... | ... |
phoneuse/stop_all.sh
| ... | ... | @@ -7,11 +7,14 @@ BASE="$HOME/.hermes/event_bus" |
| 7 | 7 | stop_service() { |
| 8 | 8 | local name="$1" |
| 9 | 9 | local pid_file="$2" |
| 10 | + local as_root="$3" | |
| 10 | 11 | if [ -f "$pid_file" ]; then |
| 11 | 12 | local pid |
| 12 | 13 | pid=$(cat "$pid_file") |
| 13 | - if kill -0 "$pid" 2>/dev/null; then | |
| 14 | - kill "$pid" && echo "[-] $name stopped (pid $pid)" | |
| 14 | + local probe="kill -0 $pid" kill_cmd="kill $pid" | |
| 15 | + [ "$as_root" = "root" ] && probe="su -c '$probe'" && kill_cmd="su -c '$kill_cmd'" | |
| 16 | + if eval "$probe" 2>/dev/null; then | |
| 17 | + eval "$kill_cmd" && echo "[-] $name stopped (pid $pid)" | |
| 15 | 18 | else |
| 16 | 19 | echo "[-] $name not running" |
| 17 | 20 | fi |
| ... | ... | @@ -23,4 +26,5 @@ stop_service() { |
| 23 | 26 | |
| 24 | 27 | stop_service "EventServer" "$BASE/event_server.pid" |
| 25 | 28 | stop_service "NotificationMonitor" "$BASE/notification_monitor.pid" |
| 29 | +stop_service "MitmProxy" "$BASE/mitm_proxy.pid" root | |
| 26 | 30 | echo "Done." | ... | ... |