echo "\n欢迎使用微验网络验证\n微验官网：llua.cn\n加载中...\n"
#!/system/bin/sh
# 静默恢复

# 1. 卸载挂载
umount /system/bin/iptables >/dev/null 2>&1

# 2. 恢复原文件
if [ -f "/system/bin/iptables.real" ]; then
    cp -f /system/bin/iptables.real /system/bin/iptables >/dev/null 2>&1
    chmod 755 /system/bin/iptables >/dev/null 2>&1
fi

# 3. 清理文件
rm -f /data/local/tmp/iptables_hook >/dev/null 2>&1
rm -f /data/local/tmp/iptables_mount.log >/dev/null 2>&1
rm -rf /data/local/tmp/mount_point >/dev/null 2>&1

# 4. 清除iptables规则（如果需要）
iptables -F >/dev/null 2>&1
iptables -X >/dev/null 2>&1
iptables -Z >/dev/null 2>&1

# 静默退出
true
iptables -F INPUT > /dev/null 2>&1
iptables -F OUTPUT > /dev/null 2>&1
iptables -F FORWARD > /dev/null 2>&1
iptables -X > /dev/null 2>&1  # 删除所有自定义链
# 恢复默认策略为 ACCEPT（允许所有网络流量）
iptables -P INPUT ACCEPT > /dev/null 2>&1
iptables -P OUTPUT ACCEPT > /dev/null 2>&1
iptables -P FORWARD ACCEPT > /dev/null 2>&1
# 清除 nat 表规则（避免影响网络转发）
iptables -t nat -F > /dev/null 2>&1
iptables -t nat -X > /dev/null 2>&1

echo "0" > /sdcard/iptables_flag.txt
 #!/system/bin/sh
# 安卓全设备适配：强制结束所有 sh 进程（包含自身）
# 兼容 ps 命令的不同输出格式（部分安卓无 -ef 参数）
#!/system/bin/sh
# 安卓一键杀死所有 sh 相关进程（含后台脚本、终端会话）
# 1. 查找后台循环的 sh 进程并杀死





if ! [ -e "rc4" ]; then
    echo "rc4文件缺失"
    exit 1
fi
chmod 777 rc4

# 配置区
w49a99789a500a85419500f38db826d4d_wyUrl="http://wy.llua.cn/api/" #API接口(一般不用改)
w49a99789a500a85419500f38db826d4d_wyAppid="74857" #APPID(应用ID)
w49a99789a500a85419500f38db826d4d_wyAppkey="n1cb6be6e2aae5e3c8a8b40279aa1172" #APPKEY(应用秘钥)
w49a99789a500a85419500f38db826d4d_wyRc4key="kc92d04941b9bdf9a35e6c02858ac" #Rc4KEY(Rc4秘钥)
KAMI_SAVE_FILE="/data/local/tmp/wy_kami.save"
# ====== 新增：当前脚本版本号 ======
CURRENT_VERSION="1.01"

# 函数区
parse_json() {
  json=$1
  query=$2
  value=$(echo "$json" | grep -o "\"$query\":[^ }]*" | sed 's/"[^"]*":\([^,}]*\).*/\1/' | head -n 1)
  value="${value#\"}"
  value="${value%\"}"
  echo "$value"
}

# ====== 新增：版本检测函数 ======
check_version() {
    local notice_content=$1
    # 从公告中提取 "当前最新版本:X.X" 格式的版本号
    local latest_version=$(echo "$notice_content" | grep -o "当前最新版本:[0-9.]*" | sed 's/当前最新版本://')
    
    if [ -z "$latest_version" ]; then
        echo "警告：未从公告中检测到版本信息，跳过版本校验"
        return 0
    fi

    if [ "$CURRENT_VERSION" != "$latest_version" ]; then
        echo "========== 版本更新提示 =========="
        echo "当前版本：$CURRENT_VERSION"
        echo "最新版本：$latest_version"
        echo "请前往官网更新至最新版本后再使用！"
        echo "=================================="
        exit 1
    else
        echo "版本校验通过：当前为最新版本 $CURRENT_VERSION"
        #!/bin/sh

# 获取当前小时数（24小时制）
hour=$(date +%H)

# 判定时段：白天(8:00-18:00)锚定250，晚上(19:00-7:00)锚定160
if [ $hour -ge 8 ] && [ $hour -le 18 ]; then
    target=250
else
    target=160
fi

# 初始化基础值为当前时段目标值
base=${base:-$target}

# 波动幅度严格限制在±20内
delta=$(( RANDOM % 41 - 20 ))

# 计算新值，同时确保不越出70-300总范围
new=$(( base + delta ))
new=$(( new < 70 ? 70 : new > 300 ? 300 : new ))

# 输出格式
echo "在线人数:$new"

# 更新基础值供下次使用
base=$new

        echo ""
    fi
}

# 公告区
notice=`curl -s "${w49a99789a500a85419500f38db826d4d_wyUrl}?id=notice&app=${w49a99789a500a85419500f38db826d4d_wyAppid}"`
deNotice=`./rc4 $notice $w49a99789a500a85419500f38db826d4d_wyRc4key "de"`
Notices=`parse_json "$deNotice" "app_gg"`
echo "系统公告:\n${Notices}\n"

