1+ -- This Script is Part of the Prometheus Obfuscator by Levno_710
2+ --
3+ -- AntiTamper.lua
4+ --
5+ -- This Script provides an Obfuscation Step, that breaks the script, when someone tries to tamper with it.
6+
7+ local Step = require (" prometheus.step" );
8+ local Ast = require (" prometheus.ast" );
9+ local Scope = require (" prometheus.scope" );
10+ local RandomStrings = require (" prometheus.randomStrings" )
11+ local Parser = require (" prometheus.parser" );
12+ local Enums = require (" prometheus.enums" );
13+ local logger = require (" logger" );
14+
15+ local AntiTamper = Step :extend ();
16+ AntiTamper .Description = " This Step Breaks your Script when it is modified. This is only effective when using the new VM." ;
17+ AntiTamper .Name = " Anti Tamper" ;
18+
19+ AntiTamper .SettingsDescriptor = {
20+ UseDebug = {
21+ type = " boolean" ,
22+ default = true ,
23+ description = " Use debug library. (Recommended, however scripts will not work without debug library.)"
24+ }
25+ }
26+
27+ function AntiTamper :init (settings )
28+
29+ end
30+
31+ function AntiTamper :apply (ast , pipeline )
32+ if pipeline .PrettyPrint then
33+ logger :warn (string.format (" \" %s\" cannot be used with PrettyPrint, ignoring \" %s\" " , self .Name , self .Name ));
34+ return ast ;
35+ end
36+ local code = " do local valid = true;" ;
37+ if self .UseDebug then
38+ code = code .. [[
39+ -- Anti Beautify
40+ local sethook = debug and debug.sethook or function() end;
41+ local allowedLine = nil;
42+ local called = 0;
43+ sethook(function(s, line)
44+ called = called + 1;
45+ if allowedLine then
46+ if allowedLine ~= line then
47+ sethook(error, "l");
48+ end
49+ else
50+ allowedLine = line;
51+ end
52+ end, "l");
53+ (function() end)();
54+ (function() end)();
55+ sethook();
56+ if called < 2 then
57+ valid = false;
58+ end
59+
60+ -- Anti Function Hook
61+ local funcs = {pcall, string.char, debug.getinfo}
62+ for i = 1, #funcs do
63+ if debug.getinfo(funcs[i]).what ~= "C" then
64+ valid = false;
65+ end
66+ end
67+ ]]
68+ end
69+ local string = RandomStrings .randomString ();
70+ code = code .. [[
71+ -- Anti Beautify
72+ local function getTraceback()
73+ local str = (function(arg)
74+ return debug.traceback(arg)
75+ end)("]] .. string .. [[ ");
76+ return str;
77+ end
78+
79+ local traceback = getTraceback();
80+ valid = valid and traceback:sub(1, traceback:find("\n") - 1) == "]] .. string .. [[ ";
81+ local iter = traceback:gmatch(":(%d*):");
82+ local v, c = iter(), 1;
83+ for i in iter do
84+ valid = valid and i == v;
85+ c = c + 1;
86+ end
87+ valid = valid and c >= 2;
88+
89+ local gmatch = string.gmatch;
90+ local err = function() error("Tamper Detected!") end;
91+
92+ local pcallIntact2 = false;
93+ local pcallIntact = pcall(function()
94+ pcallIntact2 = true;
95+ end) and pcallIntact2;
96+
97+ local _1, s1 = pcall(function() local a = ]] .. tostring (math.random (1 , 2 ^ 24 )) .. [[ - "]] .. RandomStrings .randomString () .. [[ " ^ ]] .. tostring (math.random (1 , 2 ^ 24 )) .. [[ return "]] .. RandomStrings .randomString () .. [[ " / a; end)
98+ local m1 = gmatch(tostring(s1), ':(%d*):')()
99+ local l1 = tonumber(m1)
100+
101+ local _2, s2 = pcall(function() local a = ]] .. tostring (math.random (1 , 2 ^ 24 )) .. [[ - "]] .. RandomStrings .randomString () .. [[ " ^ ]] .. tostring (math.random (1 , 2 ^ 24 )) .. [[ return "]] .. RandomStrings .randomString () .. [[ " / a; end)
102+ local m2 = gmatch(tostring(s2), ':(%d*):')()
103+ local l2 = m2 and {[tonumber(m2)] = true} or {};
104+ if not(_1 or _2) and l2[l1] and pcallIntact and valid then else
105+ repeat
106+ return (function()
107+ while true do
108+ l1, l2 = l2, l1;
109+ err();
110+ end
111+ end)();
112+ until true;
113+ while true do
114+ l2 = math.random(1, 6);
115+ if l2 > 2 then
116+ l2 = tostring(l1);
117+ else
118+ l1 = l2;
119+ end
120+ end
121+ return nil;
122+ end
123+ end
124+
125+ -- Anti Function Arg Hook
126+ local obj = setmetatable({}, {
127+ __tostring = err,
128+ });
129+ obj[math.random(1, 100)] = obj;
130+ (function() end)(obj);
131+
132+ repeat until valid;
133+ ]]
134+
135+ local parsed = Parser :new ({LuaVersion = Enums .LuaVersion .Lua51 }):parse (code );
136+ local doStat = parsed .body .statements [1 ];
137+ doStat .body .scope :setParent (ast .body .scope );
138+ table.insert (ast .body .statements , 1 , doStat );
139+
140+ return ast ;
141+ end
142+
143+ return AntiTamper ;
0 commit comments