-- helper.lua
-- WIFI һϹ,ûЯ豸
-- 
-- Ȩ (C) 2025-2026 Punguin
--
-- ԸᷢGNU Afferoͨù֤֤ĵ3ѡģκκİ汾·/޸
-- ķϣáûκα֤ûı֤ķַϣõģûκα֤û·ʺĳһضĿĵı֤ μ GNU Afferoͨù֤˽ϸڡ
-- ӦѾյһGNU Afferoͨù֤ĸ ûУμ<https://www.gnu.org/licenses/>
--
-- ϵǣ3618679658@qq.com
-- ChatGPTЭд


-- ñն붨崰ڴС
os.execute("title WIFI(ChatGPTЭд)                      ǰ汾: 5.2        QQ:3618679758ٷQQȺ:725700912 ")
os.execute("mode con: cols=113 lines=32")

-- ⲿ
local path = require("lua\\path") -- ·
local colors = require("lua\\colors") -- ANSIɫ
local delay = require("lua\\sleep") -- ʱ

-- ȡűǰĿ¼
local script_dir = debug.getinfo(1, "S").source:match("@(.*[/\\])")

-- ADBؽ
local function exec_command(cmd)       -- cmommandͱǩ,ʹcmd
    local file = io.popen(cmd)         -- cmd
    local output = file:read("*all")   -- All
    file:close()                       -- ض
    return output                      -- 
end

-- ADB״̬
local function check_adb_status()
    local adb_path = path.adb -- adb.exe
    --  adb devices ȡӵ豸б
    local adb_output = exec_command(adb_path .. " devices 2>nul")

    -- ǷЧ豸Ϣ
    local has_device = false        -- ƥdevice
    local is_offline = false        -- ƥoffline
    for line in adb_output:gmatch("[^\r\n]+") do   -- 趨ƥ
        if line:match("device$") then      -- ƥdevice
            has_device = true              -- ,deviceӦ
        elseif line:match("offline") then  -- ƥoffline
            is_offline = true              -- ,deviceݲoffline
        end
    end

    -- ݼ趨ıɫ
    if has_device and not is_offline then
        print(colors.yellow .. colors.bright .. "豸״̬" .. colors.reset .. colors.green .. colors.bright .."" .. colors.reset)
    elseif is_offline then
        print(colors.yellow .. colors.bright .. "豸״̬" .. colors.reset .. colors.green ..  colors.bright .."(".. colors.reset .. colors.red .."" .. colors.reset .. colors.green ..  colors.bright ..")".. colors.reset)
    else
        print(colors.yellow .. colors.bright .. "豸״̬" .. colors.reset .. colors.red .. "豸" .. colors.reset)
    end
end

-- nv ѯ
function get_nv_value(param)
	local command = "bin\\adb shell nv get " .. param
	local handle = io.popen(command)
	local result = handle:read("*a")
	handle:close()

	local value = result:gsub("%s+", "")
	return value
end

-- װ鴮ӵĺ
function check_serial()
    -- ϵͳǷпõĴ
    local function is_serial_port_connected()
        for i = 1, 256 do
            local com_port = "\\\\.\\COM" .. i
            local file = io.open(com_port, "r")
            if file then
                file:close()
                return true -- 򿪳ɹ˵д
            end
        end
        return false -- ûд򿪳ɹ˵ûд
    end

    -- 
    if is_serial_port_connected() then
	    print(colors.yellow .. colors.bright .. "״̬(AT)" .. colors.reset .. colors.green .. colors.bright .."" .. colors.reset)
    else
	    print(colors.yellow .. colors.bright .. "״̬(AT)" .. colors.reset .. colors.red .. "豸" .. colors.reset)
    end
end

-- һȡƶ˰汾Ϣ
local function check_version()
    local local_version = "5.2"  -- 滻Ϊصİ汾
    local temp_version_file = "version.ini" -- ʱ汾ļ
    
    -- Ӱ汾ļȡƶ˰汾
    local function get_version_from_html(file_path)
        local file = io.open(file_path, "r")
        if not file then
            return nil
        end
        for line in file:lines() do
            local version = line:match("%d+%.%d+[%w%-]*") -- "%d.%d"Ϊ汾Ÿʽ,Ӧİ汾ΪX.X(ָʽ)
            if version then
                file:close()
                return version
            end
        end
        file:close()
        return nil
    end
    
    local cloud_version = get_version_from_html(temp_version_file)
    --os.remove(temp_version_file) -- ɾʱ汾ļ(4.5汾ʼ,øָ)

    -- 汾Ϣ
    if cloud_version then
        print(colors.bright .."°汾: " .. cloud_version .. "  ǰ汾: " .. local_version .. colors.reset)
    else
        print(colors.bright .."޷ȡƶ˰汾" .. colors.reset)
    end
end

-- Ƿ adb 豸
local function is_adb_device_connected()
	local check = io.popen("bin\\adb get-state")
	local state = check:read("*a")
	check:close()

	if not state:match("device") then -- û豸ʱ
	    print()
		print(colors.red .."[] δ⵽ADB豸豸ԡ".. colors.reset)
		print(colors.green .."ʾ:豸ӵģʽ豸adbҲǲá".. colors.reset)
		print()
		io.read()  -- ȡû
		os.execute("bin\\lua54 lua\\helper.lua")
		io.read()  -- ȡû
	end
end

local function mtd_check() --ʾ豸MTD״̬
        print(colors.cyan .. colors.bright .. "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" .. colors.reset)
        print("Ϊ豸MTD״̬")
        print()
        os.execute("bin\\adb shell cat /proc/mtd")
        print()
		print(colors.cyan .. colors.bright .. "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" .. colors.reset)
        print("һ,mtd4:'rootfs' ")
		print(" Сֻmtd4:'imagefs'")
		print("  Ŀǰ֧mtd4:'rootfs'Ļ")
		print("   ڿܿmtd5֧")
		print()
		os.execute("pause")
end

