-- call_a.lua -- Usage: 修改下面变量然后运行,或触动界面传入参数 local a_sh = "/var/mobile/a.sh" -- 这里示例值,实际可由触动脚本 UI 或变量设置 local cmd = "0" -- 0 or 1 local udid = "5edaa84151778693541c0a62b4de7fb875a767cf" local sn = "FFQZNKWHJC6C" local ecid = "285023194775598" local bmac = "3c:cd:36:24:28:e0" local wmac = "3c:cd:36:27:47:58" function removeAdiPbFiles() local foundFiles = {} -- 执行查找命令 local getFileTable = io.popen('find /private/var/containers/Data/System/ 2>/dev/null | grep "adi.pb"') if getFileTable then for file in getFileTable:lines() do if string.find(file, "adi.pb") then table.insert(foundFiles, file) -- 删除文件 os.execute("rm -rf '" .. file .. "'") wolf_log("已删除: " .. file, 2) end end getFileTable:close() else wolf_log("执行命令失败", 2) end if #foundFiles == 0 then wolf_log("未找到 adi.pb 文件", 2) else wolf_log("共删除 " .. #foundFiles .. " 个文件", 2) end return foundFiles end function new_ios_device(new_type) local function q(s) return string.format("%q", tostring(s)) end local function safe_show(title, msg) if type(alert) == "function" then pcall(alert, title or "提示", msg or "") return end if type(toast) == "function" then pcall(toast, msg or "") return end print((title and (title..": ") or "") .. tostring(msg or "")) end local cmdline = string.format("cd /var/root/ &&/bin/sh %s %s %s %s %s %s %s", a_sh, q(cmd), q(udid), q(sn), q(ecid), q(bmac), q(wmac)) -- 先尝试 io.popen local function popen_exec(cmd) if type(io) ~= "table" or type(io.popen) ~= "function" then return nil, "io.popen not available" end local fh, err = io.popen(cmd) if not fh then return nil, err end local out = fh:read("*a") pcall(function() fh:close() end) return out end local function file_exec(cmd) local tmp = "/var/tmp/call_a_out.txt" local full = cmd .. " > " .. tmp .. " 2>&1" os.execute(full) local f = io.open(tmp, "r") local content = nil if f then content = f:read("*a"); f:close() end return content end safe_show("CMD", cmdline) local out, err = popen_exec(cmdline) if out == nil then out, err = file_exec(cmdline) end if out and #out > 0 then safe_show("执行结果", out) else safe_show("执行完成", "无输出,返回:" .. tostring(err)) end end function new_ios_device2(udid, sn, ecid, bmac, wmac) local function q(s) return string.format("%q", tostring(s)) end local function safe_show(title, msg) if type(alert) == "function" then pcall(alert, title or "提示", msg or "") return end if type(toast) == "function" then pcall(toast, msg or "") return end print((title and (title..": ") or "") .. tostring(msg or "")) end local cmdline = string.format("cd /var/root/ &&/bin/sh %s %s %s %s %s %s %s", a_sh, q(1), q(udid), q(sn), q(ecid), q(bmac), q(wmac)) -- 先尝试 io.popen local function popen_exec(cmd) if type(io) ~= "table" or type(io.popen) ~= "function" then return nil, "io.popen not available" end local fh, err = io.popen(cmd) if not fh then return nil, err end local out = fh:read("*a") pcall(function() fh:close() end) return out end local function file_exec(cmd) local tmp = "/var/tmp/call_a_out.txt" local full = cmd .. " > " .. tmp .. " 2>&1" os.execute(full) local f = io.open(tmp, "r") local content = nil if f then content = f:read("*a"); f:close() end return content end safe_show("CMD", cmdline) local out, err = popen_exec(cmdline) if out == nil then out, err = file_exec(cmdline) end if out and #out > 0 then safe_show("执行结果", out) else safe_show("执行完成", "无输出,返回:" .. tostring(err)) end end