local path,rw,code,randomStr,randomKey,keyTable,keyLen,decName,enc,data,class_list,keyName,lenName,path2,import path = gg.getFile() path = string.match(path, "(.-)[^/]+$") path = gg.prompt({'请选择脚本:','若编译请勾选'}, {path,true}, {'file','checkbox'}) if not path then return end isgg = path[2] path = path[1] rw = function(path, data) local file if data then file = io.open(path, 'w') file:write(data) file:close() else file = io.open(path, 'r') data = file:read('*a') file:close() return data end end code = rw(path) -- print(code) -- print({string.byte('\\\'',1,-1)}) randomStr = function(len) len = len or 6 local str = '' for i = 1, len do local num1 = math.random(1, 26) if i % 2 == 0 then num1 = num1 + 64 else num1 = num1 + 96 end str = str .. string.char(num1) end return str end randomKey = randomStr(256) keyTable = {string.byte(randomKey, 1, -1)} keyLen = #keyTable decName = randomStr() enc = function(data) local Table = {} for i, v in pairs({string.byte(data, 1, -1)}) do -- Table[i] = string.format('\\x%02X',v ~ keyTable[(i - 1) % keyLen + 1]) Table[i] = v ~ keyTable[(i - 1) % keyLen + 1] end data = table.concat(Table,',') -- local name1 = randomStr() -- local name2 = randomStr() data = '((function()local s1={};local _=(function()s1={' .. data .. '}end)();local s2={};local _2=(function()s2='..decName..'(s1)end)();local s3={};local _3=(function()return s2 end);return (function()return _3() end)() end)())' return data end --[[ import "http" ]] import={} string.gsub(code,'import%s*[\034\039].-[\034\039]',function(txt1) if load(txt1) then import[#import+1]=txt1 end end) -- print(import) data = {} repeat local types = string.match(code, '[\034\039]') if not types then break end local num1 code, num1 = string.gsub(code, '(.-)(' .. types .. '.-' .. types .. ')', function(txt0, txt1) data[#data + 1] = txt0 local num2 txt1, num2 = string.gsub(txt1, '\\([\034\039\092])', function(txt2) return string.format('\\x%02X', string.byte(txt2)) end) if string.sub(txt1, -1, -1) ~= types then return txt1 end txt1 = load('return ' .. txt1)() txt1 = enc(txt1) data[#data + 1] = txt1 return '' end, 1) until num1 == 0 data[#data + 1] = code data=table.concat(data) data = string.gsub(data, "([^%w_])function%s+([%a_][%w%s%._]*)%s*(%(.-%))", "%1%2=function%3") data = string.gsub(data, "([^%w_])function%s+([^%(]+)%s*(%(.-%))", function(txt1,txt2,txt3) if string.match(txt2,'%S') then -- print({txt1,txt2,txt3}) return txt1..txt2.."=function"..txt3 end end) data=string.gsub(data,'([^%.])%.%s*([%a_][%w_]*)',function(txt0,txt1) return txt0..'['..enc(txt1)..']' end) class_list = { ["table"] = 1, ["_G"] = 1, ["debug"] = 1, ["os"] = 1, ["io"] = 1, ["package"] = 1, ["bit32"] = 1, ["utf8"] = 1, ["string"] = 1, ["math"] = 1, ["gg"] = 1 } for k,v in pairs(_ENV)do local t=type(v) if t=='table' and class_list[k] then data=string.gsub(data,'([^%w_])'..k..'([^%w_])',function(txt0,txt1) return txt0..'_ENV['..enc(k)..']'..txt1 end) end end keyName = randomStr() lenName = randomStr() code = 'local pairs=pairs\nlocal string_byte=string.byte\nlocal string_char=string.char\nlocal table_unpack=table.unpack\n' code = code .. 'local '..keyName..'={' .. table.concat(keyTable, ',') .. '}\nlocal '..lenName..'=#'..keyName..'\n' code = code .. 'local '..decName..'=function(str)local data={}for i,v in pairs(str)do data[#data+1]=v~'..keyName..'[(i-1)%'..lenName..'+1]end str=string_char(table_unpack(data))return str end\n' code = code .. 'local rl=(function(rl,_ENV)\n' .. data .. '\nend)("字符串",_ENV or _G)' code=code..'\nlocal rl=function()\nrequire "import"\n'..table.concat(import,'\n')..'\nend' path2 = path..'.超高安全加密.lua' rw(path2, code) if isgg then func=loadfile(path2) code=string.dump(func,true) code=string.gsub(code,'\x04\x00\x00\x00\x05\x00\x00\x00\x1E\x00\x80\x00\x1F\x00\x00\x00\x1F\x00\x80\x00','\x02\x00\x00\x00\x05\x00\x00\x00\x1E\x00\x80\x00') rw(path2, code) -- func=loadfile(path2) end gg.setVisible(true) print('文件保存到:'..path2) -- func() -- print(code) -- func,err=loadfile(path2) -- print(func,err) -- func()