Skip to content

Commit aa12494

Browse files
authored
Alpha v0.1
2 parents 41f3167 + f8f39bb commit aa12494

File tree

18 files changed

+304
-79
lines changed

18 files changed

+304
-79
lines changed

cli.lua

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
-- This Script is Part of the Prometheus Obfuscator by Levno_710
2+
--
3+
-- test.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+
local Prometheus = require("src.prometheus");
13+
Prometheus.Logger.logLevel = Prometheus.Logger.LogLevel.Info;
14+
15+
-- see if the file exists
16+
local function file_exists(file)
17+
local f = io.open(file, "rb")
18+
if f then f:close() end
19+
return f ~= nil
20+
end
21+
22+
-- get all lines from a file, returns an empty
23+
-- list/table if the file does not exist
24+
local function lines_from(file)
25+
if not file_exists(file) then return {} end
26+
local lines = {}
27+
for line in io.lines(file) do
28+
lines[#lines + 1] = line
29+
end
30+
return lines
31+
end
32+
33+
-- CLI
34+
local config;
35+
local sourceFile;
36+
local outFile;
37+
38+
-- Parse Arguments
39+
local i = 1;
40+
while i <= #arg do
41+
local curr = arg[i];
42+
if curr:sub(1, 2) == "--" then
43+
if curr == "--preset" or curr == "--p" then
44+
if config then
45+
Prometheus.Logger:warn("The config was set multiple times");
46+
end
47+
48+
i = i + 1;
49+
local preset = Prometheus.Presets[arg[i]];
50+
if not preset then
51+
Prometheus.Logger:error(string.format("A Preset with the name \"%s\" was not found!", tostring(arg[i])));
52+
end
53+
54+
config = preset;
55+
elseif curr == "--config" or curr == "--c" then
56+
i = i + 1;
57+
local filename = tostring(arg[i]);
58+
if not file_exists(filename) then
59+
Prometheus.Logger:error(string.format("The config file \"%s\" was not found!", filename));
60+
end
61+
62+
local content = table.concat(lines_from(filename), "\n");
63+
-- Load Config from File
64+
local func = loadstring(content);
65+
-- Sandboxing
66+
setfenv(func, {});
67+
config = func();
68+
elseif curr == "--out" or curr == "--o" then
69+
i = i + 1;
70+
if(outFile) then
71+
Prometheus.Logger:warn("The output file was specified multiple times!");
72+
end
73+
outFile = arg[i];
74+
else
75+
Prometheus.Logger:warn(string.format("The option \"%s\" is not valid and therefore ignored"));
76+
end
77+
else
78+
if sourceFile then
79+
Prometheus.Logger:error(string.format("Unexpected argument \"%s\"", arg[i]));
80+
end
81+
sourceFile = tostring(arg[i]);
82+
end
83+
i = i + 1;
84+
end
85+
86+
if not config then
87+
Prometheus.Logger:warn("No config was specified, falling back to Minify preset");
88+
config = Prometheus.Presets.Minify;
89+
end
90+
91+
if not file_exists(sourceFile) then
92+
Prometheus.Logger:error(string.format("The File \"%s\" was not found!", sourceFile));
93+
end
94+
95+
if not outFile then
96+
if sourceFile:sub(-4) == ".lua" then
97+
outFile = sourceFile:sub(0, -5) .. ".obfuscated.lua";
98+
else
99+
outFile = sourceFile .. ".obfuscated.lua";
100+
end
101+
end
102+
103+
local source = table.concat(lines_from(sourceFile), "\n");
104+
local pipeline = Prometheus.Pipeline:fromConfig(config);
105+
local out = pipeline:apply(source, sourceFile);
106+
Prometheus.Logger:info(string.format("Writing output to \"%s\"", outFile));
107+
108+
-- Write Output
109+
local handle = io.open(outFile, "w");
110+
handle:write(out);
111+
handle:close();

demo.lua

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

doc/SUMMARY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@
55
## Getting Started
66

77
* [Installation](getting-started/installation.md)
8+
9+
***
10+
11+
* [Obfuscating your first script](obfuscating-your-first-script.md)

doc/getting-started/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
To install Prometheus, simply clone the Github Repository using:
44

5-
```
5+
```batch
66
git clone https://github.com/Levno710/Prometheus.git
77
```
88

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Obfuscating your first script
2+
3+
Now that you have downloaded and Prometheus, you probably wonder how to use it. In this quick tutorial you are going to learn how to obfuscate your first file.
4+
5+
Note that in the following command examples `lua` should be replaced by your lua implementation.
6+
7+
Create the following file within the Prometheus main directory that you just downloaded:
8+
9+
{% code title="hello_world.lua" %}
10+
```lua
11+
print("Hello, World")
12+
```
13+
{% endcode %}
14+
15+
Now run the following command inside of the Prometheus directory:
16+
17+
```batch
18+
lua ./cli.lua ./hello_world.lua
19+
```
20+
21+
This should create the following file:
22+
23+
{% code title="hello_world.obfuscated.lua" %}
24+
```lua
25+
print("Hello, World")
26+
```
27+
{% endcode %}
28+
29+
As you can see, the file hasn't changed at all. That is because by default prometheus is just a minifier and the code we gave it was already as small as possible. To actually obfuscate the file, prometheus must be told which obfuscation steps it should apply in which order. In order to do this, the cli has the `--preset` option which allows you to specify the name of a predefined configuration. There are currently only two presets:
30+
31+
* Minify
32+
* Strong
33+
34+
In order to perform the obfuscation, you need to specify that Prometheus should use the Strong preset:
35+
36+
```batch
37+
lua ./cli.lua --preset Strong ./hello_world.lua
38+
```
39+
40+
The `hello_world.obfuscated.lua` should now become around 20kB in size, but when running, it should still print "Hello World".

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Prometheus
1+
# :fire: Prometheus
22
Prometheus is a Lua obfuscator written in pure Lua.
33
[Documentation](https://levno-710.gitbook.io/prometheus/)
44

src/config.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
-- These may be changed
77

88
-- You are not allowed to change the following Variables
9-
local VERSION = "Alpha v0.5.1";
9+
local VERSION = "Alpha v0.1";
1010
local NAME = "Prometheus";
1111
local BY = "Levno_710";
1212

src/obfuscator/namegenerators.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
return {
2+
Mangled = require("obfuscator.namegenerators.mangled");
3+
MangledShuffled = require("obfuscator.namegenerators.mangled_shuffled");
4+
Il = require("obfuscator.namegenerators.Il");
5+
Number = require("obfuscator.namegenerators.number");
6+
}

src/obfuscator/pipeline.lua

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,10 @@ local util = require("obfuscator.util");
1212
local Parser = require("obfuscator.parser");
1313
local Unparser = require("obfuscator.unparser");
1414
local logger = require("logger");
15-
local Watermark = require("obfuscator.watermark");
1615

17-
local NameGenerators = {
18-
Mangled = require("obfuscator.namegenerators.mangled");
19-
MangledShuffled = require("obfuscator.namegenerators.mangled_shuffled");
20-
Il = require("obfuscator.namegenerators.Il");
21-
Number = require("obfuscator.namegenerators.number");
22-
}
16+
local NameGenerators = require("obfuscator.namegenerators");
2317

24-
local Steps = {
25-
WrapInFunction = require("obfuscator.steps.WrapInFunction");
26-
SplitStrings = require("obfuscator.steps.SplitStrings");
27-
LocalsToTable = require("obfuscator.steps.LocalsToTable");
28-
Vmify = require("obfuscator.steps.Vmify");
29-
ConstantArray = require("obfuscator.steps.ConstantArray");
30-
ProxifyLocals = require("obfuscator.steps.ProxifyLocals");
31-
}
18+
local Steps = require("obfuscator.steps");
3219

3320
local lookupify = util.lookupify;
3421
local LuaVersion = Enums.LuaVersion;
@@ -92,6 +79,30 @@ function Pipeline:new(settings)
9279
return pipeline;
9380
end
9481

82+
function Pipeline:fromConfig(config)
83+
local pipeline = Pipeline:new({
84+
LuaVersion = config.LuaVersion;
85+
PrettyPrint = config.PrettyPrint;
86+
VarNamePrefix = config.VarNamePrefix;
87+
Seed = config.Seed;
88+
});
89+
90+
-- Add all Steps defined in Config
91+
local steps = config.Steps or {};
92+
for i, step in ipairs(steps) do
93+
if type(step.Name) ~= "string" then
94+
logger:error("Step.Name must be a String");
95+
end
96+
local constructor = pipeline.Steps[step.Name];
97+
if not constructor then
98+
logger:error(string.format("The Step \"%s\" was not found!", step.Name));
99+
end
100+
pipeline:addStep(constructor:new(step.Settings or {}));
101+
end
102+
103+
return pipeline;
104+
end
105+
95106
function Pipeline:addStep(step)
96107
table.insert(self.steps, step);
97108
end
@@ -165,13 +176,6 @@ function Pipeline:apply(code, filename)
165176

166177
local parserTimeDiff = gettime() - parserStartTime;
167178
logger:info(string.format("Parsing Done in %.2f seconds", parserTimeDiff));
168-
169-
-- TODO: Apply Watermark Check Step
170-
local watermark;
171-
if(#self.steps > 0) then
172-
watermark = Watermark:new();
173-
end
174-
175179

176180
-- User Defined Steps
177181
for i, step in ipairs(self.steps) do
@@ -184,11 +188,6 @@ function Pipeline:apply(code, filename)
184188
logger:info(string.format("Step \"%s\" Done in %.2f seconds", step.Name or "Unnamed", gettime() - stepStartTime));
185189
end
186190

187-
-- TODO: Apply Watermark Step
188-
if watermark then
189-
watermark:apply(ast);
190-
end
191-
192191
-- Rename Variables Step
193192
self:renameVariables(ast);
194193

src/obfuscator/steps.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
return {
2+
WrapInFunction = require("obfuscator.steps.WrapInFunction");
3+
SplitStrings = require("obfuscator.steps.SplitStrings");
4+
LocalsToTable = require("obfuscator.steps.LocalsToTable");
5+
Vmify = require("obfuscator.steps.Vmify");
6+
ConstantArray = require("obfuscator.steps.ConstantArray");
7+
ProxifyLocals = require("obfuscator.steps.ProxifyLocals");
8+
}

0 commit comments

Comments
 (0)