forked from prometheus-lua/Prometheus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAntiTamper.lua
More file actions
190 lines (171 loc) · 5.85 KB
/
AntiTamper.lua
File metadata and controls
190 lines (171 loc) · 5.85 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
-- This Script is Part of the Prometheus Obfuscator by Levno_710
--
-- AntiTamper.lua
--
-- This Script provides an Obfuscation Step, that breaks the script, when someone tries to tamper with it.
local Step = require("prometheus.step");
local Ast = require("prometheus.ast");
local Scope = require("prometheus.scope");
local RandomStrings = require("prometheus.randomStrings")
local Parser = require("prometheus.parser");
local Enums = require("prometheus.enums");
local logger = require("logger");
local AntiTamper = Step:extend();
AntiTamper.Description = "This Step Breaks your Script when it is modified. This is only effective when using the new VM.";
AntiTamper.Name = "Anti Tamper";
AntiTamper.SettingsDescriptor = {
UseDebug = {
type = "boolean",
default = true,
description = "Use debug library. (Recommended, however scripts will not work without debug library.)"
}
}
function AntiTamper:init(settings)
end
function AntiTamper:apply(ast, pipeline)
if pipeline.PrettyPrint then
logger:warn(string.format("\"%s\" cannot be used with PrettyPrint, ignoring \"%s\"", self.Name, self.Name));
return ast;
end
local code = "do local valid = true;";
if self.UseDebug then
local string = RandomStrings.randomString();
code = code .. [[
-- Anti Beautify
local sethook = debug and debug.sethook or function() end;
local allowedLine = nil;
local called = 0;
sethook(function(s, line)
if not line then
return
end
called = called + 1;
if allowedLine then
if allowedLine ~= line then
sethook(error, "l", 5);
end
else
allowedLine = line;
end
end, "l", 5);
(function() end)();
(function() end)();
sethook();
if called < 2 then
valid = false;
end
if called < 2 then
valid = false;
end
-- Anti Function Hook
local funcs = {pcall, string.char, debug.getinfo, string.dump}
for i = 1, #funcs do
if debug.getinfo(funcs[i]).what ~= "C" then
valid = false;
end
if debug.getupvalue(funcs[i], 1) then
valid = false;
end
if pcall(string.dump, funcs[i]) then
valid = false;
end
end
-- Anti Beautify
local function getTraceback()
local str = (function(arg)
return debug.traceback(arg)
end)("]] .. string .. [[");
return str;
end
local traceback = getTraceback();
valid = valid and traceback:sub(1, traceback:find("\n") - 1) == "]] .. string .. [[";
local iter = traceback:gmatch(":(%d*):");
local v, c = iter(), 1;
for i in iter do
valid = valid and i == v;
c = c + 1;
end
valid = valid and c >= 2;
]]
end
code = code .. [[
local gmatch = string.gmatch;
local err = function() error("Tamper Detected!") end;
local pcallIntact2 = false;
local pcallIntact = pcall(function()
pcallIntact2 = true;
end) and pcallIntact2;
local random = math.random;
local tblconcat = table.concat;
local unpkg = table and table.unpack or unpack;
local n = random(3, 65);
local acc1 = 0;
local acc2 = 0;
local pcallRet = {pcall(function() local a = ]] .. tostring(math.random(1, 2^24)) .. [[ - "]] .. RandomStrings.randomString() .. [[" ^ ]] .. tostring(math.random(1, 2^24)) .. [[ return "]] .. RandomStrings.randomString() .. [[" / a; end)};
local origMsg = pcallRet[2];
local line = tonumber(gmatch(tostring(origMsg), ':(%d*):')());
for i = 1, n do
local len = math.random(1, 100);
local n2 = random(0, 255);
local pos = random(1, len);
local shouldErr = random(1, 2) == 1;
local msg = origMsg:gsub(':(%d*):', ':' .. tostring(random(0, 10000)) .. ':');
local arr = {pcall(function()
if random(1, 2) == 1 or i == n then
local line2 = tonumber(gmatch(tostring(({pcall(function() local a = ]] .. tostring(math.random(1, 2^24)) .. [[ - "]] .. RandomStrings.randomString() .. [[" ^ ]] .. tostring(math.random(1, 2^24)) .. [[ return "]] .. RandomStrings.randomString() .. [[" / a; end)})[2]), ':(%d*):')());
valid = valid and line == line2;
end
if shouldErr then
error(msg, 0);
end
local arr = {};
for i = 1, len do
arr[i] = random(0, 255);
end
arr[pos] = n2;
return unpkg(arr);
end)};
if shouldErr then
valid = valid and arr[1] == false and arr[2] == msg;
else
valid = valid and arr[1];
acc1 = (acc1 + arr[pos + 1]) % 256;
acc2 = (acc2 + n2) % 256;
end
end
valid = valid and acc1 == acc2;
if valid then else
repeat
return (function()
while true do
l1, l2 = l2, l1;
err();
end
end)();
until true;
while true do
l2 = random(1, 6);
if l2 > 2 then
l2 = tostring(l1);
else
l1 = l2;
end
end
return;
end
end
-- Anti Function Arg Hook
local obj = setmetatable({}, {
__tostring = err,
});
obj[math.random(1, 100)] = obj;
(function() end)(obj);
repeat until valid;
]]
local parsed = Parser:new({LuaVersion = Enums.LuaVersion.Lua51}):parse(code);
local doStat = parsed.body.statements[1];
doStat.body.scope:setParent(ast.body.scope);
table.insert(ast.body.statements, 1, doStat);
return ast;
end
return AntiTamper;