|
4 | 4 | -- |
5 | 5 | -- This Script provides an Obfuscation Step, that breaks the script, when someone tries to tamper with it. |
6 | 6 |
|
7 | | -local Step = require("prometheus.step"); |
8 | | -local Ast = require("prometheus.ast"); |
9 | | -local Scope = require("prometheus.scope"); |
| 7 | +local Step = require("prometheus.step") |
10 | 8 | local RandomStrings = require("prometheus.randomStrings") |
11 | | -local Parser = require("prometheus.parser"); |
12 | | -local Enums = require("prometheus.enums"); |
13 | | -local logger = require("logger"); |
| 9 | +local Parser = require("prometheus.parser") |
| 10 | +local Enums = require("prometheus.enums") |
| 11 | +local logger = require("logger") |
14 | 12 |
|
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"; |
| 13 | +local AntiTamper = Step:extend() |
| 14 | +AntiTamper.Description = |
| 15 | + "This Step Breaks your Script when it is modified. This is only effective when using the new VM." |
| 16 | +AntiTamper.Name = "Anti Tamper" |
18 | 17 |
|
19 | 18 | 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 | | - } |
| 19 | + UseDebug = { |
| 20 | + type = "boolean", |
| 21 | + default = true, |
| 22 | + description = "Use debug library. (Recommended, however scripts will not work without debug library.)", |
| 23 | + }, |
25 | 24 | } |
26 | 25 |
|
27 | | -function AntiTamper:init(settings) |
28 | | - |
| 26 | +local function generateSanityCheck() |
| 27 | + local sanityCheckAnswers = {} |
| 28 | + local sanityPasses = math.random(1, 10) |
| 29 | + for i = 1, sanityPasses do |
| 30 | + sanityCheckAnswers[i] = (math.random(1, 2 ^ 24) % 2 == 1) |
| 31 | + end |
| 32 | + local primaryCheck = RandomStrings.randomString() |
| 33 | + local codeParts = {} |
| 34 | + local function addCode(fmt, ...) |
| 35 | + table.insert(codeParts, string.format(fmt, ...)) |
| 36 | + end |
| 37 | + |
| 38 | + local function generateAssignment(idx) |
| 39 | + local index = math.min(idx, sanityPasses) |
| 40 | + addCode(" valid = %s;\n", tostring(sanityCheckAnswers[index])) |
| 41 | + end |
| 42 | + local function generateValidation(idx) |
| 43 | + local index = math.min(idx - 1, sanityPasses) |
| 44 | + addCode(" if valid == %s then\n", tostring(sanityCheckAnswers[index])) |
| 45 | + addCode(" else\n") |
| 46 | + addCode(" while true do end\n") |
| 47 | + addCode(" end\n") |
| 48 | + end |
| 49 | + |
| 50 | + addCode("do local valid = '%s';", primaryCheck) |
| 51 | + addCode("for i = 0, %d do\n", sanityPasses) |
| 52 | + for i = 0, sanityPasses do |
| 53 | + if i == 0 then |
| 54 | + addCode(" if i == 0 then\n") |
| 55 | + addCode(" if valid ~= '%s' then\n", primaryCheck) |
| 56 | + addCode(" while true do end\n") |
| 57 | + addCode(" end\n") |
| 58 | + addCode(" valid = %s;\n", tostring(sanityCheckAnswers[1])) |
| 59 | + elseif i == 1 then |
| 60 | + addCode(" elseif i == 1 then\n") |
| 61 | + addCode(" if valid == %s then\n", tostring(sanityCheckAnswers[1])) |
| 62 | + addCode(" end\n") |
| 63 | + else |
| 64 | + addCode(" elseif i == %d then\n", i) |
| 65 | + |
| 66 | + --[[ |
| 67 | + Basically, even iterations are used to assign a new sanity check value, |
| 68 | + and odd iterations are used to validate the previous sanity check value. |
| 69 | + ]] |
| 70 | + if i % 2 == 0 then |
| 71 | + generateAssignment(i) |
| 72 | + else |
| 73 | + generateValidation(i) |
| 74 | + end |
| 75 | + end |
| 76 | + end |
| 77 | + addCode(" end\n") |
| 78 | + addCode(" end\n") |
| 79 | + addCode("do valid = true end\n") |
| 80 | + return table.concat(codeParts) |
29 | 81 | end |
30 | 82 |
|
| 83 | +function AntiTamper:init(settings) end |
| 84 | + |
31 | 85 | 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 | | - local string = RandomStrings.randomString(); |
39 | | - code = code .. [[ |
| 86 | + if pipeline.PrettyPrint then |
| 87 | + logger:warn(string.format('"%s" cannot be used with PrettyPrint, ignoring "%s"', self.Name, self.Name)) |
| 88 | + return ast |
| 89 | + end |
| 90 | + local code = generateSanityCheck() |
| 91 | + if self.UseDebug then |
| 92 | + local string = RandomStrings.randomString() |
| 93 | + code = code |
| 94 | + .. [[ |
40 | 95 | -- Anti Beautify |
41 | 96 | local sethook = debug and debug.sethook or function() end; |
42 | 97 | local allowedLine = nil; |
@@ -87,7 +142,7 @@ function AntiTamper:apply(ast, pipeline) |
87 | 142 | end)("]] .. string .. [["); |
88 | 143 | return str; |
89 | 144 | end |
90 | | - |
| 145 | +
|
91 | 146 | local traceback = getTraceback(); |
92 | 147 | valid = valid and traceback:sub(1, traceback:find("\n") - 1) == "]] .. string .. [["; |
93 | 148 | local iter = traceback:gmatch(":(%d*):"); |
@@ -149,13 +204,13 @@ function AntiTamper:apply(ast, pipeline) |
149 | 204 | valid = valid and acc1 == acc2; |
150 | 205 |
|
151 | 206 | if valid then else |
152 | | - repeat |
| 207 | + repeat |
153 | 208 | return (function() |
154 | 209 | while true do |
155 | 210 | l1, l2 = l2, l1; |
156 | 211 | err(); |
157 | 212 | end |
158 | | - end)(); |
| 213 | + end)(); |
159 | 214 | until true; |
160 | 215 | while true do |
161 | 216 | l2 = random(1, 6); |
|
0 commit comments