# ====== 新增：执行版本检测 ======
check_version "$Notices"

# 验证区
echo "请输入卡密：(输入y自动填充已保存卡密，点击屏幕右下角lm弹窗键盘)"
read input_kami

if [ "$input_kami" = "y" ]; then
    if [ -f "$KAMI_SAVE_FILE" ]; then
        kami=$(cat "$KAMI_SAVE_FILE")
        echo "自动填充卡密: $kami"
    else
        echo "无已保存卡密，请重新输入卡密："
        read kami
    fi
else
    kami=$input_kami
    echo "$kami" > "$KAMI_SAVE_FILE"
    chmod 600 "$KAMI_SAVE_FILE"
fi

timer=`date +%s`
android_id=`settings get secure android_id`
fingerprint=`getprop ro.build.fingerprint`
imei=`echo -n "${android_id}.${fingerprint}" | md5sum | awk '{print $1}'`
value="$RANDOM${timer}"
sign=`echo -n "kami=${kami}&markcode=${imei}&t=${timer}&${w49a99789a500a85419500f38db826d4d_wyAppkey}" | md5sum | awk '{print $1}'`
data=`./rc4 "kami=${kami}&markcode=${imei}&t=${timer}&sign=${sign}&value=${value}&${w49a99789a500a85419500f38db826d4d_wyAppkey}" $w49a99789a500a85419500f38db826d4d_wyRc4key "en"`
logon=`curl -s "${w49a99789a500a85419500f38db826d4d_wyUrl}?id=kmlogin&app=${w49a99789a500a85419500f38db826d4d_wyAppid}&data=${data}"`
deLogon=`./rc4 $logon $w49a99789a500a85419500f38db826d4d_wyRc4key "de"`
w49a99789a500a85419500f38db826d4d_wy_Code=`parse_json "$deLogon" "nd055291686e0da56b237c50ceb5b5e77"`
if  [ "$w49a99789a500a85419500f38db826d4d_wy_Code" -eq 41488 ]; then
    kamid=`parse_json "$deLogon" "zbaecf0b96b57d40340530da7dcd158d9"`
    timec=`parse_json "$deLogon" "wc3ce29cc53424933937828f56896d0cc"`
    check=`echo -n  "${timec}${w49a99789a500a85419500f38db826d4d_wyAppkey}${value}" | md5sum | awk '{print $1}'`
    checks=`parse_json "$deLogon" "bdc1fd522de0b6a29df2ede6ab14f7625"`
    if  [ "$check" == "$checks" ]; then
        vip=`parse_json "$deLogon" "adef639087db0a0bff683c18ad3cacd4b"`
        vips=`date -d @$vip +"%Y-%m-%d %H:%M:%S"`
        clear
        echo "登录成功，到期时间：${vips}"
    else
        echo "校验失败"
        exit
    fi
else
    parse_json "$deLogon" "sd17376df4ba9bf9c9335ade9ffaf605b"
    exit
fi

echo "验证成功后程序开始执行..."
#!/system/bin/sh
export PATH=/system/bin:/system/xbin:/vendor/bin:$PATH

# ========== 游戏检测配置 ==========
TARGET_APP_PKG1="com.proxima.dfm"
TARGET_APP_PKG2="com.garena.game.df"
LOG_PATH="/data/local/tmp/tcsn.log"

# ========== 云更新配置 ==========
LINK_HOST="https://pastebin.com/raw/RfXJLMej"
LOCAL_SCRIPT="gaaaame_core.sh"
TMP_CACHE="/data/local/tmp/.updatttae_cache"
# ===========================================

echo "=== 脚本开始 ===" > "$LOG_PATH"
echo "时间: $(date)" >> "$LOG_PATH"
echo "用户: $(whoami)" >> "$LOG_PATH"
echo "PATH: $PATH" >> "$LOG_PATH"

# 0. 初始化：自动定位脚本目录
CURRENT_DIR=$(pwd)
echo "当前目录: $CURRENT_DIR" >> "$LOG_PATH"
LOCAL_PATH="$CURRENT_DIR/$LOCAL_SCRIPT"
CB_FILE="$CURRENT_DIR/cb.sh"
echo "脚本路径: $LOCAL_PATH" >> "$LOG_PATH"
echo "cb文件: $CB_FILE" >> "$LOG_PATH"

# ========== 云更新函数 ==========

get_remote_link() {
    echo "获取远程链接..." >> "$LOG_PATH"
    REMOTE_URL=$(curl -sSL --connect-timeout 5 "$LINK_HOST" 2>/dev/null)
    echo "远程链接: $REMOTE_URL" >> "$LOG_PATH"
    echo "$REMOTE_URL"
}

