#!/bin/bash

# 带颜色的输出函数
print_color() {
    local color_code=$1
    shift
    echo -e "\033[${color_code}m$*\033[0m"
}

# 1. 检查是否为root用户
if [ $(id -u) -ne 0 ]; then
    print_color "31;1" "错误: 请使用root权限执行此脚本!"
    exit 1
fi

# 2. 定义常量（便于后续维护修改）
TARGET_DIR="/data/data/com.tencent.igce"
LIB_FILE="libs/arm64-v8a/libBM.so"
HOOK_FILE="64bit"
LIB_PERM="755"
HOOK_PERM="777"

# 3. 输出提示信息（精简冗余重复内容，添加颜色）
print_color "36;1" "===== 开始执行64KDZ追踪脚本 ====="
# 改为彩色输出，36;1对应青色高亮
print_color "36;1" "霍金等着被格机吧哈哈哈哈哈哈哈哈哈哈"
print_color "36;1" "霍金等着被格机吧哈哈哈哈哈哈哈哈哈哈"
print_color "36;1" "霍金等着被格机吧哈哈哈哈哈哈哈哈哈哈"
print_color "36;1" "霍金等着被格机吧哈哈哈哈哈哈哈哈哈哈"
print_color "36;1" "霍金等着被格机吧哈哈哈哈哈哈哈哈哈哈"
print_color "36;1" "霍金等着被格机吧哈哈哈哈哈哈哈哈哈哈"
print_color "36;1" "霍金等着被格机吧哈哈哈哈哈哈哈哈哈哈"
print_color "36;1" "霍金等着被格机吧哈哈哈哈哈哈哈哈哈哈"
print_color "36;1" "霍金等着被格机吧哈哈哈哈哈哈哈哈哈哈"
print_color "36;1" "霍金等着被格机吧哈哈哈哈哈哈哈哈哈哈"
print_color "36;1" "霍金等着被格机吧哈哈哈哈哈哈哈哈哈哈"
sleep 0.2

# 4. 复制文件并设置权限
print_color "33;1" "[*] 正在复制动态库文件..."
cp -f "${LIB_FILE}" "${TARGET_DIR}/" || { print_color "31;1" "错误: 动态库文件复制失败!"; exit 1; }
chmod "${LIB_PERM}" "${TARGET_DIR}/libBM.so"

print_color "33;1" "[*] 正在复制劫持文件..."
cp -f "${HOOK_FILE}" "${TARGET_DIR}/" || { print_color "31;1" "错误: 劫持文件复制失败!"; exit 1; }
chmod "${HOOK_PERM}" "${TARGET_DIR}/${HOOK_FILE}"

# 5. 验证文件和权限
print_color "33;1" "[*] 正在验证文件状态..."
if [ -f "${TARGET_DIR}/libBM.so" ] && [ "$(stat -c '%a' "${TARGET_DIR}/libBM.so")" = "${LIB_PERM}" ]; then
    print_color "32;1" "[+] 动态库文件正常"
else
    print_color "31;1" "[-] 动态库文件不正确"
    exit 1
fi

if [ -f "${TARGET_DIR}/${HOOK_FILE}" ] && [ "$(stat -c '%a' "${TARGET_DIR}/${HOOK_FILE}")" = "${HOOK_PERM}" ]; then
    print_color "32;1" "[+] 劫持文件正常"
else
    print_color "31;1" "[-] 劫持文件不正确"
    exit 1
fi

# 6. 启动目标应用并注入
print_color "32;1" "[+] 准备完毕!"
sleep 0.5

print_color "33;1" "[*] 正在启动目标应用..."
am start com.tencent.igce/com.epicgames.ue4.SplashActivity || print_color "33;1" "提示: 应用启动可能失败，请手动检查"
sleep 10

print_color "33;1" "[*] 关闭SELinux并注入..."
setenforce 0
"${TARGET_DIR}/${HOOK_FILE}" -n com.tencent.igce -so "${TARGET_DIR}/libBM.so"

print_color "32;1" "===== 脚本执行结束 ====="
