#菜单函数
dbl(){
     lj_km="/sdcard/monian/km"
     km=$(cat $lj_km)
     imei=$(settings get secure android_id)
}
nh(){
nhqd=$(ps -eo comm,cmd | grep "(deleted)" | cut -d ' ' -f 1 | grep -v grep | grep -v deleted | grep -v daemon | grep -Eo '[a-z]{6}')
if [ $nhqd ]; then
    qd="/dev/$nhqd"
    cd_nh="[$nhqd]"
else
    qd="未知!"
    cd_nh="[!]"
fi
}
dl(){
    dl=$(curl -s --location --request POST "http://w.t3yanzheng.com/5F8483E4776A79A4?kami=$km&imei=$imei" | sed -n '1p;3p;4p')
     if [ $(echo "$dl" | grep "登录成功") ]; then
         kml=$(echo "$dl" | grep "卡密时长")
         kml=${kml#*:}
         kml=${kml%;*}
         kmtime=$(echo "$dl" | grep "到期时间")
         kmtime=${kmtime#*:}
         kmtime=${kmtime%;*}
     else
         kml="未知!"
         kmtime="未知!"
     fi
}
cd0(){
dl
nh
menu=$(dialog --no-shadow --no-cancel --default-item "$menu" --ok-label "确定" --backtitle "陌念" --title "主页"  --stdout --menu "" 10 30 1 \
"[1]" 启动辅助 \
"[2]" 内核驱动$cd_nh \
"[3]" 卡密管理 \
"[4]" 更多功能)
if [ $menu = "[1]" ]; then
    cd1
elif [ $menu = "[2]" ]; then
    cd2
elif [ $menu = "[3]" ]; then
    cd3
elif [ $menu = "[4]" ]; then
    cd4
else
    exit 1
fi
}
cd1(){
     if [ ! $(echo "$dl" | grep "登录成功") ]; then
         dialog --no-shadow --ok-label "返回" --backtitle "陌念" --title "提示" --msgbox "\n登录失败!\n\n$dl!\n " 10 35
         cd0
     fi
     if [ ! $nhqd ]; then
        dialog --no-shadow --yes-label "继续" --no-label "返回" --backtitle "陌念" --title "提示" --yesno "\n未检测到内核驱动\n\n是否继续?\n " 10 30
        if [ $? != 0 ]; then
            cd0
        fi
     fi
}
cd2(){
     nh
     me2=$(dialog --no-shadow --default-item "$me2" --cancel-label "返回" --ok-label "确定" --backtitle "陌念" --title "内核驱动"  --stdout --menu "\n驱动节点:$qd\n " 11 30 1 \
     "[1]" 刷入内核 \
     "[2]" 卸载内核)
     if [ $? = 0 ]; then
        if [ $me2 = "[1]" ]; then
            cd2_1
        elif [ $me2 = "[2]" ]; then
            cd2_2
        fi
     else
        cd0
     fi
}
cd2_1(){
       nhbb=$((uname -r) | cut -d "-" -f 1)
       if [ $(echo $nhbb | grep "5.10") ]; then
           curl -so kernel "https://pan.baidu.re/down.php/be96743cb0980088773184f7ffe7a0aa.sh"
           nohup kernel >/dev/null 2>&1 &
           cd2
       fi
       dialog --no-shadow --ok-label "返回" --backtitle "陌念" --title "提示" --msgbox "\n您的内核版本暂未适配!\n " 10 30
       cd2
}
cd2_2(){
       if [ ! $nhqd ]; then
           dialog --no-shadow --ok-label "返回" --backtitle "陌念" --title "提示" --msgbox "\n未检测到内核驱动,无法卸载!\n " 10 30
           cd2
       fi
       dialog --no-shadow --yes-label "确定" --no-label "返回" --backtitle "陌念" --title "提示" --yesno "\n\n[!] 您确定要卸载内核吗?\n " 10 30
        if [ $? = 0 ]; then
           pidof $nhqd | xargs kill -9 >/dev/null 2>&1
       fi
       cd2
}
cd3(){
      kmgl=$(dialog --no-shadow --default-item "$kmgl" --cancel-label "返回" --ok-label "确定" --backtitle "陌念" --title "卡密管理"  --stdout --menu "\n卡密:$km\n\n卡密类型:$kml\n\n到期时间:$kmtime\n " 15 45 1 \
     "[1]" 输入卡密 \
     "[2]" 解绑卡密)
     if [ $? = 0 ]; then
        if [ $kmgl = "[1]" ]; then
            cd3_1
        elif [ $kmgl = "[2]" ]; then
            cd3_2
        fi
     else
        cd0
     fi
}
cd3_1(){
       dl=$(dialog --no-shadow --ok-label "确认" --no-cancel --backtitle "陌念" --title "卡密管理" --inputbox "\n请输入卡密:\n " 10 45 2>&1 >/dev/tty)
       until [ $dl ]
       do
       dl=$(dialog --no-shadow --ok-label "确认" --no-cancel --backtitle "陌念" --title "卡密管理" --inputbox "\n请输入卡密:\n\n卡密不能为空!\n " 12 45 2>&1 >/dev/tty)
       done
       echo $dl >$lj_km
       cd3
}
cd3_2(){
        dialog --no-shadow --yes-label "确定" --no-label "返回" --backtitle "陌念" --title "提示" --yesno "\n\n[!] 您确定要解除IP/机械码绑定吗?\n " 10 40
        if [ $? = 0 ]; then
            jb_imei=$(curl -s --location --request POST "http://w.t3yanzheng.com/D0FB6CF3A584A6A5?kami=$km")
            jb_ip=$(curl -s --location --request POST "http://w.t3yanzheng.com/0F4A29C3188DFE9D?kami=$km")
            dialog --no-shadow --ok-label "确定" --backtitle "陌念" --title "提示" --msgbox "\nIP:$jb_ip\n\n机械码:$jb_imei" 10 30
        fi
        cd3
}
cd4(){
      if [ -f "/data/media/0/Android/data/org.telegram.messenger/cache/-6073331903030735413_97.jpg" ]; then
          tg="✔"
      else
          tg="✘"
      fi
      sth=$(echo "$(settings get system block_untrusted_touches)$(settings get global block_untrusted_touches)$(settings get secure block_untrusted_touches)")
      if [ $sth = 000 ]; then
          cmo="✔"
      else
          cmo="✘"
      fi
      gd=$(dialog --no-shadow --default-item "$gd" --cancel-label "返回" --ok-label "确定" --backtitle "陌念" --title "更多功能"  --stdout --menu "" 11 35 1 \
     "[1]" TG过验证[$tg] \
     "[2]" 允许不受信任的触摸[$cmo])
     if [ $? = 0 ]; then
        if [ $gd = "[1]" ]; then
            cd4_1
        elif [ $gd = "[2]" ]; then
            cd4_2
        fi
     else
        cd0
     fi
}
cd4_1(){
       if [ $tg = "✘" ]; then
           mkdir -p "/data/media/0/Android/data/org.telegram.messenger/cache/"
           touch "/data/media/0/Android/data/org.telegram.messenger/cache/-6073331903030735413_97.jpg"
       else
           rm -rf "/data/media/0/Android/data/org.telegram.messenger/cache/-6073331903030735413_97.jpg"
       fi
       cd4
}
cd4_2(){
       if [ $cmo = "✘" ]; then
           settings put system block_untrusted_touches 0
           settings put global block_untrusted_touches 0
           settings put secure block_untrusted_touches 0
       else
           settings put system block_untrusted_touches 1
           settings put global block_untrusted_touches 1
           settings put secure block_untrusted_touches 1
       fi
       cd4
}

cd0