From a5700eddceeaabdfccfb4cc7ed501274d0de7964 Mon Sep 17 00:00:00 2001 From: sssnake Date: Sun, 12 Jul 2026 11:09:41 -0700 Subject: [PATCH] Fix detector daemon status check and dumpsys-hang stale status action.sh: use short pgrep patterns so the enforcement/detector 'running' check resolves correctly instead of falsely reporting 'not running'. cgdetect.sh: wrap dumpsys telephony.registry in timeout so a blocking registry read can no longer freeze the status file and stall the frame counter. --- action.sh | 49 ++++++++++++++++++++++++++++--------------------- cgdetect.sh | 4 +++- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/action.sh b/action.sh index 58e46e8..060d5b3 100755 --- a/action.sh +++ b/action.sh @@ -1,38 +1,45 @@ #!/system/bin/sh -# CellGuard — KernelSU-Next "Action" button handler. -# Shows enforcement + diagnostics status. - +# CellGuard — KernelSU-Next "Action" button handler. Status readout only. MODDIR=${0%/*} PATH=/system/bin:$PATH -CONFIG_DIR="/data/adb/cellguard" +CG=/data/adb/cellguard -echo "== CellGuard status ==" +kv() { grep -m1 "^$1=" "$CG/status" 2>/dev/null | cut -d= -f2-; } -# --- enforcement (LTE + 5G/NR only) --- -if pgrep -f "$MODDIR/ratlock.sh" >/dev/null 2>&1; then - if [ "$(cat "$CONFIG_DIR/enabled" 2>/dev/null)" = 0 ]; then - echo "RAT lock: running, BLOCK toggle OFF (all RAT allowed)" +echo "== CellGuard ==" + +# --- enforcement: block 2G/3G (ratlock) --- +if pgrep -f ratlock.sh >/dev/null 2>&1; then + if [ "$(cat "$CG/enabled" 2>/dev/null)" = "0" ]; then + echo "Block 2G/3G: OFF (all RAT allowed)" else - echo "RAT lock: RUNNING (LTE + 5G/NR only, 2G/3G blocked)" + echo "Block 2G/3G: ON (LTE + 5G/NR only)" fi else - echo "RAT lock: NOT running — reboot or run: sh $MODDIR/ratlock.sh &" + echo "Block 2G/3G: daemon not running — reboot" fi for s in 0 1; do v=$(cmd phone get-allowed-network-types-for-users -s "$s" 2>/dev/null) [ -n "$v" ] && echo " SIM$s allowed: $v" done -# --- diagnostics (kernel CP-frame capture) --- -if [ -e /proc/cgcap/frames ]; then - total=$(head -1 /proc/cgcap/frames | sed -n 's/.*total=\([0-9]*\).*/\1/p') - echo "Diag capture: ACTIVE (cgcap) — frames seen: ${total:-0}" - echo " raw diag: /proc/cgcap/frames (all cpif channels)" +# --- detection (cgdetect) --- +if pgrep -f cgdetect.sh >/dev/null 2>&1; then + if [ "$(cat "$CG/detect_enabled" 2>/dev/null)" = "0" ]; then + echo "Detection: OFF" + else + echo "Detection: ON" + fi else - echo "Diag capture: OFF — cgcap.ko not loaded" + echo "Detection: daemon not running — reboot" fi -echo -echo "Decode + IMSI-catcher heuristics run off-device (Android has no Python):" -echo " adb shell su -c 'cat /proc/cgcap/frames' > frames.txt" -echo " python3 tools/cg_decode.py frames.txt" +# --- live serving + capture --- +rat=$(kv rat); plmn=$(kv plmn); op=$(kv operator) +[ -n "$rat" ] && echo "Serving: $rat $op PLMN $plmn" +if [ -e /proc/cgcap/frames ]; then + echo "Diag capture: $(head -1 /proc/cgcap/frames | sed -n 's/.*total=\([0-9]*\).*/\1/p') frames" +else + echo "Diag capture: cgcap not loaded" +fi +echo "Alerts: $(grep -c . "$CG/alerts" 2>/dev/null)" diff --git a/cgdetect.sh b/cgdetect.sh index d59c1c6..d1ef3e5 100755 --- a/cgdetect.sh +++ b/cgdetect.sh @@ -38,7 +38,9 @@ echo "[$(date '+%Y-%m-%d %H:%M:%S')] cgdetect start (poll=${POLL}s)" >> "$CG/cgd while true; do # detector toggle (WebUI) — idle when off if [ "$(cat "$CG/detect_enabled" 2>/dev/null)" = "0" ]; then sleep "$POLL"; continue; fi - reg=$(dumpsys telephony.registry 2>/dev/null) + # timeout guards against a blocking dumpsys hanging the whole loop (which + # would freeze the status file — the cause of stale frame counts). + reg=$(timeout 6 dumpsys telephony.registry 2>/dev/null) # serving air-interface RAT = type of the registered cell identity (real MCC). # A serving GSM/WCDMA identity == an active 2G/3G downgrade. if echo "$reg" | grep -q 'CellIdentityNr:{[^}]*mMcc=[0-9]'; then rat=NR