local function install_drive() --һװ
  print(colors.cyan .. colors.bright .. "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" .. colors.reset)
  print("ѡҪװ(ûȫ)")
  print()
  print(colors.cyan .. colors.bright .. "           1.ͨð׿ADB      2.΢      3.ԶASRר       4.ϹSPDͨ" .. colors.reset)
  print()
  print(colors.red .. colors.bright .."ʾ:Ϊ밲,װֻᵯcmdװɹֱӹرա".. colors.reset)
  print()
  io.write(colors.green .. "ֲ Enter : " .. colors.reset)
  local drive_selection = io.read()
    if drive_selection == "1" then
     os.execute("start file\\drive\\vivo-drive.exe")
    elseif drive_selection == "2" then
     os.execute("start file\\drive\\ZXIC_Develop_Driver.exe")
	 print()
	 io.write(colors.green .. "ʼװ......" .. colors.reset)
	 io.read()
     os.execute("start file\\drive\\zxicser.exe")
    elseif drive_selection == "3" then
     os.execute("start file\\drive\\Quectel_LTE_Windows_USB_Driver.exe")
    elseif drive_selection == "4" then
     os.execute("start file\\drive\\SPD_Driver\\DriverSetup.exe")
    end
end

local function set_adb()   -- 豸adb(3.21汾,4.0)
  print(colors.cyan .. colors.bright .. "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" .. colors.reset)
  print()
  -- ûIPַΪʱipAddress
  print(colors.red .. colors.bright .. "!豸WIFI,[Ц]" .. colors.reset)
  print()
  print()
  io.write(colors.green .. "豸WEBַ( 192.168.100.1): "  .. colors.red .. colors.bright)
  local ipAddress = io.read()
  print(colors.cyan .. colors.bright .. "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" .. colors.reset)
  -- ӡѡ˵
  print()
  print(colors.cyan .. colors.bright .."ʹСʿ:".. colors.reset .. colors.green .. "豸ɾadbd,¿adbȻ޷ʹ״̬(ģʽ),뿴ҳ豸״̬")
  print()
  print(colors.cyan .. colors.bright .." =------".. colors.magenta .. colors.bright .."ѡģʽ" .. colors.cyan .. colors.bright .."------------------------------------------------------------------------------------------------=")
  print(colors.cyan .. colors.bright .." =                                                                                                              =")
  print(colors.cyan .. colors.bright .." =    ".. colors.reset .. colors.yellow .."1. ģʽ(ADB+AT+)     2. ˿ģʽ(AT)       3. ϵͳģʽ()        4. رģʽ       ".. colors.cyan ..colors.bright .."=")
  print(colors.cyan .. colors.bright .." =                                                                                                              =")
  print(colors.cyan .. colors.bright .." =    ".. colors.reset .. colors.yellow .."5. Remoרõģʽ(ADB+AT+)                                                                          ".. colors.cyan ..colors.bright .."=")
  print(colors.cyan .. colors.bright .." =                                                                                                              =")
  print(colors.cyan .. colors.bright .." =--------------------------------------------------------------------------------------------------------------=")
  print()
  -- ûѡӦĲʱ
  io.write(colors.green .. "ֲ Enter : ".. colors.red .. colors.bright)
  local adb_selection = io.read()
  -- ɸѡݲִжӦ
    if adb_selection == "1" then
      print(colors.blue .. colors.bright)
      os.execute('bin\\curl "http://'..ipAddress..'/goform/goform_set_cmd_process?goformId=SET_DEVICE_MODE&debug_enable=2"')
      os.execute('bin\\curl "http://'..ipAddress..'/goform/goform_set_cmd_process?goformId=SET_DEVICE_MODE&debug_enable=1"')
      os.execute('bin\\curl "http://'..ipAddress..'/reqproc/proc_post?goformId=SET_DEVICE_MODE&debug_enable=1"')
	  -- 5.1Qrzl
	  print()
      os.execute('bin\\curl "http://'..ipAddress..'/reqproc/proc_post?goformId=SET_DEVICE_MODE&debug_enable=1&password=coolfish666@Qiruizhilian20241202"')
	  print()
      os.execute('bin\\curl "http://'..ipAddress..'/reqproc/proc_post?goformId=SET_DEVICE_MODE&debug_enable=1&password=xscmadmin888@Qiruizhilian20241202"')
	  print()
      os.execute('bin\\curl "http://'..ipAddress..'/reqproc/proc_post?goformId=SET_DEVICE_MODE&debug_enable=1&password=MM888@Qiruizhilian20241202"')
	  print()
      os.execute('bin\\curl "http://'..ipAddress..'/reqproc/proc_post?goformId=SET_DEVICE_MODE&debug_enable=1&password=159258@Qiruizhilian20241202"')
	  print(colors.green .. colors.bright .."\nԺ豸(5)....." .. colors.blue .. colors.bright)
      delay.sleep(5)
      os.execute('bin\\curl "http://'..ipAddress..'/reqproc/proc_post?goformId=REBOOT_DEVICE"')
      os.execute('bin\\curl "http://'..ipAddress..'/goform/goform_set_cmd_process?goformId=REBOOT_DEVICE"')
      print(colors.green .. colors.bright .."\nɣԺ󷵻" .. colors.reset)
      delay.sleep(3)
    elseif adb_selection == "2" then
      print(colors.blue .. colors.bright)
      os.execute('bin\\curl "http://'..ipAddress..'/goform/goform_set_cmd_process?goformId=SET_DEVICE_MODE&debug_enable=2"')
      print(colors.green .. colors.bright .."\nԺ豸(5)....." .. colors.blue .. colors.bright)
      delay.sleep(5)
      os.execute('bin\\curl "http://'..ipAddress..'/reqproc/proc_post?goformId=REBOOT_DEVICE"')
      os.execute('bin\\curl "http://'..ipAddress..'/goform/goform_set_cmd_process?goformId=REBOOT_DEVICE"')
      print(colors.green .. colors.bright .."\nɣԺ󷵻" .. colors.reset)
      delay.sleep(3)
    elseif adb_selection == "3" then
      print(colors.blue .. colors.bright) 
      os.execute('bin\\curl "http://'..ipAddress..'/goform/goform_set_cmd_process?goformId=SET_DEVICE_MODE&debug_enable=3"')
      print(colors.green .. colors.bright .."\nԺ豸(5)....." .. colors.blue .. colors.bright)
      delay.sleep(5)
      os.execute('bin\\curl "http://'..ipAddress..'/reqproc/proc_post?goformId=REBOOT_DEVICE"')
      os.execute('bin\\curl "http://'..ipAddress..'/goform/goform_set_cmd_process?goformId=REBOOT_DEVICE"')
      print(colors.green .. colors.bright .."\nɣԺ󷵻" .. colors.reset)
      delay.sleep(3)
    elseif adb_selection == "4" then
      print(colors.blue .. colors.bright)
      os.execute('bin\\curl "http://'..ipAddress..'/goform/goform_set_cmd_process?goformId=SET_DEVICE_MODE&debug_enable=0"')
      os.execute('bin\\curl "http://'..ipAddress..'/reqproc/proc_post?goformId=ID_SENDAT&at_str_data=AT%2BZMODE%3D0"')
	  print(colors.green .. colors.bright .."\nԺ豸(5)....." .. colors.blue .. colors.bright)
      delay.sleep(5)
      os.execute('bin\\curl "http://'..ipAddress..'/reqproc/proc_post?goformId=REBOOT_DEVICE"')
      os.execute('bin\\curl "http://'..ipAddress..'/goform/goform_set_cmd_process?goformId=REBOOT_DEVICE"')
      print(colors.green .. colors.bright .."\nɣԺ󷵻" .. colors.reset)
      delay.sleep(3)
    elseif adb_selection == "5" then -- ⲿֳϮufitool
	  print(colors.red .. colors.bright .."\n\n:÷ʽԴRemoڲԱ" .. colors.blue .. colors.bright)
	  print(colors.red .. colors.bright .."ڵĴǰİ汾(246֮ǰ),汾ƻ" .. colors.blue .. colors.bright)
	  print("\n")
	  print(colors.green .. colors.bright .."\nϵͳ....." .. colors.blue .. colors.bright)
	  delay.sleep(2)
	  print(colors.blue .. colors.bright)
	  os.execute('bin\\curl "http://'..ipAddress..'/reqproc/proc_post?goformId=LOGIN&password=cmVtb19zdXBlcl9hZG1pbl8yMjAx"')
	  os.execute('bin\\curl "http://'..ipAddress..'/reqproc/proc_post?goformId=LOGIN&password=YWRtaW4%3D"')
	  print(colors.green .. colors.bright .."\n⵽ֹ,ƹ....." .. colors.blue .. colors.bright)
	  delay.sleep(3)
      os.execute('bin\\curl "http://'..ipAddress..'/reqproc/proc_post?goformId=REMO_SIM_SELECT_R1865&isTest=false&sim_option_id=3&select_sim_mode=1"')
	  print(colors.green .. colors.bright .."\nҵʱAPi,ڷٳdebug mode....." .. colors.blue .. colors.bright)
	  delay.sleep(2)
      os.execute('bin\\curl "http://'..ipAddress..'/reqproc/proc_post?goformId=SysCtlUtal&action=System_MODE&debug_enable=1"')
	  delay.sleep(2)
      os.execute('bin\\curl "http://'..ipAddress..'/reqproc/proc_post?goformId=ID_SENDAT&at_str_data=AT%2BZMODE%3D1"')
	  delay.sleep(2)
      os.execute('bin\\curl "http://'..ipAddress..'/reqproc/proc_post?goformId=SET_DEVICE_MODE&debug_enable=1"')
      print(colors.green .. colors.bright .."\nԺ豸(5)....." .. colors.blue .. colors.bright)
      delay.sleep(5)
      os.execute('bin\\curl "http://'..ipAddress..'/reqproc/proc_post?isTest=false&goformId=RESTORE_FACTORY_SETTINGS"')
      print(colors.green .. colors.bright .."\nɣԺ󷵻" .. colors.reset)
      delay.sleep(3)
	elseif About_stealing == "stealing" then
	  A = "Remoδ͵Ufitool"
	  B = "ܲÿǼεʹû"
	  C = "ϣոԭҰ,½"
	  D = "͵Ϊȷʵ,Ҳܲ"
	  E = "֮ϣոԭ,δϵҰ"
	  print ("Test,remo adbd By ufitool")
    end
 end
 
 local intype = get_nv_value("zcgmi")
 local fota_platform = get_nv_value("fota_platform")
 local function ufi_nv_set() --ͨñ׼NVŻ豸
  print(colors.cyan .. colors.bright .. "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" .. colors.reset)
  print()
  if intype ~= "" then
	  print(colors.yellow .. colors.bright .. "豸: ".. colors.blue .. intype .. colors.reset)
      print()
	else
	  print()
  end
  print(colors.cyan .. colors.bright .."ʹСʿ:".. colors.reset .. colors.green .. "ȥصʱ豸jffs2ϵͳô߻᳢ԽԶس")
  print()
  print(colors.cyan .. colors.bright .." =------".. colors.magenta .. colors.bright .."ѡģʽ" .. colors.cyan .. colors.bright .."------------------------------------------------------------------------------------------------=")
  print(colors.cyan .. colors.bright .." =                                                                                                              =")
  print(colors.cyan .. colors.bright .." =    ".. colors.reset .. colors.yellow .."     1. SZXFͨŻ       2.ZTEŻ(SZXK)      3.ͨŻ(ALK)       4.V1.3V1.2          ".. colors.cyan ..colors.bright .."=")
  print(colors.cyan .. colors.bright .." =                                                                                                              =")
  print(colors.cyan .. colors.bright .." =    ".. colors.reset .. colors.yellow .."                                                                                                          ".. colors.cyan ..colors.bright .."=")
  print(colors.cyan .. colors.bright .." =                                                                      Ժ½ָ֧豸,ڴota    =")
  print(colors.cyan .. colors.bright .." =--------------------------------------------------------------------------------------------------------------=")
  print()
  -- ûѡӦĲʱ
  io.write(colors.green .. "ֲ Enter : ".. colors.red .. colors.bright)
  local selection = io.read()
  print(colors.reset)
  -- ɸѡݲִжӦ
    if selection == "1" then
	is_adb_device_connected()
	print()
	print("ضд")
	os.execute("bin\\adb shell mount -o remount,rw /")
	print()
	print("رղ۸")
	os.execute("bin\\adb shell nv set fota_updateMode=0")
	os.execute("bin\\adb shell nv set fota_updateIntervalDay=365")
	os.execute("bin\\adb shell nv set fota_platform=Punguin")
	os.execute("bin\\adb shell nv set fota_token_rs=0")
	os.execute("bin\\adb shell nv set fota_version_delta_id=")
	os.execute("bin\\adb shell nv set fota_version_delta_url=")
	os.execute("bin\\adb shell nv set fota_version_name=")
	os.execute("bin\\adb shell nv set fota_upgrade_result_internal=")
	os.execute("bin\\adb shell nv set fota_oem=QEJ")
	print("۸Զ")
	os.execute("bin\\adb shell rm -rf /bin/terminal_mgmt")
	os.execute("bin\\adb shell rm -rf /sbin/ip_ratelimit.sh")
	os.execute("bin\\adb shell nv set traffic_mgmt_enable=0")
	os.execute("bin\\adb shell nv set terminal_mgmt_enable=0")
	os.execute("bin\\adb shell nv set tr069_enable=0")
	os.execute("bin\\adb shell nv set enable_lpa=0")
	os.execute("bin\\adb shell nv set lpa_trigger_host=info.punguin.cn")
	os.execute("bin\\adb shell nv set os_url=http://punguin.cn/")
	os.execute("bin\\adb shell nv set TM_SERVER_NAME=reportinfo.punguin.cn")
	os.execute("bin\\adb shell nv set HOST_FIELD=reportinfo.punguin.cn")
	print("ǿ")
	os.execute("bin\\adb shell nv set sim_auto_switch_enable=0")
	os.execute("bin\\adb shell nv set sim_switch=1")
	os.execute("bin\\adb shell nv set sim_unlock_code=az952#")
	os.execute("bin\\adb shell nv set sim_default_type=1")
	os.execute("bin\\adb shell nv set band_select_enable=1")
	os.execute("bin\\adb shell nv set dns_manual_func_enable=1")
	os.execute("bin\\adb shell nv set tr069_func_enable=1")
	os.execute("bin\\adb shell nv set ussd_enable=1")
	os.execute("bin\\adb shell nv set pdp_type=IPv4v6")
	os.execute("bin\\adb shell nv set zcgmi=SZXF-Punguin")
	print("NV")
	os.execute("bin\\adb shell nv save")
	print(colors.green .. colors.bright .."nv༭ѱ".. colors.reset)
	print()
	print(colors.blue .."ڸ豸ˮӡ".. colors.reset)
	os.execute([[bin\\adb shell "echo 'copyright = 豸 &copy; Punguin ޸' >> /etc_ro/web/i18n/Messages_zh-cn.properties"]])
	os.execute([[bin\\adb shell "echo 'copyright = Software by: &copy; Penguin Revise' >> /etc_ro/web/i18n/Messages_en.properties"]])
	os.execute([[bin\\adb shell "echo 'nv set cr_version=SZXF-Punguin_P001-20250601 &' >> /etc/rc"]])
	print(colors.green .. colors.bright .."Read-only file system".. colors.reset)
	print()
	print()
	print()
	print()
	print()
	print(colors.red .."޸ɣָᶪʧģҪָ".. colors.reset)
	print()
	os.execute("pause")  -- ȴû
	elseif selection == "2" then
	  is_adb_device_connected()
	        print(colors.blue .. colors.bright .."ضд..." .. colors.reset)
            os.execute("bin\\adb shell mount -o remount,rw /")
            --  /sbin/ д test ļ
		    print()
	     	print(colors.blue .. colors.bright .."ļϵͳ..." .. colors.reset)
            local createFileCmd = "bin\\adb shell touch /sbin/test 2>&1" -- 
            local handle = io.popen(createFileCmd)
            local result = handle:read("*a")
            handle:close()

            -- Ƿ"Read-only"
            if result:find("Read") then
		       print(colors.red .. "豸ϵͳֻ,볢Ա" .. colors.reset)
			   print()
			   os.execute("pause")
            else
            -- ޸豸
			--os.execute("pause") -- ʱʹ,ֹ޸
			print(colors.green .. colors.bright .."ѹظĿ¼Ϊɶдֹͣҷ...".. colors.reset)
			os.execute("bin\\adb shell killall fota_Update")
			os.execute("bin\\adb shell killall fota_upi")
			os.execute("bin\\adb shell killall zte_mqtt_sdk &")
			print()
			print(colors.green .. colors.bright .."ѹرն".. colors.reset)
			print()
			print(colors.yellow .."Ż豸nv...".. colors.reset)
			os.execute("bin\\adb shell nv set mqtt_syslog_level=0")
			os.execute("bin\\adb shell nv set dm_enable=0")
			os.execute("bin\\adb shell nv set mqtt_enable=0")
			os.execute("bin\\adb shell nv set tc_enable=0")
			os.execute("bin\\adb shell nv set tc_downlink=")
			os.execute("bin\\adb shell nv set tc_uplink=")
			os.execute("bin\\adb shell nv set tr069_enable=0")
			os.execute("bin\\adb shell nv set fota_updateMode=0")
			os.execute("bin\\adb shell nv set fota_version_delta_id=")
			os.execute("bin\\adb shell nv set fota_version_delta_url=")
			os.execute("bin\\adb shell nv set fota_version_name=")
			os.execute("bin\\adb shell nv set fota_upgrade_result_internal=")
			os.execute("bin\\adb shell nv save")
			print(colors.green .. colors.bright .."nv༭ѱ".. colors.reset)
			print()
	        print(colors.blue .."ڸ豸ˮӡ".. colors.reset)
			os.execute([[bin\\adb shell "echo 'copyright = 豸 &copy; Punguin ޸' >> /etc_ro/web/i18n/Messages_zh-cn.properties"]])
			os.execute([[bin\\adb shell "echo 'copyright = Software by: &copy; Penguin Revise' >> /etc_ro/web/i18n/Messages_en.properties"]])
			os.execute([[bin\\adb shell "echo 'nv set cr_version=SZXK-Punguin_P049U-20250601 &' >> /etc/rc"]])
			print(colors.green .. colors.bright .."Read-only file system".. colors.reset)
			print()
			print(colors.yellow .."޸豸ļ".. colors.reset)
			os.execute("bin\\adb push file\\gsmtty /bin")
			os.execute('bin\\adb shell "chmod +x /bin/gsmtty"')
			os.execute("bin\\adb shell gsmtty AT+ZCARDSWITCH=0")
			os.execute("bin\\adb push file\\hosts /etc/hosts")
			os.execute("bin\\adb shell chmod +x /etc/hosts")
			os.execute("bin\\adb shell rm -r -rf /sbin/tc_tbf.sh")
			os.execute("bin\\adb push file\\tc_tbf.sh /sbin/tc_tbf.sh")
            os.execute("bin\\adb shell rm -rf /sbin/start_update_app.sh")
            os.execute("bin\\adb shell rm -rf /bin/fota_Update")
            os.execute("bin\\adb shell rm -rf /bin/fota_upi")
			os.execute([[bin\\adb shell "echo 'killall zte_de &' >> /etc/rc"]])
            os.execute([[bin\\adb shell "echo 'killall ztede_timer &' >> /etc/rc"]])
            os.execute([[bin\\adb shell "echo 'killall zte_mqtt_sdk &' >> /etc/rc"]])
			print()
			print(colors.yellow .."ʱļ...".. colors.reset)
			os.execute("bin\\adb shell rm -r -rf /bin/miniupnp")
			os.execute("bin\\adb shell rm -r -rf /bin/gsmtty")
			os.execute("bin\\adb shell reboot")
			print()
			print(colors.green .. colors.bright ..",ȴ豸".. colors.reset)
	        print()
	        print()
	        print()
	        print()
	        os.execute("pause")  -- ȴû
		end
	elseif selection == "3" then
		-- ÷װ
		local function run(cmd)
			os.execute(cmd)
		end

		local function adb(cmd)
			run("bin\\adb " .. cmd)
		end

		local function ateer(cmd)
			run("bin\\ATeer " .. cmd)
		end

		--  ADB ״̬
		local function get_adb_state()
			local handle = io.popen("bin\\adb devices 2>nul")
			local result = handle:read("*a")
			handle:close()

			local serial, state = result:match("(%d+%S*)%s+(%S+)")
			if serial and state then
				return state
			else
				return nil
			end
		end

		--  adbd
		local function wake_adb()
			print("Ի豸 ADB...")
			ateer("at+shell=adbd")
		end

		-- ϵͳǷΪֻ
		local function is_system_readonly()
			local tmp_output_file = "adb_tmp.txt"
			adb("shell mount -o remount,rw /")
			run('bin\\adb shell "touch /sbin/test" 2>&1 > ' .. tmp_output_file)

			local file = io.open(tmp_output_file, "r")
			if not file then
				print("޷ȡʱļ")
				return true -- ʱĬֻ
			end

			local output = file:read("*a")
			file:close()
			os.remove(tmp_output_file)

			return output:lower():match("read") ~= nil
		end

		-- ִֻϵͳĴ߼
		local function handle_readonly()
		  print()
			print(colors.green .. colors.bright .."ϵͳΪִֻֻϵͳר...".. colors.reset)
			print(colors.yellow .."Ż豸nv...".. colors.reset)
			adb("shell nv set dm_enable=0")
			adb("shell nv set mqtt_enable=0")
			adb("shell nv set tc_enable=0")
			adb("shell nv set tc_downlink=")
			adb("shell nv set tc_uplink=")
			adb("shell nv set fota_updateMode=0")
			adb("shell nv set fota_version_delta_id=")
			adb("shell nv set fota_version_delta_url=")
			adb("shell nv set fota_version_name=")
			adb("shell nv set fota_upgrade_result_internal=")
			adb("shell nv set fl_autoswitchsim=0")
			adb("shell nv set alk_sim_select=0")
			adb("shell nv set path_sh=/etc_rw/sbin")
			adb("shell nv save")
			print(colors.green .. colors.bright .."nv༭ѱ".. colors.reset)
			print()
			adb("shell mkdir -p /etc_rw/sbin")
			adb("shell cp /sbin/*.sh /etc_rw/sbin/")
			print(colors.yellow .."޸豸ļ".. colors.reset)
			adb([[shell "echo 'killall iccid_check' >> /etc_rw/sbin/global.sh"]])
			adb([[shell "echo 'killall mqtt_client' >> /etc_rw/sbin/global.sh"]])
			adb([[shell "echo 'killall vsim' >> /etc_rw/sbin/global.sh"]])
			adb([[shell "echo 'killall rmc' >> /etc_rw/sbin/global.sh"]])
			adb("shell reboot")
			print()
			print()
			print(colors.red .."޸ɣָᶪʧģҪָ".. colors.reset)
			os.execute("pause")  -- ȴû
		end

		-- ִпɶдϵͳĴ߼
		local function handle_rw()
			print(colors.green .. colors.bright .."ϵͳɶдִпɶдϵͳר...".. colors.reset)
			print(colors.yellow .."Ż豸nv...".. colors.reset)
			adb([[shell "echo 'tc_enable=0' >> /etc_ro/default/default_parameter_sys"]])
			adb([[shell "echo 'alk_sim_select=0' >> /etc_ro/default/default_parameter_user"]])
			adb([[shell "echo 'fota_updateMode=0' >> /etc_ro/default/default_parameter_user"]])
			adb("shell nv set tc_enable=0")
			adb("shell nv setro alk_server=0.1.2.3")
			adb("shell nv save")
			print(colors.green .. colors.bright .."nv༭ѱ".. colors.reset)
			print(colors.blue .."ڸ豸ˮӡ".. colors.reset)
			adb([[shell "echo 'copyright = 豸 &copy; Punguin ޸' >> /etc_ro/web/i18n/Messages_zh-cn.properties"]])
			adb([[shell "echo 'copyright = Software by: &copy; Penguin Revise' >> /etc_ro/web/i18n/Messages_en.properties"]])
			adb([[shell "echo 'nv set cr_version=ALK-Punguin_P049U-20250813 &' >> /etc/rc"]])
			print()
			print(colors.yellow .."޸豸ļ".. colors.reset)
			adb("shell rm -rf bin/iccid_check")
			adb("shell rm -rf bin/mqtt_client")
			adb("shell rm -rf bin/vsim")
			adb("shell rm -rf bin/rmc")
			adb("shell rm -rf /sbin/fl_set_iptables.sh")
			print(colors.red .."޸ɣѹ̻豸Իָ".. colors.reset)
			os.execute("pause")  -- ȴû
		end

		-- ϵͳɶдԲִд
		local function check_system_rw()
			print(colors.yellow .."ڼ豸ϵͳǷΪֻ...".. colors.reset)
			if is_system_readonly() then
				print(colors.green .. colors.bright .."ϵͳΪֻ".. colors.reset)
				print()
				handle_readonly()
			else
				print(colors.green .. colors.bright .."ϵͳɶд".. colors.reset)
				print()
				handle_rw()
			end
		end

		-- ߼ִ
		local function main()
			local state = get_adb_state()

			if not state then
				print(colors.red .."δ⵽κ豸ȿ ADB 豸".. colors.reset)
				run("pause")
				return
			end

			if state == "device" then
				print(colors.green .. colors.bright .."豸ӡ".. colors.reset)
				print()
				check_system_rw()
				run("pause")
				return
			end

			if state == "offline" then
				print(colors.yellow .."⵽豸״̬Ϊ offline".. colors.reset)
				io.write(colors.cyan .. colors.bright .."Ƿ豸 ADB(y/n): ".. colors.reset)
				local choice = io.read()
				if choice:lower() == "y" then
					wake_adb()
					local new_state = get_adb_state()
					if new_state == "device" then
						print(colors.green .. colors.bright .."豸ѳɹߣADB ".. colors.reset)
						check_system_rw()
					else
						print(colors.red .."豸Ϊ offlineҪֶ豸".. colors.reset)
					end
				else
					print(colors.yellow .."豸δκ޸ġ".. colors.reset)
				end
				run("pause")
				return
			end

			print(colors.yellow .."δ֪豸״̬: " .. state .. colors.reset)
			run("pause")
		end

		main()
	elseif selection == "4" then
	is_adb_device_connected()
	        print(colors.blue .. colors.bright .."ضд..." .. colors.reset)
            os.execute("bin\\adb shell mount -o remount,rw /")
            --  /sbin/ д test ļ
		    print()
	     	print(colors.blue .. colors.bright .."ļϵͳ..." .. colors.reset)
            local createFileCmd = "bin\\adb shell touch /sbin/test 2>&1" -- 
            local handle = io.popen(createFileCmd)
            local result = handle:read("*a")
            handle:close()

            -- Ƿ"Read-only"
            if result:find("Read") then
		       print(colors.red .. "豸ϵͳֻ,볢Ա" .. colors.reset)
			   print()
			   os.execute("pause")
            else
            -- ޸豸
			print("\n\n")
			print(colors.red .. colors.bright .."ʹ֪:")
			print()
			print("Ŀǰð汾ڸGX009Դ߿籦".. colors.reset .. "SNΪXFWP25ͷ豸")
			print()
			print(colors.red .. colors.bright .."ҵװǽֹʹõģʹñҵ豸޸ǲĲκε")
			print()
			print("ڸйٷ˵Ľֹ޸豸Ϊѹ豸Ȩе豸(ڸ豸".. colors.reset .. "Ըб".. colors.red .. colors.bright ..")߸ȫѣ踶ѣӯΪ".. colors.reset)
			print("\n\n")
			io.write(colors.green .. "豸ϵSN Enter : ".. colors.red .. colors.bright)
			io.read()
			print(colors.green .. colors.bright .."ѹظĿ¼Ϊɶдֹͣҷ...".. colors.reset)
			os.execute("bin\\adb shell killall iccid_check")
			os.execute("bin\\adb shell killall goahead")
			os.execute("bin\\adb shell killall zte_mifi &")
			print()
			print(colors.green .. colors.bright .."ѹرն".. colors.reset)
			print()
	        print(colors.blue .."ڸϵͳ汾".. colors.reset)
			os.execute([[bin\\adb shell "echo 'nv set cr_version=ALK-Punguin_P012-20250814 &' >> /etc/rc"]])
			print()
			print(colors.yellow .."޸豸ļ".. colors.reset)
			os.execute("bin\\adb shell rm -rf /sbin/zte_mifi")
			os.execute("bin\\adb shell rm -rf /bin/iccid_check")
			os.execute("bin\\adb shell rm -rf /bin/goahead")
			os.execute("bin\\adb shell rm -rf -r /etc_ro/web")
			os.execute("bin\\adb shell rm -rf -r /etc_ro/mmi")
			os.execute("bin\\adb shell rm -r -rf /sbin/tc_tbf.sh")
            os.execute("bin\\adb shell rm -rf /sbin/start_update_app.sh")
			print(colors.red .."豸ںѱɾ벻Ҫػ豸".. colors.reset)
			print(colors.red .."豸ںѱɾ벻Ҫػ豸".. colors.reset)
			print(colors.red .."豸ںѱɾ벻Ҫػ豸".. colors.reset)
			print()
			print(colors.green .."ڰװںļ벹...".. colors.reset)
			os.execute("bin\\adb push file\\gx009\\zte_mifi /sbin/zte_mifi")
			os.execute("bin\\adb push file\\gx009\\goahead /bin/goahead")
			os.execute("bin\\adb push file\\gx009\\web.zip /tmp/web.zip")
			os.execute("bin\\adb push file\\gx009\\mmi.zip /tmp/mmi.zip")
			os.execute("bin\\adb push file\\gsmtty /bin/gsmtty")
			os.execute("bin\\adb push file\\at_web\\at_server /bin/at_server")
			os.execute("bin\\adb push file\\tc_tbf.sh /sbin/tc_tbf.sh")
			print("\n")
			print(colors.yellow .."ļѴɣнѹ".. colors.reset)
			os.execute('bin\\adb shell "unzip /tmp/web.zip -d /etc_ro/"')
			os.execute('bin\\adb shell "unzip /tmp/mmi.zip -d /etc_ro/"')
			print("\n")
			print(colors.blue .."ļȨ...".. colors.reset)
			os.execute('bin\\adb shell "chmod +x /sbin/zte_mifi"')
			os.execute('bin\\adb shell "chmod +x /bin/goahead"')
			os.execute('bin\\adb shell "chmod +x /etc_ro/web/*"')
			os.execute('bin\\adb shell "chmod +x /etc_ro/mmi/*"')
			os.execute('bin\\adb shell "chmod +x /bin/at_server"')
			os.execute('bin\\adb shell "chmod +x /bin/gsmtty"')
			print(colors.yellow .."öʱ...".. colors.reset)
			os.execute([[bin\\adb shell "echo 'at_server &' >> /etc/rc"]])
			print()
			print(colors.green .."лÿ...".. colors.reset)
			os.execute("bin\\adb shell gsmtty AT+ZCARDSWITCH=0")
			print()
			print(colors.yellow .."ʱļ...".. colors.reset)
			os.execute("bin\\adb shell rm -r -rf /bin/gsmtty")
			os.execute("bin\\adb shell reboot")
			print()
			print(colors.green .. colors.bright ..",ȴ豸".. colors.reset)
	        print()
	        print()
	        print()
	        print()
	        os.execute("pause")  -- ȴû
	end
  end