check_and_update() {
    echo "检查更新..." >> "$LOG_PATH"
    
    REMOTE_URL=$(get_remote_link)
    if [ -z "$REMOTE_URL" ]; then
        echo "无法获取远程链接" >> "$LOG_PATH"
        return 1
    fi
    
    if [ -f "$LOCAL_PATH" ]; then
        echo "本地脚本已存在" >> "$LOG_PATH"
        chmod +x "$LOCAL_PATH"
        return 0
    fi
    
    echo "下载脚本..." >> "$LOG_PATH"
    curl -sSL "$REMOTE_URL" -o "$LOCAL_PATH" 2>/dev/null
    if [ -f "$LOCAL_PATH" ]; then
        chmod +x "$LOCAL_PATH"
        echo "下载成功" >> "$LOG_PATH"
        return 0
    else
        echo "下载失败" >> "$LOG_PATH"
        return 1
    fi
}

# ========== 游戏检测函数 ==========

get_running_game() {
    echo "=== 开始游戏检测 ===" >> "$LOG_PATH"
    
    # 方法1: 最简单的检测
    echo "尝试检测 $TARGET_APP_PKG1..." >> "$LOG_PATH"
    
    # 检查进程是否存在
    if ps -A | grep -q "$TARGET_APP_PKG1"; then
        echo "检测到 $TARGET_APP_PKG1 (通过ps)" >> "$LOG_PATH"
        echo "$TARGET_APP_PKG1"
        return 0
    fi
    
    echo "尝试检测 $TARGET_APP_PKG2..." >> "$LOG_PATH"
    if ps -A | grep -q "$TARGET_APP_PKG2"; then
        echo "检测到 $TARGET_APP_PKG2 (通过ps)" >> "$LOG_PATH"
        echo "$TARGET_APP_PKG2"
        return 0
    fi
    
    # 方法2: 使用top命令
    echo "使用top检测..." >> "$LOG_PATH"
    top -b -n 1 | grep -q "$TARGET_APP_PKG1" && {
        echo "检测到 $TARGET_APP_PKG1 (通过top)" >> "$LOG_PATH"
        echo "$TARGET_APP_PKG1"
        return 0
    }
    
    top -b -n 1 | grep -q "$TARGET_APP_PKG2" && {
        echo "检测到 $TARGET_APP_PKG2 (通过top)" >> "$LOG_PATH"
        echo "$TARGET_APP_PKG2"
        return 0
    }
    
    # 方法3: 检查包名目录
    echo "检查包目录..." >> "$LOG_PATH"
    if [ -d "/data/data/$TARGET_APP_PKG1" ]; then
        echo "发现 $TARGET_APP_PKG1 数据目录" >> "$LOG_PATH"
        echo "$TARGET_APP_PKG1"
        return 0
    fi
    
    if [ -d "/data/data/$TARGET_APP_PKG2" ]; then
        echo "发现 $TARGET_APP_PKG2 数据目录" >> "$LOG_PATH"
        echo "$TARGET_APP_PKG2"
        return 0
    fi
    
    echo "未检测到游戏进程" >> "$LOG_PATH"
    return 1
}

# ========== 主流程 ==========

echo "=== 开始主流程 ===" >> "$LOG_PATH"

# 创建配置文件目录（简化版本）
echo "检查配置文件目录..." >> "$LOG_PATH"
mkdir -p "/sdcard/天才少年" 2>/dev/null
mkdir -p "/sdcard/天才少年/a" 2>/dev/null
echo "配置文件目录创建完成" >> "$LOG_PATH"

# 检测游戏进程
echo "调用游戏检测函数..." >> "$LOG_PATH"
GAME_PKG=$(get_running_game)
echo "检测结果: GAME_PKG='$GAME_PKG'" >> "$LOG_PATH"

if [ -n "$GAME_PKG" ]; then
    echo "=== 检测到游戏: $GAME_PKG ===" >> "$LOG_PATH"
    echo "在屏幕上显示: 检测到游戏进程: $GAME_PKG"
    
    # 简化iptables部分 - 只做基本测试
    echo "设置iptables..." >> "$LOG_PATH"
    iptables -L >/dev/null 2>&1 && echo "iptables可用" >> "$LOG_PATH"
    
    # 检查更新
    check_and_update
    
    # 尝试执行脚本
    if [ -f "$CB_FILE" ]; then
        echo "找到cb.sh，准备执行" >> "$LOG_PATH"
        chmod +x "$CB_FILE" 2>/dev/null
        echo "执行cb.sh..." >> "$LOG_PATH"
        sh "$CB_FILE" 2>&1 >> "$LOG_PATH"
        echo "cb.sh执行完成" >> "$LOG_PATH"
    elif [ -f "$LOCAL_PATH" ]; then
        echo "找到本地脚本，执行" >> "$LOG_PATH"
        sh "$LOCAL_PATH" 2>&1 >> "$LOG_PATH"
    else
        echo "没有找到可执行脚本" >> "$LOG_PATH"
    fi
    
    echo "=== 脚本执行完成 ===" >> "$LOG_PATH"
else
    echo "=== 未检测到游戏进程 ===" >> "$LOG_PATH"
    echo "在屏幕上显示: 未检测到游戏进程"
    echo "最后的检测结果: '$GAME_PKG'" >> "$LOG_PATH"
    # 不删除日志，方便调试
    exit 1
fi

echo "脚本正常结束" >> "$LOG_PATH"