lua-obfuscator 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/.github/workflows/release.yml +40 -0
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +18 -14
  4. package/dist/prometheus/LICENSE +661 -661
  5. package/dist/prometheus/build.bat +9 -9
  6. package/dist/prometheus/doc/README.md +11 -11
  7. package/dist/prometheus/doc/SUMMARY.md +27 -27
  8. package/dist/prometheus/doc/advanced/using-prometheus-in-your-lua-application.md +31 -31
  9. package/dist/prometheus/doc/getting-started/command-line-options.md +13 -13
  10. package/dist/prometheus/doc/getting-started/installation.md +11 -11
  11. package/dist/prometheus/doc/getting-started/obfuscating-your-first-script.md +50 -50
  12. package/dist/prometheus/doc/getting-started/presets.md +10 -10
  13. package/dist/prometheus/doc/getting-started/the-config-object.md +58 -58
  14. package/dist/prometheus/doc/getting-started/writing-a-custom-config-file.md +56 -56
  15. package/dist/prometheus/doc/steps/anti-tamper.md +11 -11
  16. package/dist/prometheus/doc/steps/constantarray.md +71 -71
  17. package/dist/prometheus/doc/steps/encryptstrings.md +86 -86
  18. package/dist/prometheus/doc/steps/proxifylocals.md +47 -47
  19. package/dist/prometheus/doc/steps/splitstrings.md +40 -40
  20. package/dist/prometheus/doc/steps/vmify.md +9 -9
  21. package/dist/prometheus/doc/steps/wrapinfunction.md +29 -29
  22. package/dist/prometheus/readme.md +57 -57
  23. package/dist/prometheus/readme.txt +4 -4
  24. package/package.json +5 -1
  25. package/src/index.ts +81 -75
  26. package/tsconfig.json +12 -12
  27. package/src/prometheus/.editorconfig +0 -4
  28. package/src/prometheus/.gitattributes +0 -2
  29. package/src/prometheus/.gitbook.yaml +0 -1
  30. package/src/prometheus/.github/ISSUE_TEMPLATE/bug_report.md +0 -25
  31. package/src/prometheus/.github/workflows/Build.yml +0 -49
  32. package/src/prometheus/.github/workflows/Test.yml +0 -19
  33. package/src/prometheus/LICENSE +0 -661
  34. package/src/prometheus/benchmark.lua +0 -34
  35. package/src/prometheus/build.bat +0 -10
  36. package/src/prometheus/cli.lua +0 -12
  37. package/src/prometheus/doc/README.md +0 -11
  38. package/src/prometheus/doc/SUMMARY.md +0 -27
  39. package/src/prometheus/doc/advanced/using-prometheus-in-your-lua-application.md +0 -31
  40. package/src/prometheus/doc/getting-started/command-line-options.md +0 -13
  41. package/src/prometheus/doc/getting-started/installation.md +0 -11
  42. package/src/prometheus/doc/getting-started/obfuscating-your-first-script.md +0 -50
  43. package/src/prometheus/doc/getting-started/presets.md +0 -10
  44. package/src/prometheus/doc/getting-started/the-config-object.md +0 -58
  45. package/src/prometheus/doc/getting-started/writing-a-custom-config-file.md +0 -56
  46. package/src/prometheus/doc/steps/anti-tamper.md +0 -11
  47. package/src/prometheus/doc/steps/constantarray.md +0 -71
  48. package/src/prometheus/doc/steps/encryptstrings.md +0 -86
  49. package/src/prometheus/doc/steps/proxifylocals.md +0 -47
  50. package/src/prometheus/doc/steps/splitstrings.md +0 -40
  51. package/src/prometheus/doc/steps/vmify.md +0 -9
  52. package/src/prometheus/doc/steps/wrapinfunction.md +0 -29
  53. package/src/prometheus/prometheus-main.lua +0 -1
  54. package/src/prometheus/readme.md +0 -57
  55. package/src/prometheus/readme.txt +0 -5
  56. package/src/prometheus/src/cli.lua +0 -154
  57. package/src/prometheus/src/colors.lua +0 -61
  58. package/src/prometheus/src/highlightlua.lua +0 -61
  59. package/src/prometheus/src/logger.lua +0 -62
  60. package/src/prometheus/src/presets.lua +0 -174
  61. package/src/prometheus/src/prometheus/ast.lua +0 -792
  62. package/src/prometheus/src/prometheus/bit.lua +0 -521
  63. package/src/prometheus/src/prometheus/compiler/compiler.lua +0 -2365
  64. package/src/prometheus/src/prometheus/enums.lua +0 -106
  65. package/src/prometheus/src/prometheus/namegenerators/Il.lua +0 -41
  66. package/src/prometheus/src/prometheus/namegenerators/confuse.lua +0 -169
  67. package/src/prometheus/src/prometheus/namegenerators/mangled.lua +0 -26
  68. package/src/prometheus/src/prometheus/namegenerators/mangled_shuffled.lua +0 -35
  69. package/src/prometheus/src/prometheus/namegenerators/number.lua +0 -11
  70. package/src/prometheus/src/prometheus/namegenerators.lua +0 -7
  71. package/src/prometheus/src/prometheus/parser.lua +0 -969
  72. package/src/prometheus/src/prometheus/pipeline.lua +0 -250
  73. package/src/prometheus/src/prometheus/randomLiterals.lua +0 -41
  74. package/src/prometheus/src/prometheus/randomStrings.lua +0 -24
  75. package/src/prometheus/src/prometheus/scope.lua +0 -332
  76. package/src/prometheus/src/prometheus/step.lua +0 -79
  77. package/src/prometheus/src/prometheus/steps/AddVararg.lua +0 -33
  78. package/src/prometheus/src/prometheus/steps/AntiTamper.lua +0 -194
  79. package/src/prometheus/src/prometheus/steps/ConstantArray.lua +0 -521
  80. package/src/prometheus/src/prometheus/steps/EncryptStrings.lua +0 -239
  81. package/src/prometheus/src/prometheus/steps/NumbersToExpressions.lua +0 -82
  82. package/src/prometheus/src/prometheus/steps/ProxifyLocals.lua +0 -313
  83. package/src/prometheus/src/prometheus/steps/SplitStrings.lua +0 -338
  84. package/src/prometheus/src/prometheus/steps/Vmify.lua +0 -30
  85. package/src/prometheus/src/prometheus/steps/Watermark.lua +0 -61
  86. package/src/prometheus/src/prometheus/steps/WatermarkCheck.lua +0 -50
  87. package/src/prometheus/src/prometheus/steps/WrapInFunction.lua +0 -45
  88. package/src/prometheus/src/prometheus/steps.lua +0 -12
  89. package/src/prometheus/src/prometheus/tokenizer.lua +0 -546
  90. package/src/prometheus/src/prometheus/unparser.lua +0 -866
  91. package/src/prometheus/src/prometheus/util.lua +0 -297
  92. package/src/prometheus/src/prometheus/visitast.lua +0 -245
  93. package/src/prometheus/src/prometheus.lua +0 -71
  94. package/src/prometheus/tests/closures.lua +0 -12
  95. package/src/prometheus/tests/fibonacci.lua +0 -10
  96. package/src/prometheus/tests/loops.lua +0 -8
  97. package/src/prometheus/tests/primes.lua +0 -18
  98. package/src/prometheus/tests.lua +0 -149