end

-- ӡѡ
local function uisoc()
    print(colors.cyan .. colors.bright .. "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" .. colors.reset)
    print("\n")
	print()
    print(colors.yellow .. "       1.ѯۻSN" .. colors.reset) 
	print()
    print(colors.blue .. "          2.޸豸" .. colors.reset) 
	print()
    print(colors.cyan .. "             3.ResearchDownload" .. colors.reset) 
	print()
    print(colors.green .. "                4.spd_dump" .. colors.reset) 
	print()
    print(colors.white .. "                   5.п" .. colors.reset) 
	print()
	print("»س")
	print()
	print()
	print()
	print()
	io.write(colors.green .. "벢Enter: " .. colors.reset)
        local choice111 = io.read()
        if choice111 == "1" then
            os.execute("explorer file\\tool\\SNѯ")
        elseif choice111 == "2" then
		    os.execute("explorer file\\tool\\Pandora_R22.20.1701")
        elseif choice111 == "3" then
		    os.execute("explorer file\\tool\\ResearchDownload")
        elseif choice111 == "4" then
		    os.execute("explorer file\\tool\\spd_dump")
        elseif choice111 == "5" then
		    print()
            print(colors.red .. colors.bright .. "!豸WIFI,[Ц]" .. colors.reset)
            print()
            print()
		    io.write(colors.green .. "豸WEBַ( 192.168.100.1): "  .. colors.red .. colors.bright)
             local ipAddress = io.read()
			 os.execute('start "" "http://'..ipAddress..'//postesim?postesim=%7B%22esim%22:0%7D"')
		else
            os.execute("bin\\lua54 lua\\helper.lua")
        end
