-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathboolean.lua
More file actions
59 lines (53 loc) · 1.84 KB
/
boolean.lua
File metadata and controls
59 lines (53 loc) · 1.84 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
-- This Script is Part of the Prometheus Obfuscator by Levno_710
--
-- boolean.lua
--
-- This Script contains the expression handler for the BooleanExpression.
local Ast = require("prometheus.ast");
local expressionEvaluators = {
[Ast.GreaterThanExpression] = function(left, right)
return left > right
end,
[Ast.LessThanExpression] = function(left, right)
return left < right
end,
[Ast.GreaterThanOrEqualsExpression] = function(left, right)
return left >= right
end,
[Ast.LessThanOrEqualsExpression] = function(left, right)
return left <= right
end,
[Ast.NotEqualsExpression] = function(left, right)
return left ~= right
end,
}
local function createRandomASTCFlowExpression(resultBool)
local expTB = {
Ast.GreaterThanExpression,
Ast.LessThanExpression,
Ast.GreaterThanOrEqualsExpression,
Ast.LessThanOrEqualsExpression,
Ast.NotEqualsExpression
}
local leftInt, rightInt, boolResult, randomExp
repeat
randomExp = expTB[math.random(1, #expTB)]
leftInt = Ast.NumberExpression(math.random(1, 2^24))
rightInt = Ast.NumberExpression(math.random(1, 2^24))
boolResult = expressionEvaluators[randomExp](leftInt.value, rightInt.value)
until boolResult == resultBool
return randomExp(leftInt, rightInt, false)
end
return function(self, expression, _, numReturns)
local scope = self.activeBlock.scope;
local regs = {};
for i = 1, numReturns do
regs[i] = self:allocRegister();
if i == 1 then
self:addStatement(self:setRegister(scope, regs[i], createRandomASTCFlowExpression(expression.value)), {regs[i]}, {}, false);
else
self:addStatement(self:setRegister(scope, regs[i], Ast.NilExpression()), {regs[i]}, {}, false);
end
end
return regs;
end;