-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathpass_self_function_call.lua
More file actions
40 lines (34 loc) · 1.79 KB
/
pass_self_function_call.lua
File metadata and controls
40 lines (34 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
-- This Script is Part of the Prometheus Obfuscator by levno-710
--
-- pass_self_function_call.lua
--
-- This Script contains the statement handler for the PassSelfFunctionCallStatement.
local Ast = require("prometheus.ast");
local AstKind = Ast.AstKind;
return function(self, statement, funcDepth)
local scope = self.activeBlock.scope;
local baseReg = self:compileExpression(statement.base, funcDepth, 1)[1];
local tmpReg = self:allocRegister(false);
local args = { self:register(scope, baseReg) };
local regs = { baseReg };
for i, expr in ipairs(statement.args) do
if i == #statement.args and (expr.kind == AstKind.FunctionCallExpression or expr.kind == AstKind.PassSelfFunctionCallExpression or expr.kind == AstKind.VarargExpression) then
local reg = self:compileExpression(expr, funcDepth, self.RETURN_ALL)[1];
table.insert(args, Ast.FunctionCallExpression(
self:unpack(scope),
{self:register(scope, reg)}));
table.insert(regs, reg);
else
local reg = self:compileExpression(expr, funcDepth, 1)[1];
table.insert(args, self:register(scope, reg));
table.insert(regs, reg);
end
end
self:addStatement(self:setRegister(scope, tmpReg, Ast.StringExpression(statement.passSelfFunctionName)), {tmpReg}, {}, false);
self:addStatement(self:setRegister(scope, tmpReg, Ast.IndexExpression(self:register(scope, baseReg), self:register(scope, tmpReg))), {tmpReg}, {tmpReg, baseReg}, false);
self:addStatement(self:setRegister(scope, tmpReg, Ast.FunctionCallExpression(self:register(scope, tmpReg), args)), {tmpReg}, {tmpReg, unpack(regs)}, true);
self:freeRegister(tmpReg, false);
for _, reg in ipairs(regs) do
self:freeRegister(reg, false);
end
end;