end

 local function mifi_Studio() --MifiStudioȡ豸ļ
    print(colors.cyan .. colors.bright .. "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" .. colors.reset)
	print()
	print()
	print(colors.green .. colors.bright .."ʹСʿ:".. colors.reset .. colors.green .. " 1.ֱMIFI֮ҵZXIC-RomKitȡ,ù3.0ʱѾ")
	print()
	print()
	print()
	print()
	print(colors.red .. 'ȡɺ,ȡݻZXIC-RomKitĿ¼"Z."ͷļ'.. colors.reset)
	print()
	print(colors.bright .."ѡҪеĲ")
    print()
    print(colors.cyan .. colors.bright .. "                      1.򿪹           2.ȡĿ¼          3." .. colors.reset)
	print()
	io.write(colors.green .. "ֲ Enter : " .. colors.reset)
    local user_Studio_selection = io.read()
        if user_Studio_selection == "1" then
        os.execute("start conhost.exe file\\ZXIC-RomKit\\_ADBһȡ̼.bat")
        elseif user_Studio_selection == "2" then
		os.execute("explorer file\\ZXIC-RomKit")
        end
 end

local function AD()  --ΪάӵһС档
os.execute('start "" "https://shimo.im/docs/RKAWMBJLgXu96aq8/"')
end

 local function set_wifi()  -- zxicWIFI,4.1汾,24.11.14
    print(colors.cyan .. colors.bright .. "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" .. colors.reset)
    print()
	print(colors.red .. "ʹ֪:".. colors.blue .. colors.bright .."Ŀǰ汾ݲָ֧·WiFi,ֻ֧޸WiFi,֧")
    print()
	print("         " .. "֧Сֱ󲿷ַWiFiʧWiFi޷ӵ,볤ָť")
	print()
	print(colors.cyan .. colors.bright .. "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" .. colors.reset)
	io.write(colors.green .. "豸WEBַ( 192.168.100.1): "  .. colors.red .. colors.bright)
    local YOUR_IP = io.read()
    print()
    print(colors.blue .. colors.bright .."ڵϵ¼豸̨: http://".. YOUR_IP .."/".. colors.reset)
    print()
    io.write(colors.green .." SSID: ".. colors.red .. colors.bright)
    local YOUR_SSID = io.read()
    print(colors.reset)
    io.write(colors.green .."豸: ".. colors.red .. colors.bright)
    local MAX_Access = io.read()
    print(colors.reset)
    -- Prepare the POST data
    local DATA = "goformId=SET_WIFI_SSID1_SETTINGS&ssid=" .. YOUR_SSID ..
                "&broadcastSsidEnabled=0&MAX_Access_num=" .. MAX_Access ..
                "&security_mode=OPEN&cipher=2&NoForwarding=0&show_qrcode_flag=0&security_shared_mode=NONE"

    local TYPES = {
        'goform/goform_set_cmd_process',
        'reqproc/proc_post'
    }

    -- Function to perform the POST request
    local function requ(type)
        local command = "bin\\curl -s -X POST -d \"" .. DATA .. "\" \"http://" .. YOUR_IP .. "/" .. type .. "\" 1>nul 2>nul"
        os.execute(command)
    end

    -- Loop through the request types and execute
    for _, TYPE in ipairs(TYPES) do
        requ(TYPE)
    end

    -- Output result
    print(colors.green .."ʱWiFiϿóɹ")
    print("ʧ")
    io.read(1)
