-- 需要:ELGG版本 >= 1.2.5 -- 下载:https://www.xiaoman.top/elgg elgg.import("devTool") -- 导入 devTool 模块 if devTool == nil then gg.alert("devTool 模块导入失败!") end local mark local function Main() local choice = gg.choice({ "源代码语法解析", "字节码反汇编(拆卸)", "汇编码清垃圾", "编译汇编码(汇编 | 组装)", "编译源代码", "免费加密", "退出工具", }, 0, "devTool") if choice == nil then elseif choice == 1 then parseLuaCode() elseif choice == 2 then disassemble() elseif choice == 3 then cleanLasm() elseif choice == 4 then assemble() elseif choice == 5 then compileLuaCode() elseif choice == 6 then freeEncrypt() elseif choice == 7 then os.exit() end mark = 0 end function parseLuaCode() -- 感谢大佬 妒猫 提供的技术支持 local choice = gg.prompt({ "选择文件:" }, { gg.getFile() }, { "file" }) if choice == nil then return end local code = io.open(choice[1], "rb"):read("*a") -- 源代码语法解析 local AST = devTool.parseLuaCode(code) if type(AST) == "table" then gg.alert2("解析成功,语法树:", tostring(AST)) end local function AST_2_script(AST_Table) -- 根据语法树表生成脚本 local script = "" for k, v in ipairs(AST_Table) do script = script .. " " .. v[2] end return script end local script = AST_2_script(AST) local file_path = choice[1] .. ".语法树生成.lua" io.open(file_path, "wb"):write(script) gg.alert2("根据语法树生成脚本成功:", "文件输出在:\n" .. file_path) end function disassemble() local choice = gg.prompt({ "选择文件:", "汇编码不转义字符串", "伪代码注释不转义字符串" }, { gg.getFile(), false, false }, { "file", "checkbox", "checkbox" }) if choice == nil then return end local code = io.open(choice[1], "rb"):read("*a") -- 反汇编 (拆卸) (自动识别垃圾,无视刷内存,支持伪代码) -- 默认会对非 ASCII 编码字符进行转义 -- 第 2 个参数:汇编码中是否使用原始字符串 (不转义) -- 第 3 个参数:伪代码中是否使用原始字符串 (不转义) local lasm_code = devTool.disassemble(code, choice[2], choice[3]) if type(lasm_code) == "string" then local file_path = choice[1] .. ".反汇编.lua" io.open(file_path, "wb"):write(lasm_code) gg.alert2("反汇编成功:", "文件输出在:\n" .. file_path) end end function cleanLasm() local choice = gg.prompt({ "选择文件:" }, { gg.getFile() }, { "file" }) if choice == nil then return end local file = io.open(choice[1], "rb") local output = "" -- 逐行读取 for line in file:lines() do if line:sub(1, 1) ~= "." then -- 不是 . 开头,则为指令码 if line:sub(-10) == "-- garbage" then -- 以 -- garbage 结尾则是垃圾 line = "" -- 删除这行 (替换成空行) end end output = output .. line .. "\n" end local file_path = choice[1] .. ".清理.lua" io.open(file_path, "wb"):write(output) gg.alert2("清理成功:", "文件输出在:\n" .. file_path) end function assemble() local choice = gg.prompt({ "选择文件:" }, { gg.getFile() }, { "file" }) if choice == nil then return end local code = io.open(choice[1], "rb"):read("*a") -- 汇编,将反汇编(拆卸)后的内容组装回去 local bytecode = devTool.assemble(code) if type(bytecode) == "string" then local file_path = choice[1] .. ".汇编.lua" io.open(file_path, "wb"):write(bytecode) gg.alert2("汇编成功:", "文件输出在:\n" .. file_path) end end function compileLuaCode() local choice = gg.prompt({ "选择文件:" }, { gg.getFile() }, { "file" }) if choice == nil then return end local code = io.open(choice[1], "rb"):read("*a") -- 编译 local bytecode = devTool.compileLuaCode(code) if type(bytecode) == "string" then local file_path = choice[1] .. ".编译.lua" io.open(file_path, "wb"):write(bytecode) gg.alert2("编译成功:", "文件输出在:\n" .. file_path) end end function freeEncrypt() local choice = gg.prompt({ "选择文件:" }, { gg.getFile() }, { "file" }) if choice == nil then return end local code = io.open(choice[1], "rb"):read("*a") -- 免费加密 (源代码和字节码均可加密) local encrypt = devTool.freeEncrypt(code) if type(encrypt) == "string" then local file_path = choice[1] .. ".免费加密.lua" io.open(file_path, "wb"):write(encrypt) gg.alert2("免费加密成功:", "文件输出在:\n" .. file_path) end end while true do if gg.isVisible(true) then mark = 1 gg.setVisible(false) end if mark == 1 then Main() end end