warcraft-vscode 0.2.7 → 0.2.8

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 (42) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/bin/lua/cli.lua +154 -0
  3. package/bin/lua/colors.lua +61 -0
  4. package/bin/lua/config.lua +35 -0
  5. package/bin/lua/highlightlua.lua +61 -0
  6. package/bin/lua/logger.lua +62 -0
  7. package/bin/lua/presets.lua +174 -0
  8. package/bin/lua/prometheus/ast.lua +792 -0
  9. package/bin/lua/prometheus/bit.lua +521 -0
  10. package/bin/lua/prometheus/compiler/compiler.lua +2364 -0
  11. package/bin/lua/prometheus/enums.lua +106 -0
  12. package/bin/lua/prometheus/namegenerators/Il.lua +41 -0
  13. package/bin/lua/prometheus/namegenerators/confuse.lua +169 -0
  14. package/bin/lua/prometheus/namegenerators/mangled.lua +26 -0
  15. package/bin/lua/prometheus/namegenerators/mangled_shuffled.lua +35 -0
  16. package/bin/lua/prometheus/namegenerators/number.lua +11 -0
  17. package/bin/lua/prometheus/namegenerators.lua +7 -0
  18. package/bin/lua/prometheus/parser.lua +969 -0
  19. package/bin/lua/prometheus/pipeline.lua +250 -0
  20. package/bin/lua/prometheus/randomLiterals.lua +41 -0
  21. package/bin/lua/prometheus/randomStrings.lua +24 -0
  22. package/bin/lua/prometheus/scope.lua +332 -0
  23. package/bin/lua/prometheus/step.lua +79 -0
  24. package/bin/lua/prometheus/steps/AddVararg.lua +33 -0
  25. package/bin/lua/prometheus/steps/AntiTamper.lua +194 -0
  26. package/bin/lua/prometheus/steps/ConstantArray.lua +521 -0
  27. package/bin/lua/prometheus/steps/EncryptStrings.lua +239 -0
  28. package/bin/lua/prometheus/steps/NumbersToExpressions.lua +82 -0
  29. package/bin/lua/prometheus/steps/ProxifyLocals.lua +313 -0
  30. package/bin/lua/prometheus/steps/SplitStrings.lua +338 -0
  31. package/bin/lua/prometheus/steps/Vmify.lua +30 -0
  32. package/bin/lua/prometheus/steps/Watermark.lua +61 -0
  33. package/bin/lua/prometheus/steps/WatermarkCheck.lua +50 -0
  34. package/bin/lua/prometheus/steps/WrapInFunction.lua +45 -0
  35. package/bin/lua/prometheus/steps.lua +12 -0
  36. package/bin/lua/prometheus/tokenizer.lua +546 -0
  37. package/bin/lua/prometheus/unparser.lua +866 -0
  38. package/bin/lua/prometheus/util.lua +297 -0
  39. package/bin/lua/prometheus/visitast.lua +245 -0
  40. package/bin/lua/prometheus.lua +71 -0
  41. package/out/cli.js +1 -1
  42. package/package.json +10 -4
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [0.2.8](https://github.com/warcraft-iii/warcraft-vscode/compare/v0.2.7...v0.2.8) (2024-07-10)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Parameters are not correctly confused ([11b91c9](https://github.com/warcraft-iii/warcraft-vscode/commit/11b91c94f55db1eee7b64f36e955f0b54f7f49ee))
7
+
8
+
9
+ ### Features
10
+
11
+ * Adding the lua code obfuscation module ([494b40c](https://github.com/warcraft-iii/warcraft-vscode/commit/494b40cf5c04107a3f8a4eebe85746538515a9c0))
12
+
13
+
14
+
1
15
  ## [0.2.7](https://github.com/warcraft-iii/warcraft-vscode/compare/v0.2.6...v0.2.7) (2024-07-09)
2
16
 
3
17
 
@@ -0,0 +1,154 @@
1
+ -- This Script is Part of the Prometheus Obfuscator by Levno_710
2
+ --
3
+ -- cli.lua
4
+ -- This script contains the Code for the Prometheus CLI
5
+
6
+ -- Configure package.path for requiring Prometheus
7
+ local function script_path()
8
+ local str = debug.getinfo(2, "S").source:sub(2)
9
+ return str:match("(.*[/%\\])")
10
+ end
11
+ package.path = script_path() .. "?.lua;" .. package.path;
12
+ ---@diagnostic disable-next-line: different-requires
13
+ local Prometheus = require("prometheus");
14
+ Prometheus.Logger.logLevel = Prometheus.Logger.LogLevel.Info;
15
+
16
+ -- Check if the file exists
17
+ local function file_exists(file)
18
+ local f = io.open(file, "rb")
19
+ if f then f:close() end
20
+ return f ~= nil
21
+ end
22
+
23
+ string.split = function(str, sep)
24
+ local fields = {}
25
+ local pattern = string.format("([^%s]+)", sep)
26
+ str:gsub(pattern, function(c) fields[#fields+1] = c end)
27
+ return fields
28
+ end
29
+
30
+ -- get all lines from a file, returns an empty
31
+ -- list/table if the file does not exist
32
+ local function lines_from(file)
33
+ if not file_exists(file) then return {} end
34
+ local lines = {}
35
+ for line in io.lines(file) do
36
+ lines[#lines + 1] = line
37
+ end
38
+ return lines
39
+ end
40
+
41
+ -- CLI
42
+ local config;
43
+ local sourceFile;
44
+ local outFile;
45
+ local luaVersion;
46
+ local prettyPrint;
47
+
48
+ Prometheus.colors.enabled = true;
49
+
50
+ -- Parse Arguments
51
+ local i = 1;
52
+ while i <= #arg do
53
+ local curr = arg[i];
54
+ if curr:sub(1, 2) == "--" then
55
+ if curr == "--preset" or curr == "--p" then
56
+ if config then
57
+ Prometheus.Logger:warn("The config was set multiple times");
58
+ end
59
+
60
+ i = i + 1;
61
+ local preset = Prometheus.Presets[arg[i]];
62
+ if not preset then
63
+ Prometheus.Logger:error(string.format("A Preset with the name \"%s\" was not found!", tostring(arg[i])));
64
+ end
65
+
66
+ config = preset;
67
+ elseif curr == "--config" or curr == "--c" then
68
+ i = i + 1;
69
+ local filename = tostring(arg[i]);
70
+ if not file_exists(filename) then
71
+ Prometheus.Logger:error(string.format("The config file \"%s\" was not found!", filename));
72
+ end
73
+
74
+ local content = table.concat(lines_from(filename), "\n");
75
+ -- Load Config from File
76
+ local func = loadstring(content);
77
+ -- Sandboxing
78
+ setfenv(func, {});
79
+ config = func();
80
+ elseif curr == "--out" or curr == "--o" then
81
+ i = i + 1;
82
+ if(outFile) then
83
+ Prometheus.Logger:warn("The output file was specified multiple times!");
84
+ end
85
+ outFile = arg[i];
86
+ elseif curr == "--nocolors" then
87
+ Prometheus.colors.enabled = false;
88
+ elseif curr == "--Lua51" then
89
+ luaVersion = "Lua51";
90
+ elseif curr == "--LuaU" then
91
+ luaVersion = "LuaU";
92
+ elseif curr == "--pretty" then
93
+ prettyPrint = true;
94
+ elseif curr == "--saveerrors" then
95
+ -- Override error callback
96
+ Prometheus.Logger.errorCallback = function(...)
97
+ print(Prometheus.colors(Prometheus.Config.NameUpper .. ": " .. ..., "red"))
98
+
99
+ local args = {...};
100
+ local message = table.concat(args, " ");
101
+
102
+ local fileName = sourceFile:sub(-4) == ".lua" and sourceFile:sub(0, -5) .. ".error.txt" or sourceFile .. ".error.txt";
103
+ local handle = io.open(fileName, "w");
104
+ handle:write(message);
105
+ handle:close();
106
+
107
+ os.exit(1);
108
+ end;
109
+ else
110
+ Prometheus.Logger:warn(string.format("The option \"%s\" is not valid and therefore ignored", curr));
111
+ end
112
+ else
113
+ if sourceFile then
114
+ Prometheus.Logger:error(string.format("Unexpected argument \"%s\"", arg[i]));
115
+ end
116
+ sourceFile = tostring(arg[i]);
117
+ end
118
+ i = i + 1;
119
+ end
120
+
121
+ if not sourceFile then
122
+ Prometheus.Logger:error("No input file was specified!")
123
+ end
124
+
125
+ if not config then
126
+ Prometheus.Logger:warn("No config was specified, falling back to Minify preset");
127
+ config = Prometheus.Presets.Minify;
128
+ end
129
+
130
+ -- Add Option to override Lua Version
131
+ config.LuaVersion = luaVersion or config.LuaVersion;
132
+ config.PrettyPrint = prettyPrint ~= nil and prettyPrint or config.PrettyPrint;
133
+
134
+ if not file_exists(sourceFile) then
135
+ Prometheus.Logger:error(string.format("The File \"%s\" was not found!", sourceFile));
136
+ end
137
+
138
+ if not outFile then
139
+ if sourceFile:sub(-4) == ".lua" then
140
+ outFile = sourceFile:sub(0, -5) .. ".obfuscated.lua";
141
+ else
142
+ outFile = sourceFile .. ".obfuscated.lua";
143
+ end
144
+ end
145
+
146
+ local source = table.concat(lines_from(sourceFile), "\n");
147
+ local pipeline = Prometheus.Pipeline:fromConfig(config);
148
+ local out = pipeline:apply(source, sourceFile);
149
+ Prometheus.Logger:info(string.format("Writing output to \"%s\"", outFile));
150
+
151
+ -- Write Output
152
+ local handle = io.open(outFile, "w");
153
+ handle:write(out);
154
+ handle:close();
@@ -0,0 +1,61 @@
1
+ -- This Script is Part of the Prometheus Obfuscator by Levno_710
2
+
3
+ local keys = {
4
+ reset = 0,
5
+
6
+ bright = 1,
7
+ dim = 2,
8
+ underline = 4,
9
+ blink = 5,
10
+ reverse = 7,
11
+ hidden = 8,
12
+
13
+ black = 30,
14
+ pink = 91,
15
+ red = 31,
16
+ green = 32,
17
+ yellow = 33,
18
+ blue = 34,
19
+ magenta = 35,
20
+ cyan = 36,
21
+ grey = 37,
22
+ gray = 37,
23
+ white = 97,
24
+
25
+ blackbg = 40,
26
+ redbg = 41,
27
+ greenbg = 42,
28
+ yellowbg = 43,
29
+ bluebg = 44,
30
+ magentabg = 45,
31
+ cyanbg = 46,
32
+ greybg = 47,
33
+ graybg = 47,
34
+ whitebg = 107,
35
+ }
36
+
37
+ local escapeString = string.char(27) .. '[%dm';
38
+ local function escapeNumber(number)
39
+ return escapeString:format(number)
40
+ end
41
+
42
+
43
+ local settings = {
44
+ enabled = true,
45
+ }
46
+
47
+ local function colors(str, ...)
48
+ if not settings.enabled then
49
+ return str;
50
+ end
51
+ str = tostring(str or '')
52
+
53
+ local escapes = {};
54
+ for i, name in ipairs({...}) do
55
+ table.insert(escapes, escapeNumber(keys[name]))
56
+ end
57
+
58
+ return escapeNumber(keys.reset) .. table.concat(escapes) .. str .. escapeNumber(keys.reset);
59
+ end
60
+
61
+ return setmetatable(settings, { __call = function(_, ...) return colors(...) end});
@@ -0,0 +1,35 @@
1
+ -- This Script is Part of the Prometheus Obfuscator by Levno_710
2
+ --
3
+ -- config.lua
4
+ --
5
+ -- In this Script, some Global config Variables are defined
6
+
7
+ local NAME = "Prometheus";
8
+ local REVISION = "Alpha";
9
+ local VERSION = "v0.2";
10
+ local BY = "levno-710";
11
+
12
+ for _, currArg in pairs(arg) do
13
+ if currArg == "--CI" then
14
+ local releaseName = string.gsub(string.format("%s %s %s", NAME, REVISION, VERSION), "%s", "-")
15
+ print(releaseName)
16
+ end
17
+
18
+ if currArg == "--FullVersion" then
19
+ print(VERSION)
20
+ end
21
+ end
22
+
23
+ -- Config Starts here
24
+ return {
25
+ Name = NAME,
26
+ NameUpper = string.upper(NAME),
27
+ NameAndVersion = string.format("%s %s", NAME, VERSION),
28
+ Version = VERSION;
29
+ Revision = REVISION;
30
+ -- Config Starts Here
31
+ IdentPrefix = "__prometheus_"; -- The Prefix used for Identifiers generated by PROMETHEUS. NOTE: There should be no identifiers in the script to be obfuscated starting with that prefix, because that can lead to weird bugs
32
+
33
+ SPACE = " "; -- The Whitespace to be used by the unparser
34
+ TAB = "\t"; -- The Tab Whitespace to be used by the unparser for pretty printing
35
+ }
@@ -0,0 +1,61 @@
1
+ -- This Script is Part of the Prometheus Obfuscator by Levno_710
2
+ --
3
+ -- This Script provides a simple Method for Syntax Highlighting of Lua code
4
+
5
+ local Tokenizer = require("prometheus.tokenizer");
6
+ local colors = require("colors");
7
+ local TokenKind = Tokenizer.TokenKind;
8
+ local lookupify = require("prometheus.util").lookupify;
9
+
10
+ return function(code, luaVersion)
11
+ local out = "";
12
+ local tokenizer = Tokenizer:new({
13
+ LuaVersion = luaVersion,
14
+ });
15
+
16
+ tokenizer:append(code);
17
+ local tokens = tokenizer:scanAll();
18
+
19
+ local nonColorSymbols = lookupify{
20
+ ",", ";", "(", ")", "{", "}", ".", ":", "[", "]"
21
+ }
22
+
23
+ local defaultGlobals = lookupify{
24
+ "string", "table", "bit32", "bit"
25
+ }
26
+
27
+ local currentPos = 1;
28
+ for _, token in ipairs(tokens) do
29
+ if token.startPos >= currentPos then
30
+ out = out .. string.sub(code, currentPos, token.startPos);
31
+ end
32
+ if token.kind == TokenKind.Ident then
33
+ if defaultGlobals[token.source] then
34
+ out = out .. colors(token.source, "red");
35
+ else
36
+ out = out .. token.source;
37
+ end
38
+ elseif token.kind == TokenKind.Keyword then
39
+ if token.source == "nil" then
40
+ out = out .. colors(token.source, "yellow");
41
+ else
42
+ out = out .. colors(token.source, "yellow");
43
+ end
44
+ elseif token.kind == TokenKind.Symbol then
45
+ if nonColorSymbols[token.source] then
46
+ out = out .. token.source;
47
+ else
48
+ out = out .. colors(token.source, "yellow");
49
+ end
50
+ elseif token.kind == TokenKind.String then
51
+ out = out .. colors(token.source, "green")
52
+ elseif token.kind == TokenKind.Number then
53
+ out = out .. colors(token.source, "red")
54
+ else
55
+ out = out .. token.source;
56
+ end
57
+
58
+ currentPos = token.endPos + 1;
59
+ end
60
+ return out;
61
+ end
@@ -0,0 +1,62 @@
1
+ -- This Script is Part of the Prometheus Obfuscator by Levno_710
2
+ --
3
+ -- logger.lua
4
+
5
+ local logger = {}
6
+ local config = require("config");
7
+ local colors = require("colors");
8
+
9
+ logger.LogLevel = {
10
+ Error = 0,
11
+ Warn = 1,
12
+ Log = 2,
13
+ Info = 2,
14
+ Debug = 3,
15
+ }
16
+
17
+ logger.logLevel = logger.LogLevel.Log;
18
+
19
+ logger.debugCallback = function(...)
20
+ print(colors(config.NameUpper .. ": " .. ..., "grey"));
21
+ end;
22
+ function logger:debug(...)
23
+ if self.logLevel >= self.LogLevel.Debug then
24
+ self.debugCallback(...);
25
+ end
26
+ end
27
+
28
+ logger.logCallback = function(...)
29
+ print(colors(config.NameUpper .. ": ", "magenta") .. ...);
30
+ end;
31
+ function logger:log(...)
32
+ if self.logLevel >= self.LogLevel.Log then
33
+ self.logCallback(...);
34
+ end
35
+ end
36
+
37
+ function logger:info(...)
38
+ if self.logLevel >= self.LogLevel.Log then
39
+ self.logCallback(...);
40
+ end
41
+ end
42
+
43
+ logger.warnCallback = function(...)
44
+ print(colors(config.NameUpper .. ": " .. ..., "yellow"));
45
+ end;
46
+ function logger:warn(...)
47
+ if self.logLevel >= self.LogLevel.Warn then
48
+ self.warnCallback(...);
49
+ end
50
+ end
51
+
52
+ logger.errorCallback = function(...)
53
+ print(colors(config.NameUpper .. ": " .. ..., "red"))
54
+ error(...);
55
+ end;
56
+ function logger:error(...)
57
+ self.errorCallback(...);
58
+ error(config.NameUpper .. ": logger.errorCallback did not throw an Error!");
59
+ end
60
+
61
+
62
+ return logger;
@@ -0,0 +1,174 @@
1
+ -- This Script is Part of the Prometheus Obfuscator by Levno_710
2
+ --
3
+ -- pipeline.lua
4
+ --
5
+ -- This Script Provides some configuration presets
6
+
7
+ return {
8
+ ["Minify"] = {
9
+ -- The default LuaVersion is Lua51
10
+ LuaVersion = "Lua51";
11
+ -- For minifying no VarNamePrefix is applied
12
+ VarNamePrefix = "";
13
+ -- Name Generator for Variables
14
+ NameGenerator = "MangledShuffled";
15
+ -- No pretty printing
16
+ PrettyPrint = false;
17
+ -- Seed is generated based on current time
18
+ Seed = 0;
19
+ -- No obfuscation steps
20
+ Steps = {
21
+
22
+ }
23
+ };
24
+ ["Weak"] = {
25
+ -- The default LuaVersion is Lua51
26
+ LuaVersion = "Lua51";
27
+ -- For minifying no VarNamePrefix is applied
28
+ VarNamePrefix = "";
29
+ -- Name Generator for Variables that look like this: IlI1lI1l
30
+ NameGenerator = "MangledShuffled";
31
+ -- No pretty printing
32
+ PrettyPrint = false;
33
+ -- Seed is generated based on current time
34
+ Seed = 0;
35
+ -- Obfuscation steps
36
+ Steps = {
37
+ {
38
+ Name = "Vmify";
39
+ Settings = {
40
+
41
+ };
42
+ },
43
+ {
44
+ Name = "ConstantArray";
45
+ Settings = {
46
+ Treshold = 1;
47
+ StringsOnly = true;
48
+ }
49
+ },
50
+ {
51
+ Name = "WrapInFunction";
52
+ Settings = {
53
+
54
+ }
55
+ },
56
+ }
57
+ };
58
+ ["Medium"] = {
59
+ -- The default LuaVersion is Lua51
60
+ LuaVersion = "Lua51";
61
+ -- For minifying no VarNamePrefix is applied
62
+ VarNamePrefix = "";
63
+ -- Name Generator for Variables
64
+ NameGenerator = "MangledShuffled";
65
+ -- No pretty printing
66
+ PrettyPrint = false;
67
+ -- Seed is generated based on current time
68
+ Seed = 0;
69
+ -- Obfuscation steps
70
+ Steps = {
71
+ {
72
+ Name = "EncryptStrings";
73
+ Settings = {
74
+
75
+ };
76
+ },
77
+ {
78
+ Name = "AntiTamper";
79
+ Settings = {
80
+ UseDebug = false;
81
+ };
82
+ },
83
+ {
84
+ Name = "Vmify";
85
+ Settings = {
86
+
87
+ };
88
+ },
89
+ {
90
+ Name = "ConstantArray";
91
+ Settings = {
92
+ Treshold = 1;
93
+ StringsOnly = true;
94
+ Shuffle = true;
95
+ Rotate = true;
96
+ LocalWrapperTreshold = 0;
97
+ }
98
+ },
99
+ {
100
+ Name = "NumbersToExpressions";
101
+ Settings = {
102
+
103
+ }
104
+ },
105
+ {
106
+ Name = "WrapInFunction";
107
+ Settings = {
108
+
109
+ }
110
+ },
111
+ }
112
+ };
113
+ ["Strong"] = {
114
+ -- The default LuaVersion is Lua51
115
+ LuaVersion = "Lua51";
116
+ -- For minifying no VarNamePrefix is applied
117
+ VarNamePrefix = "";
118
+ -- Name Generator for Variables that look like this: IlI1lI1l
119
+ NameGenerator = "MangledShuffled";
120
+ -- No pretty printing
121
+ PrettyPrint = false;
122
+ -- Seed is generated based on current time
123
+ Seed = 0;
124
+ -- Obfuscation steps
125
+ Steps = {
126
+ {
127
+ Name = "Vmify";
128
+ Settings = {
129
+
130
+ };
131
+ },
132
+ {
133
+ Name = "EncryptStrings";
134
+ Settings = {
135
+
136
+ };
137
+ },
138
+ {
139
+ Name = "AntiTamper";
140
+ Settings = {
141
+
142
+ };
143
+ },
144
+ {
145
+ Name = "Vmify";
146
+ Settings = {
147
+
148
+ };
149
+ },
150
+ {
151
+ Name = "ConstantArray";
152
+ Settings = {
153
+ Treshold = 1;
154
+ StringsOnly = true;
155
+ Shuffle = true;
156
+ Rotate = true;
157
+ LocalWrapperTreshold = 0;
158
+ }
159
+ },
160
+ {
161
+ Name = "NumbersToExpressions";
162
+ Settings = {
163
+
164
+ }
165
+ },
166
+ {
167
+ Name = "WrapInFunction";
168
+ Settings = {
169
+
170
+ }
171
+ },
172
+ }
173
+ },
174
+ }