end

local function xr_web()
	is_adb_device_connected()
	print(colors.cyan .. colors.bright .. "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT" .. colors.reset)
	print()
	print(colors.cyan .. colors.bright .. "ʹСʿ:" .. colors.reset .. colors.green .. "ʹñ豸jffs2ϵͳĿǰ֧squashfsֻѹļϵͳ")
	print()
	print(colors.cyan .. colors.bright .. " =------" .. colors.magenta .. colors.bright .. "ѡдģʽ" .. colors.cyan .. colors.bright .. "--------------------------------------------------------------------------------------------=")
	print(colors.cyan .. colors.bright .. " =                                                                                                              =")
	print(colors.cyan .. colors.bright .. " =" .. colors.reset .. colors.yellow .. "     1.Զļ        2.ͨATweb߼web                                                                   " .. colors.cyan .. colors.bright .. "=")
	print(colors.cyan .. colors.bright .. " =                                                                                                              =")
	print(colors.cyan .. colors.bright .. " =    " .. colors.reset .. colors.yellow .. "                                                                                                          " .. colors.cyan .. colors.bright .. "=")
	print(colors.cyan .. colors.bright .. " =--------------------------------------------------------------------------------------------------------------=")
	print()
  -- ûѡӦĲʱ
	io.write(colors.green .. "ֲ Enter : " .. colors.red .. colors.bright)
	local web_selection = io.read()
           -- ɸѡݲִжӦ
	print(colors.reset)
	if web_selection == "1" then
		os.execute("start conhost.exe bin\\lua54 lua\\app_zfile-web.lua")
	elseif web_selection == "2" then
		print()
		print(colors.blue .. colors.bright .. "ضд..." .. colors.reset)
		os.execute("bin\\adb shell mount -o remount,rw /")
		print()
		print(colors.yellow .. colors.bright .. "ļ(סǲ֧)..." .. colors.reset)
		--os.execute("bin\\adb push file\\at_web\\at_server /bin/at_server")
		--os.execute("bin\\adb shell chmod +x ./bin/at_server")
		--os.execute("bin\\adb push file\\at_web\\at_info.html /etc_ro/web/at_info.html")
		--os.execute("bin\\adb push file\\at_web\\css\\at.css /etc_ro/web/css/at.css")
		--os.execute("bin\\adb push file\\at_web\\js\\at.js /etc_ro/web/js/at.js")
		print()
		print(colors.magenta .. colors.bright .. "..." .. colors.reset)
		--os.execute([[bin\\adb shell "echo 'at_server &' >> /sbin/rm_dev.sh"]])
		--os.execute("start /min bin\\adb shell at_server &")
		print("\n")
		print("\n")
		print(colors.green .. "óɹ")
				-- ȡ豸 IP
		local handle = io.popen("bin\\adb shell nv get lan_ipaddr")
		local ip = handle:read("*l")
		handle:close()
		if ip and ip:match("%d+%.%d+%.%d+%.%d+") then
			print()
			print(colors.cyan .. "⵽豸IP: " .. colors.yellow .. ip .. colors.reset)
			io.write(colors.cyan .. "ǷҪд ATweb? (y/n): ")
			local choice = io.read()
			if choice == "y" or choice == "Y" then
				os.execute("start http://" .. ip .. ":9090/at_info.html")
			else
				print("\n")
				print(colors.green .."ֶз: http://" .. ip .. "9090˿ڲat_info.htmlҳ档")
			end
		else
		    print("ֶ豸ipַ9090˿ڲat_info.htmlҳ档")
		end
		print("\n\n")
		print(colors.reset)
		os.execute("pause")
	end
