mirror of
https://github.com/okhsunrog/vpnhide.git
synced 2026-05-23 03:50:05 +00:00
`pm list packages` starts responding to IPC very early in boot but returns only system packages for several more seconds. service.sh's previous `pm list packages >/dev/null && break` loop exited as soon as PM was alive — before user-installed packages (including the vpnhide app itself and any chosen targets) were indexed. The subsequent `pm list packages -U | grep "^package:$pkg "` returned nothing, so /data/system/vpnhide_uids.txt was written empty, and the LSPosed hook in system_server cached an empty target set for the session. Result: all Java-level filtering silently disabled until the next reboot where we got lucky on timing. Gate the boot wait on our own package being visible in the list (with a 60s budget instead of 30s). That guarantees PM has moved past the system-only snapshot before we read target names. Also add per-call diagnostic logs to the three writeToParcel hooks (NC, NI, LP) — `VpnHide-NC`, `VpnHide-NI`, `VpnHide-LP` tags — so the next "Java check fails with zygisk on / passes with zygisk off" style report can be diagnosed from logs alone instead of a live instrumented build. The per-call volume is modest compared to system_server's own logging and the logs live inside the LSPosed bridge log.
92 lines
3.3 KiB
Bash
92 lines
3.3 KiB
Bash
#!/system/bin/sh
|
|
# Resolves package names → UIDs for kmod and lsposed at boot.
|
|
# kmod targets → /proc/vpnhide_targets
|
|
# lsposed targets → /data/system/vpnhide_uids.txt
|
|
|
|
KMOD_TARGETS="/data/adb/vpnhide_kmod/targets.txt"
|
|
LSPOSED_TARGETS="/data/adb/vpnhide_lsposed/targets.txt"
|
|
PROC_TARGETS="/proc/vpnhide_targets"
|
|
SS_UIDS_FILE="/data/system/vpnhide_uids.txt"
|
|
|
|
# Wait for the proc entry (kernel module must be loaded)
|
|
for i in 1 2 3 4 5 6 7 8 9 10; do
|
|
[ -f "$PROC_TARGETS" ] && break
|
|
sleep 1
|
|
done
|
|
|
|
# Wait until PackageManager has actually indexed user-installed apps.
|
|
# `pm list packages` starts responding very early in boot but returns
|
|
# only system packages for several more seconds — if we resolve during
|
|
# that window, `dev.okhsunrog.vpnhide` (and any other user-installed
|
|
# target) silently drops from the UID file and the LSPosed hook caches
|
|
# an empty target set for the rest of the session. Gate on our own
|
|
# package being visible, with a 60s budget.
|
|
for i in $(seq 1 60); do
|
|
if pm list packages -U 2>/dev/null | grep -q "^package:dev.okhsunrog.vpnhide "; then
|
|
break
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
if [ ! -f "$PROC_TARGETS" ]; then
|
|
log -t vpnhide "kernel module not loaded, skipping kmod UID resolution"
|
|
fi
|
|
|
|
# Migration: if lsposed targets don't exist yet, seed from kmod targets
|
|
if [ ! -f "$LSPOSED_TARGETS" ] && [ -f "$KMOD_TARGETS" ]; then
|
|
cp "$KMOD_TARGETS" "$LSPOSED_TARGETS"
|
|
log -t vpnhide "migrated kmod targets to lsposed targets"
|
|
fi
|
|
|
|
# Get all packages with UIDs in one call
|
|
ALL_PACKAGES="$(pm list packages -U 2>/dev/null)"
|
|
|
|
# resolve_uids <targets_file> — prints resolved UIDs to stdout
|
|
resolve_uids() {
|
|
local targets_file="$1"
|
|
[ -f "$targets_file" ] || return
|
|
local uids=""
|
|
while IFS= read -r line || [ -n "$line" ]; do
|
|
pkg="$(echo "$line" | tr -d '[:space:]')"
|
|
[ -z "$pkg" ] && continue
|
|
case "$pkg" in \#*) continue ;; esac
|
|
uid="$(echo "$ALL_PACKAGES" | grep "^package:${pkg} " | sed 's/.*uid://')"
|
|
if [ -n "$uid" ]; then
|
|
if [ -z "$uids" ]; then uids="$uid"; else uids="${uids}
|
|
${uid}"; fi
|
|
else
|
|
log -t vpnhide "package not found: $pkg"
|
|
fi
|
|
done < "$targets_file"
|
|
[ -n "$uids" ] && echo "$uids"
|
|
}
|
|
|
|
# Resolve kmod targets → /proc/vpnhide_targets
|
|
if [ -f "$PROC_TARGETS" ] && [ -f "$KMOD_TARGETS" ]; then
|
|
KMOD_UIDS="$(resolve_uids "$KMOD_TARGETS")"
|
|
if [ -n "$KMOD_UIDS" ]; then
|
|
echo "$KMOD_UIDS" > "$PROC_TARGETS"
|
|
count="$(echo "$KMOD_UIDS" | wc -l)"
|
|
log -t vpnhide "kmod: loaded $count target UIDs"
|
|
else
|
|
log -t vpnhide "kmod: no UIDs resolved"
|
|
fi
|
|
fi
|
|
|
|
# Resolve lsposed targets → /data/system/vpnhide_uids.txt
|
|
# Create persist dir if needed (for first-time installs)
|
|
mkdir -p /data/adb/vpnhide_lsposed 2>/dev/null
|
|
if [ -f "$LSPOSED_TARGETS" ]; then
|
|
LSPOSED_UIDS="$(resolve_uids "$LSPOSED_TARGETS")"
|
|
if [ -n "$LSPOSED_UIDS" ]; then
|
|
echo "$LSPOSED_UIDS" > "$SS_UIDS_FILE"
|
|
chmod 644 "$SS_UIDS_FILE"
|
|
chcon u:object_r:system_data_file:s0 "$SS_UIDS_FILE" 2>/dev/null
|
|
count="$(echo "$LSPOSED_UIDS" | wc -l)"
|
|
log -t vpnhide "lsposed: wrote $count UIDs to $SS_UIDS_FILE"
|
|
else
|
|
echo > "$SS_UIDS_FILE"
|
|
chmod 644 "$SS_UIDS_FILE"
|
|
log -t vpnhide "lsposed: no UIDs resolved"
|
|
fi
|
|
fi
|