#!/system/bin/sh
频道@qvxvxz
if [ $(id -u) -ne 0 ]; then
    exec su -c "$0"
    exit
fi

SCRIPT_DIR=$(dirname "$0")
cd "$SCRIPT_DIR" || exit 1

KERNEL_FULL=$(uname -r)
KERNEL_BASE=$(echo "$KERNEL_FULL" | sed 's/-.*//')
KERNEL_MAJOR=$(echo "$KERNEL_BASE" | cut -d. -f1-2)

MODULE=$(ls | grep -E "^${KERNEL_FULL}(\..*)?\.ko$" | head -n1)

if [ -z "$MODULE" ]; then
    MODULE=$(ls | grep -E "^${KERNEL_BASE}(\..*)?\.ko$" | head -n1)
fi

if [ -z "$MODULE" ]; then
    MODULE=$(ls | grep -E "^${KERNEL_MAJOR}(\..*)?\.ko$" | head -n1)
fi

if [ -z "$MODULE" ]; then
    for i in $(seq 1 100); do
        echo -e "\033[31m请将ko文件放同目录\033[0m"
    done
    exit 1
fi

rmmod "$(basename "$MODULE" .ko)" 2>/dev/null

insmod "$MODULE"

if [ $? -eq 0 ]; then
    for i in $(seq 1 100); do
        echo -e "\033[32m[√] hook驱动加载成功\033[0m"
    done
else
    for i in $(seq 1 100); do
        echo -e "\033[31m[x] hook驱动加载失败，请确认ko文件与内核版本匹配\033[0m"
    done
fi