end

-- ӡ
local function print_title1()
    os.execute("cls")  -- 
	print("(C) 2025-2026 punguin. All rights reserverd.".. colors.cyan .. colors.bright .. "                XZ.ж        RE.ˢ      EXIT.˳\n".. colors.reset)

end

-- ӡ
local function print_announcement()
    print()
    print(colors.blue .. colors.bright .. "ֹ:".. colors.red .."4GȦѾͣ\n" .. colors.reset)
    check_adb_status()  -- ADB״̬
    check_serial() -- ״̬
	print(colors.green .. "\n" .. "Tips:ֹٷQQȺ2000˴Ⱥ,ӭ" .. colors.underline_blue .. colors.bright .. "725700912" .. colors.reset)
	print()
	check_version() -- Ӱ汾Ϣ
	print(colors.blue .. colors.bright .. "ƶ°汾,'new'" .. colors.reset)
end

-- ӡѡ
local function print_menu()
	print()
	print()
    print(colors.yellow .. "            01.豸Ϣ           02.豸adb       03.װ       04.ADBն      05.豸    " .. colors.reset)
    print(colors.cyan .. colors.bright .. "          =------ 豸ļ-------------------------------------------------------------------------=" .. colors.reset)
    print(colors.cyan .. colors.bright .."          =                                                                                            =".. colors.reset)
    print(colors.cyan .. colors.bright .."          =".. colors.reset .. colors.yellow .."    A.ȡMTD4    B.dongleˢMTD4     C.MTDˢд      D.鿴mtd     ".. colors.reset .. colors.cyan ..colors.bright .."=" .. colors.reset)
    print(colors.cyan .. colors.bright .."          =                                                                                            =".. colors.reset)
	print(colors.cyan .. colors.bright .."          =".. colors.reset .. colors.yellow .."    E.дWEB         F.΢ͨɱȥ     G.̼ȡ                           ".. colors.reset .. colors.cyan ..colors.bright .."=" .. colors.reset)
	print(colors.cyan .. colors.bright .."          =                                                                                            =".. colors.reset)
    print(colors.cyan .. colors.bright .. "          =--------------------------------------------------------------------------------------------=" .. colors.reset)
	print("\n")
	print(colors.cyan .. colors.bright .. "     뵼:" .. colors.reset)
    print()
	print(colors.yellow .. "         1.ڹ         2.С      3.1869      4.ζasr()   5.Orz0000()" .. colors.reset)
	print()
	print(colors.yellow .. "         6.zxicWIFI     7.ʧ      ".. colors.underline_magenta .. "8.Ϲר" .. colors.reset .."  ".. colors.underline_green .. colors.bright .."9.Ҫ" .. colors.reset)
	print()
	print()
