55-- This Script contains the statement handler for the ForStatement
66
77local Ast = require (" prometheus.ast" );
8+ local util = require (" prometheus.util" );
89
910return function (self , statement , funcDepth )
1011 local scope = self .activeBlock .scope ;
@@ -33,7 +34,11 @@ return function(self, statement, funcDepth)
3334 local tmpReg = self :allocRegister (false );
3435 self :addStatement (self :setRegister (scope , tmpReg , Ast .NumberExpression (0 )), {tmpReg }, {}, false );
3536 local incrementIsNegReg = self :allocRegister (false );
36- self :addStatement (self :setRegister (scope , incrementIsNegReg , Ast .LessThanExpression (self :register (scope , incrementReg ), self :register (scope , tmpReg ))), {incrementIsNegReg }, {incrementReg , tmpReg }, false );
37+
38+ local shouldSwap3 = math.random (1 , 2 ) == 2 ;
39+ local shuffledRegs4 = shouldSwap3 and {incrementReg , tmpReg } or {tmpReg , incrementReg };
40+ self :addStatement (self :setRegister (scope , incrementIsNegReg , Ast [shouldSwap3 and " LessThanExpression" or " GreaterThanExpression" ](self :register (scope , shuffledRegs4 [1 ]), self :register (scope , shuffledRegs4 [2 ]))), {incrementIsNegReg }, {shuffledRegs4 [1 ], shuffledRegs4 [2 ]}, false );
41+
3742 self :freeRegister (tmpReg );
3843
3944 local currentReg = self :allocRegister (true );
@@ -45,13 +50,26 @@ return function(self, statement, funcDepth)
4550 self :setActiveBlock (checkBlock );
4651
4752 scope = checkBlock .scope ;
48- self :addStatement (self :setRegister (scope , currentReg , Ast .AddExpression (self :register (scope , currentReg ), self :register (scope , incrementReg ))), {currentReg }, {currentReg , incrementReg }, false );
53+
54+ -- x = x + y or x = y + x instead of just x = x + y.
55+ -- > NEW: In an attempt to thwart deobfuscations, despite this being a simple comparison... Shuffling these causes problems for decompilers.
56+ -- > NOTE: This isn't unstable code, I've tested it multiple times.
57+
58+ local shuffledRegs = util .shuffle ({currentReg , incrementReg });
59+ self :addStatement (self :setRegister (scope , currentReg , Ast .AddExpression (self :register (scope , shuffledRegs [1 ]), self :register (scope , shuffledRegs [2 ]))), {currentReg }, {shuffledRegs [1 ], shuffledRegs [2 ]}, false );
4960 local tmpReg1 = self :allocRegister (false );
5061 local tmpReg2 = self :allocRegister (false );
5162 self :addStatement (self :setRegister (scope , tmpReg2 , Ast .NotExpression (self :register (scope , incrementIsNegReg ))), {tmpReg2 }, {incrementIsNegReg }, false );
52- self :addStatement (self :setRegister (scope , tmpReg1 , Ast .LessThanOrEqualsExpression (self :register (scope , currentReg ), self :register (scope , finalReg ))), {tmpReg1 }, {currentReg , finalReg }, false );
63+
64+ local shouldSwap = math.random (1 , 2 ) == 2 ;
65+ local shuffledRegs2 = shouldSwap and {currentReg , finalReg } or {finalReg , currentReg };
66+ self :addStatement (self :setRegister (scope , tmpReg1 , Ast [shouldSwap and " LessThanOrEqualsExpression" or " GreaterThanOrEqualsExpression" ](self :register (scope , shuffledRegs2 [1 ]), self :register (scope , shuffledRegs2 [2 ]))), {tmpReg1 }, {shuffledRegs2 [1 ], shuffledRegs2 [2 ]}, false );
5367 self :addStatement (self :setRegister (scope , tmpReg1 , Ast .AndExpression (self :register (scope , tmpReg2 ), self :register (scope , tmpReg1 ))), {tmpReg1 }, {tmpReg1 , tmpReg2 }, false );
54- self :addStatement (self :setRegister (scope , tmpReg2 , Ast .GreaterThanOrEqualsExpression (self :register (scope , currentReg ), self :register (scope , finalReg ))), {tmpReg2 }, {currentReg , finalReg }, false );
68+
69+ local shouldSwap2 = math.random (1 , 2 ) == 2 ;
70+ local shuffledRegs3 = shouldSwap2 and {currentReg , finalReg } or {finalReg , currentReg };
71+ self :addStatement (self :setRegister (scope , tmpReg2 , Ast [shouldSwap2 and " LessThanOrEqualsExpression" or " GreaterThanOrEqualsExpression" ](self :register (scope , shuffledRegs3 [1 ]), self :register (scope , shuffledRegs3 [2 ]))), {tmpReg2 }, {shuffledRegs3 [1 ], shuffledRegs3 [2 ]}, false );
72+
5573 self :addStatement (self :setRegister (scope , tmpReg2 , Ast .AndExpression (self :register (scope , incrementIsNegReg ), self :register (scope , tmpReg2 ))), {tmpReg2 }, {tmpReg2 , incrementIsNegReg }, false );
5674 self :addStatement (self :setRegister (scope , tmpReg1 , Ast .OrExpression (self :register (scope , tmpReg2 ), self :register (scope , tmpReg1 ))), {tmpReg1 }, {tmpReg1 , tmpReg2 }, false );
5775 self :freeRegister (tmpReg2 );
0 commit comments