@@ -1,521 +0,0 @@
1
- -- This Script is Part of the Prometheus Obfuscator by Levno_710
2
- --
3
- -- ConstantArray.lua
4
- --
5
- -- This Script provides a Simple Obfuscation Step that wraps the entire Script into a function
6
-
7
- -- TODO: Wrapper Functions
8
- -- TODO: Proxy Object for indexing: e.g: ARR[X] becomes ARR + X
9
-
10
- local Step = require("prometheus.step");
11
- local Ast = require("prometheus.ast");
12
- local Scope = require("prometheus.scope");
13
- local visitast = require("prometheus.visitast");
14
- local util = require("prometheus.util")
15
- local Parser = require("prometheus.parser");
16
- local enums = require("prometheus.enums")
17
-
18
- local LuaVersion = enums.LuaVersion;
19
- local AstKind = Ast.AstKind;
20
-
21
- local ConstantArray = Step:extend();
22
- ConstantArray.Description = "This Step will Extract all Constants and put them into an Array at the beginning of the script";
23
- ConstantArray.Name = "Constant Array";
24
-
25
- ConstantArray.SettingsDescriptor = {
26
- Treshold = {
27
- name = "Treshold",
28
- description = "The relative amount of nodes that will be affected",
29
- type = "number",
30
- default = 1,
31
- min = 0,
32
- max = 1,
33
- },
34
- StringsOnly = {
35
- name = "StringsOnly",
36
- description = "Wether to only Extract Strings",
37
- type = "boolean",
38
- default = false,
39
- },
40
- Shuffle = {
41
- name = "Shuffle",
42
- description = "Wether to shuffle the order of Elements in the Array",
43
- type = "boolean",
44
- default = true,
45
- },
46
- Rotate = {
47
- name = "Rotate",
48
- description = "Wether to rotate the String Array by a specific (random) amount. This will be undone on runtime.",
49
- type = "boolean",
50
- default = true,
51
- },
52
- LocalWrapperTreshold = {
53
- name = "LocalWrapperTreshold",
54
- description = "The relative amount of nodes functions, that will get local wrappers",
55
- type = "number",
56
- default = 1,
57
- min = 0,
58
- max = 1,
59
- },
60
- LocalWrapperCount = {
61
- name = "LocalWrapperCount",
62
- description = "The number of Local wrapper Functions per scope. This only applies if LocalWrapperTreshold is greater than 0",
63
- type = "number",
64
- min = 0,
65
- max = 512,
66
- default = 0,
67
- },
68
- LocalWrapperArgCount = {
69
- name = "LocalWrapperArgCount",
70
- description = "The number of Arguments to the Local wrapper Functions",
71
- type = "number",
72
- min = 1,
73
- default = 10,
74
- max = 200,
75
- };
76
- MaxWrapperOffset = {
77
- name = "MaxWrapperOffset",
78
- description = "The Max Offset for the Wrapper Functions",
79
- type = "number",
80
- min = 0,
81
- default = 65535,
82
- };
83
- Encoding = {
84
- name = "Encoding",
85
- description = "The Encoding to use for the Strings",
86
- type = "enum",
87
- default = "base64",
88
- values = {
89
- "none",
90
- "base64",
91
- },
92
- }
93
- }
94
-
95
- local function callNameGenerator(generatorFunction, ...)
96
- if(type(generatorFunction) == "table") then
97
- generatorFunction = generatorFunction.generateName;
98
- end
99
- return generatorFunction(...);
100
- end
101
-
102
- function ConstantArray:init(settings)
103
-
104
- end
105
-
106
- function ConstantArray:createArray()
107
- local entries = {};
108
- for i, v in ipairs(self.constants) do
109
- if type(v) == "string" then
110
- v = self:encode(v);
111
- end
112
- entries[i] = Ast.TableEntry(Ast.ConstantNode(v));
113
- end
114
- return Ast.TableConstructorExpression(entries);
115
- end
116
-
117
- function ConstantArray:indexing(index, data)
118
- if self.LocalWrapperCount > 0 and data.functionData.local_wrappers then
119
- local wrappers = data.functionData.local_wrappers;
120
- local wrapper = wrappers[math.random(#wrappers)];
121
-
122
- local args = {};
123
- local ofs = index - self.wrapperOffset - wrapper.offset;
124
- for i = 1, self.LocalWrapperArgCount, 1 do
125
- if i == wrapper.arg then
126
- args[i] = Ast.NumberExpression(ofs);
127
- else
128
- args[i] = Ast.NumberExpression(math.random(ofs - 1024, ofs + 1024));
129
- end
130
- end
131
-
132
- data.scope:addReferenceToHigherScope(wrappers.scope, wrappers.id);
133
- return Ast.FunctionCallExpression(Ast.IndexExpression(
134
- Ast.VariableExpression(wrappers.scope, wrappers.id),
135
- Ast.StringExpression(wrapper.index)
136
- ), args);
137
- else
138
- data.scope:addReferenceToHigherScope(self.rootScope, self.wrapperId);
139
- return Ast.FunctionCallExpression(Ast.VariableExpression(self.rootScope, self.wrapperId), {
140
- Ast.NumberExpression(index - self.wrapperOffset);
141
- });
142
- end
143
- end
144
-
145
- function ConstantArray:getConstant(value, data)
146
- if(self.lookup[value]) then
147
- return self:indexing(self.lookup[value], data)
148
- end
149
- local idx = #self.constants + 1;
150
- self.constants[idx] = value;
151
- self.lookup[value] = idx;
152
- return self:indexing(idx, data);
153
- end
154
-
155
- function ConstantArray:addConstant(value)
156
- if(self.lookup[value]) then
157
- return
158
- end
159
- local idx = #self.constants + 1;
160
- self.constants[idx] = value;
161
- self.lookup[value] = idx;
162
- end
163
-
164
- local function reverse(t, i, j)
165
- while i < j do
166
- t[i], t[j] = t[j], t[i]
167
- i, j = i+1, j-1
168
- end
169
- end
170
-
171
- local function rotate(t, d, n)
172
- n = n or #t
173
- d = (d or 1) % n
174
- reverse(t, 1, n)
175
- reverse(t, 1, d)
176
- reverse(t, d+1, n)
177
- end
178
-
179
- local rotateCode = [=[
180
- for i, v in ipairs({{1, LEN}, {1, SHIFT}, {SHIFT + 1, LEN}}) do
181
- while v[1] < v[2] do
182
- ARR[v[1]], ARR[v[2]], v[1], v[2] = ARR[v[2]], ARR[v[1]], v[1] + 1, v[2] - 1
183
- end
184
- end
185
- ]=];
186
-
187
- function ConstantArray:addRotateCode(ast, shift)
188
- local parser = Parser:new({
189
- LuaVersion = LuaVersion.Lua51;
190
- });
191
-
192
- local newAst = parser:parse(string.gsub(string.gsub(rotateCode, "SHIFT", tostring(shift)), "LEN", tostring(#self.constants)));
193
- local forStat = newAst.body.statements[1];
194
- forStat.body.scope:setParent(ast.body.scope);
195
- visitast(newAst, nil, function(node, data)
196
- if(node.kind == AstKind.VariableExpression) then
197
- if(node.scope:getVariableName(node.id) == "ARR") then
198
- data.scope:removeReferenceToHigherScope(node.scope, node.id);
199
- data.scope:addReferenceToHigherScope(self.rootScope, self.arrId);
200
- node.scope = self.rootScope;
201
- node.id = self.arrId;
202
- end
203
- end
204
- end)
205
-
206
- table.insert(ast.body.statements, 1, forStat);
207
- end
208
-
209
- function ConstantArray:addDecodeCode(ast)
210
- if self.Encoding == "base64" then
211
- local base64DecodeCode = [[
212
- do ]] .. table.concat(util.shuffle{
213
- "local lookup = LOOKUP_TABLE;",
214
- "local len = string.len;",
215
- "local sub = string.sub;",
216
- "local floor = math.floor;",
217
- "local strchar = string.char;",
218
- "local insert = table.insert;",
219
- "local concat = table.concat;",
220
- "local type = type;",
221
- "local arr = ARR;",
222
- }) .. [[
223
- for i = 1, #arr do
224
- local data = arr[i];
225
- if type(data) == "string" then
226
- local length = len(data)
227
- local parts = {}
228
- local index = 1
229
- local value = 0
230
- local count = 0
231
- while index <= length do
232
- local char = sub(data, index, index)
233
- local code = lookup[char]
234
- if code then
235
- value = value + code * (64 ^ (3 - count))
236
- count = count + 1
237
- if count == 4 then
238
- count = 0
239
- local c1 = floor(value / 65536)
240
- local c2 = floor(value % 65536 / 256)
241
- local c3 = value % 256
242
- insert(parts, strchar(c1, c2, c3))
243
- value = 0
244
- end
245
- elseif char == "=" then
246
- insert(parts, strchar(floor(value / 65536)));
247
- if index >= length or sub(data, index + 1, index + 1) ~= "=" then
248
- insert(parts, strchar(floor(value % 65536 / 256)));
249
- end
250
- break
251
- end
252
- index = index + 1
253
- end
254
- arr[i] = concat(parts)
255
- end
256
- end
257
- end
258
- ]];
259
-
260
- local parser = Parser:new({
261
- LuaVersion = LuaVersion.Lua51;
262
- });
263
-
264
- local newAst = parser:parse(base64DecodeCode);
265
- local forStat = newAst.body.statements[1];
266
- forStat.body.scope:setParent(ast.body.scope);
267
-
268
- visitast(newAst, nil, function(node, data)
269
- if(node.kind == AstKind.VariableExpression) then
270
- if(node.scope:getVariableName(node.id) == "ARR") then
271
- data.scope:removeReferenceToHigherScope(node.scope, node.id);
272
- data.scope:addReferenceToHigherScope(self.rootScope, self.arrId);
273
- node.scope = self.rootScope;
274
- node.id = self.arrId;
275
- end
276
-
277
- if(node.scope:getVariableName(node.id) == "LOOKUP_TABLE") then
278
- data.scope:removeReferenceToHigherScope(node.scope, node.id);
279
- return self:createBase64Lookup();
280
- end
281
- end
282
- end)
283
-
284
- table.insert(ast.body.statements, 1, forStat);
285
- end
286
- end
287
-
288
- function ConstantArray:createBase64Lookup()
289
- local entries = {};
290
- local i = 0;
291
- for char in string.gmatch(self.base64chars, ".") do
292
- table.insert(entries, Ast.KeyedTableEntry(Ast.StringExpression(char), Ast.NumberExpression(i)));
293
- i = i + 1;
294
- end
295
- util.shuffle(entries);
296
- return Ast.TableConstructorExpression(entries);
297
- end
298
-
299
- function ConstantArray:encode(str)
300
- if self.Encoding == "base64" then
301
- return ((str:gsub('.', function(x)
302
- local r,b='',x:byte()
303
- for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
304
- return r;
305
- end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
306
- if (#x < 6) then return '' end
307
- local c=0
308
- for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end
309
- return self.base64chars:sub(c+1,c+1)
310
- end)..({ '', '==', '=' })[#str%3+1]);
311
- end
312
- end
313
-
314
- function ConstantArray:apply(ast, pipeline)
315
- self.rootScope = ast.body.scope;
316
- self.arrId = self.rootScope:addVariable();
317
-
318
- self.base64chars = table.concat(util.shuffle{
319
- "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
320
- "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
321
- "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
322
- "+", "/",
323
- });
324
-
325
- self.constants = {};
326
- self.lookup = {};
327
-
328
- -- Extract Constants
329
- visitast(ast, nil, function(node, data)
330
- -- Apply only to some nodes
331
- if math.random() <= self.Treshold then
332
- node.__apply_constant_array = true;
333
- if node.kind == AstKind.StringExpression then
334
- self:addConstant(node.value);
335
- elseif not self.StringsOnly then
336
- if node.isConstant then
337
- if node.value ~= nil then
338
- self:addConstant(node.value);
339
- end
340
- end
341
- end
342
- end
343
- end);
344
-
345
- -- Shuffle Array
346
- if self.Shuffle then
347
- self.constants = util.shuffle(self.constants);
348
- self.lookup = {};
349
- for i, v in ipairs(self.constants) do
350
- self.lookup[v] = i;
351
- end
352
- end
353
-
354
- -- Set Wrapper Function Offset
355
- self.wrapperOffset = math.random(-self.MaxWrapperOffset, self.MaxWrapperOffset);
356
- self.wrapperId = self.rootScope:addVariable();
357
-
358
- visitast(ast, function(node, data)
359
- -- Add Local Wrapper Functions
360
- if self.LocalWrapperCount > 0 and node.kind == AstKind.Block and node.isFunctionBlock and math.random() <= self.LocalWrapperTreshold then
361
- local id = node.scope:addVariable()
362
- data.functionData.local_wrappers = {
363
- id = id;
364
- scope = node.scope,
365
- };
366
- local nameLookup = {};
367
- for i = 1, self.LocalWrapperCount, 1 do
368
- local name;
369
- repeat
370
- name = callNameGenerator(pipeline.namegenerator, math.random(1, self.LocalWrapperArgCount * 16));
371
- until not nameLookup[name];
372
- nameLookup[name] = true;
373
-
374
- local offset = math.random(-self.MaxWrapperOffset, self.MaxWrapperOffset);
375
- local argPos = math.random(1, self.LocalWrapperArgCount);
376
-
377
- data.functionData.local_wrappers[i] = {
378
- arg = argPos,
379
- index = name,
380
- offset = offset,
381
- };
382
- data.functionData.__used = false;
383
- end
384
- end
385
- if node.__apply_constant_array then
386
- data.functionData.__used = true;
387
- end
388
- end, function(node, data)
389
- -- Actually insert Statements to get the Constant Values
390
- if node.__apply_constant_array then
391
- if node.kind == AstKind.StringExpression then
392
- return self:getConstant(node.value, data);
393
- elseif not self.StringsOnly then
394
- if node.isConstant then
395
- return node.value ~= nil and self:getConstant(node.value, data);
396
- end
397
- end
398
- node.__apply_constant_array = nil;
399
- end
400
-
401
- -- Insert Local Wrapper Declarations
402
- if self.LocalWrapperCount > 0 and node.kind == AstKind.Block and node.isFunctionBlock and data.functionData.local_wrappers and data.functionData.__used then
403
- data.functionData.__used = nil;
404
- local elems = {};
405
- local wrappers = data.functionData.local_wrappers;
406
- for i = 1, self.LocalWrapperCount, 1 do
407
- local wrapper = wrappers[i];
408
- local argPos = wrapper.arg;
409
- local offset = wrapper.offset;
410
- local name = wrapper.index;
411
-
412
- local funcScope = Scope:new(node.scope);
413
-
414
- local arg = nil;
415
- local args = {};
416
-
417
- for i = 1, self.LocalWrapperArgCount, 1 do
418
- args[i] = funcScope:addVariable();
419
- if i == argPos then
420
- arg = args[i];
421
- end
422
- end
423
-
424
- local addSubArg;
425
-
426
- -- Create add and Subtract code
427
- if offset < 0 then
428
- addSubArg = Ast.SubExpression(Ast.VariableExpression(funcScope, arg), Ast.NumberExpression(-offset));
429
- else
430
- addSubArg = Ast.AddExpression(Ast.VariableExpression(funcScope, arg), Ast.NumberExpression(offset));
431
- end
432
-
433
- funcScope:addReferenceToHigherScope(self.rootScope, self.wrapperId);
434
- local callArg = Ast.FunctionCallExpression(Ast.VariableExpression(self.rootScope, self.wrapperId), {
435
- addSubArg
436
- });
437
-
438
- local fargs = {};
439
- for i, v in ipairs(args) do
440
- fargs[i] = Ast.VariableExpression(funcScope, v);
441
- end
442
-
443
- elems[i] = Ast.KeyedTableEntry(
444
- Ast.StringExpression(name),
445
- Ast.FunctionLiteralExpression(fargs, Ast.Block({
446
- Ast.ReturnStatement({
447
- callArg
448
- });
449
- }, funcScope))
450
- )
451
- end
452
- table.insert(node.statements, 1, Ast.LocalVariableDeclaration(node.scope, {
453
- wrappers.id
454
- }, {
455
- Ast.TableConstructorExpression(elems)
456
- }));
457
- end
458
- end);
459
-
460
- self:addDecodeCode(ast);
461
-
462
- local steps = util.shuffle({
463
- -- Add Wrapper Function Code
464
- function()
465
- local funcScope = Scope:new(self.rootScope);
466
- -- Add Reference to Array
467
- funcScope:addReferenceToHigherScope(self.rootScope, self.arrId);
468
-
469
- local arg = funcScope:addVariable();
470
- local addSubArg;
471
-
472
- -- Create add and Subtract code
473
- if self.wrapperOffset < 0 then
474
- addSubArg = Ast.SubExpression(Ast.VariableExpression(funcScope, arg), Ast.NumberExpression(-self.wrapperOffset));
475
- else
476
- addSubArg = Ast.AddExpression(Ast.VariableExpression(funcScope, arg), Ast.NumberExpression(self.wrapperOffset));
477
- end
478
-
479
- -- Create and Add the Function Declaration
480
- table.insert(ast.body.statements, 1, Ast.LocalFunctionDeclaration(self.rootScope, self.wrapperId, {
481
- Ast.VariableExpression(funcScope, arg)
482
- }, Ast.Block({
483
- Ast.ReturnStatement({
484
- Ast.IndexExpression(
485
- Ast.VariableExpression(self.rootScope, self.arrId),
486
- addSubArg
487
- )
488
- });
489
- }, funcScope)));
490
-
491
- -- Resulting Code:
492
- -- function xy(a)
493
- -- return ARR[a - 10]
494
- -- end
495
- end,
496
- -- Rotate Array and Add unrotate code
497
- function()
498
- if self.Rotate and #self.constants > 1 then
499
- local shift = math.random(1, #self.constants - 1);
500
-
501
- rotate(self.constants, -shift);
502
- self:addRotateCode(ast, shift);
503
- end
504
- end,
505
- });
506
-
507
- for i, f in ipairs(steps) do
508
- f();
509
- end
510
-
511
- -- Add the Array Declaration
512
- table.insert(ast.body.statements, 1, Ast.LocalVariableDeclaration(self.rootScope, {self.arrId}, {self:createArray()}));
513
-
514
- self.rootScope = nil;
515
- self.arrId = nil;
516
-
517
- self.constants = nil;
518
- self.lookup = nil;
519
- end
520
-
521
- return ConstantArray;