end

-- ûӦѡ
    while true do
    print_title1()            --
    print_announcement()      --
    print_menu()              --˵
    io.write(colors.green .. "벢Enter: " .. colors.reset) --ʾû
    local choice = io.read() --û
    if choice == "A" then
        os.execute("start conhost.exe bin\\lua54 lua\\app_zmtd-extract.lua") --ȡĽű
    elseif choice == "B" then
		os.execute("cls")
		os.execute("start conhost.exe file\\dongle_fun\\dongle_fun.bat") --dongle_funBat
    elseif choice == "C" then
        os.execute("start conhost.exe bin\\lua54 lua\\app_zmtd-brusque.lua")
    elseif choice == "D" then
        mtd_check()
		os.execute("pause")
    elseif choice == "E" then
		xr_web()
	elseif choice == "F" then
        ufi_nv_set()
	elseif choice == "G" then
        os.execute("explorer file\\OpenZxicEditor-For-Windows")
	elseif choice == "H" then
        mifi_Studio()
	elseif choice == "01" then
	    os.execute("start conhost.exe bin\\lua54 lua\\app_machine-material.lua")
	elseif choice == "02" then
        set_adb()
	elseif choice == "03" then
        install_drive()
	elseif choice == "04" then
        os.execute("start bin\\openadb.bat")
	elseif choice == "05" then
        os.execute("start devmgmt.msc")
	elseif choice == "1" then
        os.execute('start "" "https://atmaster.netlify.app/#/"')
	elseif choice == "2" then
        os.execute("start file\\tool\\YXF_TOOL.exe")
	elseif choice == "3" then
        os.execute("start file\\tool\\ZTE_PATCH_1.1.exe")
	elseif choice == "4" then
        os.execute("start file\\tool\\Watermelon-ASR_Tools.exe")
	elseif choice == "5" then
        os.execute("start file\\tool\\UFITOOL_MTD4.exe")
	elseif choice == "6" then
        set_wifi()
	elseif choice == "7" then
        os.execute('start "" "https://net.arsn.cn/"')
	elseif choice == "8" then
        uisoc()
	elseif choice == "9" then
	    AD()
	elseif choice == "new" then
        os.execute('start "" "http://punguin.cn/web-helper"')
    elseif choice == "C" then
         os.execute("start conhost.exe bin\\lua54 lua\\so.lua")
	elseif choice == "RE" then
        os.execute("bin\\lua54 lua\\helper.lua")
	elseif choice == "XZ" then
        os.execute("start unins000.exe")
		break
    elseif choice == "EXIT" then
        print(colors.red .. "˳" .. colors.reset)
        break
    else
        print(colors.red .. "Чѡԡ" .. colors.reset)
		os.execute("pause")
    end
end