adb shell settings put global captive_portal_http_url http://cp.cloudflare.com/generate_204 adb shell settings put global captive_portal_https_url https://cp.cloudflare.com/generate_204
if [ "$#" -ne 0 ]; then echo"错误: 不支持的参数: $*" usage exit 1 fi
stop_shill() { echo"尝试停止 shill 服务以解除文件占用..." if [ -x /sbin/initctl ]; then /sbin/initctl stop shill >/dev/null 2>&1 || true fi if [ -x /sbin/stop ]; then /sbin/stop shill >/dev/null 2>&1 || true fi killall -9 shill >/dev/null 2>&1 || true }
restart_shill() { echo"尝试重启 shill 服务..."
if [ -x /sbin/initctl ]; then if /sbin/initctl restart shill >/dev/null 2>&1; then if /sbin/initctl status shill 2>/dev/null | grep -q "start/running"; then echo"shill 服务已通过 /sbin/initctl 重启。" return 0 fi fi if /sbin/initctl stop shill >/dev/null 2>&1 && /sbin/initctl start shill >/dev/null 2>&1; then if /sbin/initctl status shill 2>/dev/null | grep -q "start/running"; then echo"shill 服务已通过 /sbin/initctl stop/start 重启。" return 0 fi fi fi
if [ -x /sbin/stop ] && [ -x /sbin/start ]; then /sbin/stop shill >/dev/null 2>&1 || true if /sbin/start shill >/dev/null 2>&1; then if [ -x /sbin/initctl ] && /sbin/initctl status shill 2>/dev/null | grep -q "start/running"; then echo"shill 服务已通过 /sbin/stop 和 /sbin/start 重启。" return 0 fi echo"shill 服务已通过 /sbin/stop 和 /sbin/start 发起重启。" return 0 fi fi
echo"未找到可用的服务管理命令,请重启系统以应用更改。" return 1 }
get_selinux_context() { local target_path="$1" ifcommand -v ls >/dev/null 2>&1; then ls -Zd "$target_path" 2>/dev/null | awk '{print $4}' fi }
apply_selinux_context() { local target_path="$1" local context="$2"
if [ -n "$context" ] && command -v chcon >/dev/null 2>&1; then chcon"$context""$target_path" >/dev/null 2>&1 || true fi }
# 自动检测目标文件位置 if [ -f "shill" ]; then FILE="shill" BACKUP="shill.bak" echo"检测到当前目录下存在 shill,将对当前目录文件进行操作。" elif [ -f "/usr/bin/shill" ]; then FILE="/usr/bin/shill" BACKUP="/usr/bin/shill.bak" echo"检测到 /usr/bin/shill,将对系统文件进行操作。" else echo"错误: 未找到 shill 文件 (既不在当前目录,也不在 /usr/bin/shill)。" exit 1 fi
SHILL_CONTEXT=$(get_selinux_context "$FILE") if [ -z "$SHILL_CONTEXT" ] && [ "$FILE" = "/usr/bin/shill" ]; then SHILL_CONTEXT="u:object_r:cros_shill_exec:s0" fi
if [ -z "$offsets" ]; then if LC_ALL=C grep -a -q -F -- "$new_url""$FILE"; then echo"已是目标值: $old_url -> $new_url (跳过)" else echo"未找到目标: $old_url" fi return fi
for offset in$offsets; do local hex_offset hex_offset=$(printf'0x%X'"$offset") echo"正在替换 (偏移量 $offset, $hex_offset): $old_url -> $new_url (填充 $pad_len 字节)" # 1. 写入新 URL # 使用 printf 确保不输出换行符 printf"%s""$new_url" | dd of="$FILE" bs=1 seek="$offset" count="$new_len" conv=notrunc 2>/dev/null # 2. 写入 null 填充 (如果需要) if [ $pad_len -gt 0 ]; then ddif=/dev/zero of="$FILE" bs=1 seek=$((offset + new_len)) count="$pad_len" conv=notrunc 2>/dev/null fi done }