由于发布的代码不完整,而且可能搞砸了,我的只是有根据的猜测。
似乎整个代码将调用“匿名函数”的结果存储在变量ungz 中:(function () 片段可能像这样关闭:
ungz = (function() -- "anonymous function"
-- ...
-- definition of `prettify` + helper data
-- ...
return assert( loadstring(
prettify [===[
...obfuscated code in this long string...
]===]
) ) -- end of `loadstring` and of `assert` calls
end)() --<<-- note the () to call the "anonymous function"
在此函数中,您可能会看到函数 prettify 及其辅助数据的定义,可以通过这种方式重新格式化以便更好地理解:
local base_char,keywords=128, {
"and","break","do","else","elseif","end","false","for",
"function","if","in","local","nil","not","or","repeat","return",
"then","true","until","while","read","nbits","nbits_left_in_byte",
"wnd_pos","output","val","input",};
function prettify(code)
return code:gsub(
"["..string.char(base_char).."-"..string.char(base_char+#keywords).."]",
function (c)
return keywords[c:byte()-base_char];
end
)
end
函数prettify 应用于字符串时,将返回相同的字符串,其中任何具有base_char-base_char+#keywords 范围内的数字代码的字符都将替换为keyword 列表的关键字。
这用于使用assert(loadstring(prettify[===[xxxx]===])) 对“混淆”代码进行“反混淆”,其中我将混淆代码表示为xxxx。
附录:请注意,将prettify 应用于片段[===[xxxx]===] 不会返回有意义的代码(202 的base_char 值会产生更好的结果,尽管并不完美) .此外,您必须合并该长字符串中的所有行并将其替换为普通字符串,即将其转换为"yyyy",其中yyyy 是xxxx,并删除了所有硬换行符。
可能所有代码都以某种更进一步的方式进行了预处理。