Skip to content

Commit 5c08e7c

Browse files
authored
Merge pull request #107 from prometheus-lua/master
Merge changes to dev branch
2 parents 2e21f42 + ad1ecf9 commit 5c08e7c

File tree

7 files changed

+162
-15
lines changed

7 files changed

+162
-15
lines changed

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,6 @@ lua ./cli.lua [options]
5555
- [pnlmon](https://github.com/pnlmon)
5656
- [britzl](https://github.com/britzl)
5757
- [SpinnySpiwal](https://github.com/SpinnySpiwal)
58+
- [oxince](https://github.com/oxince)
5859
## License
5960
This Project is Licensed under the GNU General Public License v3.0. For more details, please refer to [LICENSE](https://github.com/levno-710/Prometheus/blob/master/LICENSE).

src/cli.lua

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@ package.path = script_path() .. "?.lua;" .. package.path;
1313
local Prometheus = require("prometheus");
1414
Prometheus.Logger.logLevel = Prometheus.Logger.LogLevel.Info;
1515

16-
-- Override error callback
17-
--[[Prometheus.Logger.errorCallback = function(...)
18-
print(Prometheus.colors(Prometheus.Config.NameUpper .. ": " .. ..., "red"))
19-
os.exit(1);
20-
end]]
21-
2216
-- Check if the file exists
2317
local function file_exists(file)
2418
local f = io.open(file, "rb")
2519
if f then f:close() end
2620
return f ~= nil
2721
end
2822

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+
2930
-- get all lines from a file, returns an empty
3031
-- list/table if the file does not exist
3132
local function lines_from(file)
@@ -90,6 +91,21 @@ while i <= #arg do
9091
luaVersion = "LuaU";
9192
elseif curr == "--pretty" then
9293
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;
93109
else
94110
Prometheus.Logger:warn(string.format("The option \"%s\" is not valid and therefore ignored", curr));
95111
end

src/logger.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function logger:warn(...)
4949
end
5050
end
5151

52-
logger.errorCallback = function(...)
52+
logger.errorCallback = function(...)
5353
print(colors(config.NameUpper .. ": " .. ..., "red"))
5454
error(...);
5555
end;

src/presets.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ return {
3434
Seed = 0;
3535
-- Obfuscation steps
3636
Steps = {
37+
{
38+
Name = "WatermarkCheck";
39+
Settings = {
40+
Content = "This Script was obfuscated using the Weak Preset of Prometheus Obfuscator by Levno_710";
41+
}
42+
},
3743
{
3844
Name = "Vmify";
3945
Settings = {
@@ -68,6 +74,12 @@ return {
6874
Seed = 0;
6975
-- Obfuscation steps
7076
Steps = {
77+
{
78+
Name = "WatermarkCheck";
79+
Settings = {
80+
Content = "This Script was obfuscated using the Medium Preset of Prometheus Obfuscator by Levno_710";
81+
}
82+
},
7183
{
7284
Name = "EncryptStrings";
7385
Settings = {
@@ -123,6 +135,12 @@ return {
123135
Seed = 0;
124136
-- Obfuscation steps
125137
Steps = {
138+
{
139+
Name = "WatermarkCheck";
140+
Settings = {
141+
Content = "This Script was obfuscated using the Strong Preset of Prometheus Obfuscator by Levno_710";
142+
}
143+
},
126144
{
127145
Name = "Vmify";
128146
Settings = {

src/prometheus/steps.lua

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
return {
2-
WrapInFunction = require("prometheus.steps.WrapInFunction");
3-
SplitStrings = require("prometheus.steps.SplitStrings");
4-
Vmify = require("prometheus.steps.Vmify");
5-
ConstantArray = require("prometheus.steps.ConstantArray");
6-
ProxifyLocals = require("prometheus.steps.ProxifyLocals");
7-
AntiTamper = require("prometheus.steps.AntiTamper");
8-
EncryptStrings = require("prometheus.steps.EncryptStrings");
2+
WrapInFunction = require("prometheus.steps.WrapInFunction");
3+
SplitStrings = require("prometheus.steps.SplitStrings");
4+
Vmify = require("prometheus.steps.Vmify");
5+
ConstantArray = require("prometheus.steps.ConstantArray");
6+
ProxifyLocals = require("prometheus.steps.ProxifyLocals");
7+
AntiTamper = require("prometheus.steps.AntiTamper");
8+
EncryptStrings = require("prometheus.steps.EncryptStrings");
99
NumbersToExpressions = require("prometheus.steps.NumbersToExpressions");
10-
AddVararg = require("prometheus.steps.AddVararg");
10+
AddVararg = require("prometheus.steps.AddVararg");
11+
WatermarkCheck = require("prometheus.steps.WatermarkCheck");
1112
}

src/prometheus/steps/Watermark.lua

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
-- This Script is Part of the Prometheus Obfuscator by Levno_710
2+
--
3+
-- Watermark.lua
4+
--
5+
-- This Script provides a Step that will add a watermark to the script
6+
7+
local Step = require("prometheus.step");
8+
local Ast = require("prometheus.ast");
9+
local Scope = require("prometheus.scope");
10+
11+
local Watermark = Step:extend();
12+
Watermark.Description = "This Step will add a watermark to the script";
13+
Watermark.Name = "Watermark";
14+
15+
Watermark.SettingsDescriptor = {
16+
Content = {
17+
name = "Content",
18+
description = "The Content of the Watermark",
19+
type = "string",
20+
default = "This Script is Part of the Prometheus Obfuscator by Levno_710",
21+
},
22+
CustomVariable = {
23+
name = "Custom Variable",
24+
description = "The Variable that will be used for the Watermark",
25+
type = "string",
26+
default = "_WATERMARK",
27+
}
28+
}
29+
30+
function Watermark:init(settings)
31+
32+
end
33+
34+
function Watermark:apply(ast)
35+
local body = ast.body;
36+
if string.len(self.Content) > 0 then
37+
local scope, variable = ast.globalScope:resolve(self.CustomVariable);
38+
local watermark = Ast.AssignmentVariable(ast.globalScope, variable);
39+
40+
local functionScope = Scope:new(body.scope);
41+
functionScope:addReferenceToHigherScope(ast.globalScope, variable);
42+
43+
local arg = functionScope:addVariable();
44+
local statement = Ast.PassSelfFunctionCallStatement(Ast.StringExpression(self.Content), "gsub", {
45+
Ast.StringExpression(".+"),
46+
Ast.FunctionLiteralExpression({
47+
Ast.VariableExpression(functionScope, arg)
48+
}, Ast.Block({
49+
Ast.AssignmentStatement({
50+
watermark
51+
}, {
52+
Ast.VariableExpression(functionScope, arg)
53+
})
54+
}, functionScope))
55+
});
56+
57+
table.insert(ast.body.statements, 1, statement)
58+
end
59+
end
60+
61+
return Watermark;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
-- This Script is Part of the Prometheus Obfuscator by Levno_710
2+
--
3+
-- WatermarkCheck.lua
4+
--
5+
-- This Script provides a Step that will add a watermark to the script
6+
7+
local Step = require("prometheus.step");
8+
local Ast = require("prometheus.ast");
9+
local Scope = require("prometheus.scope");
10+
local Watermark = require("prometheus.steps.Watermark");
11+
12+
local WatermarkCheck = Step:extend();
13+
WatermarkCheck.Description = "This Step will add a watermark to the script";
14+
WatermarkCheck.Name = "WatermarkCheck";
15+
16+
WatermarkCheck.SettingsDescriptor = {
17+
Content = {
18+
name = "Content",
19+
description = "The Content of the WatermarkCheck",
20+
type = "string",
21+
default = "This Script is Part of the Prometheus Obfuscator by Levno_710",
22+
},
23+
}
24+
25+
local function callNameGenerator(generatorFunction, ...)
26+
if(type(generatorFunction) == "table") then
27+
generatorFunction = generatorFunction.generateName;
28+
end
29+
return generatorFunction(...);
30+
end
31+
32+
function WatermarkCheck:init(settings)
33+
34+
end
35+
36+
function WatermarkCheck:apply(ast, pipeline)
37+
self.CustomVariable = "_" .. callNameGenerator(pipeline.namegenerator, math.random(10000000000, 100000000000));
38+
pipeline:addStep(Watermark:new(self));
39+
40+
local body = ast.body;
41+
local watermarkExpression = Ast.StringExpression(self.Content);
42+
local scope, variable = ast.globalScope:resolve(self.CustomVariable);
43+
local watermark = Ast.VariableExpression(ast.globalScope, variable);
44+
local notEqualsExpression = Ast.NotEqualsExpression(watermark, watermarkExpression);
45+
local ifBody = Ast.Block({Ast.ReturnStatement({})}, Scope:new(ast.body.scope));
46+
47+
table.insert(body.statements, 1, Ast.IfStatement(notEqualsExpression, ifBody, {}, nil));
48+
end
49+
50+
return WatermarkCheck;

0 commit comments

Comments
 (0)