Skip to content

Commit 92c7915

Browse files
authored
Merge pull request #9 from levno-710/develop
Added Windows build and binaries
2 parents 1755eb6 + c792951 commit 92c7915

File tree

6 files changed

+148
-107
lines changed

6 files changed

+148
-107
lines changed

.gitignore

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Ignore Vscode Folder
22
.vscode
3-
# Ignore Lua Implementation
3+
4+
# Ignore Lua Implementation and srlua
45
lua51.dll
5-
luajit.exe
6+
luajit.exe
7+
srlua
8+
luajit
9+
buildnotes.txt
10+
srlua.exe
11+
glue.exe
12+
build

build.bat

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@echo off
2+
ECHO Building Prometheus ...
3+
RMDIR /s /q build
4+
MKDIR build
5+
glue.exe ./srlua.exe prometheus-main.lua build/prometheus.exe
6+
robocopy ./src ./build/lua /E>nul
7+
8+
robocopy . ./build lua51.dll>nul
9+
10+
ECHO Done!

cli.lua

Lines changed: 2 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -6,110 +6,7 @@
66
-- Configure package.path for requiring Prometheus
77
local function script_path()
88
local str = debug.getinfo(2, "S").source:sub(2)
9-
return str:match("(.*[/%\\])")
9+
return str:match("(.*[/%\\])") or "";
1010
end
1111
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-
Prometheus.colors.enabled = true;
39-
40-
-- Parse Arguments
41-
local i = 1;
42-
while i <= #arg do
43-
local curr = arg[i];
44-
if curr:sub(1, 2) == "--" then
45-
if curr == "--preset" or curr == "--p" then
46-
if config then
47-
Prometheus.Logger:warn("The config was set multiple times");
48-
end
49-
50-
i = i + 1;
51-
local preset = Prometheus.Presets[arg[i]];
52-
if not preset then
53-
Prometheus.Logger:error(string.format("A Preset with the name \"%s\" was not found!", tostring(arg[i])));
54-
end
55-
56-
config = preset;
57-
elseif curr == "--config" or curr == "--c" then
58-
i = i + 1;
59-
local filename = tostring(arg[i]);
60-
if not file_exists(filename) then
61-
Prometheus.Logger:error(string.format("The config file \"%s\" was not found!", filename));
62-
end
63-
64-
local content = table.concat(lines_from(filename), "\n");
65-
-- Load Config from File
66-
local func = loadstring(content);
67-
-- Sandboxing
68-
setfenv(func, {});
69-
config = func();
70-
elseif curr == "--out" or curr == "--o" then
71-
i = i + 1;
72-
if(outFile) then
73-
Prometheus.Logger:warn("The output file was specified multiple times!");
74-
end
75-
outFile = arg[i];
76-
elseif curr == "--nocolors" then
77-
Prometheus.colors.enabled = false;
78-
else
79-
Prometheus.Logger:warn(string.format("The option \"%s\" is not valid and therefore ignored"));
80-
end
81-
else
82-
if sourceFile then
83-
Prometheus.Logger:error(string.format("Unexpected argument \"%s\"", arg[i]));
84-
end
85-
sourceFile = tostring(arg[i]);
86-
end
87-
i = i + 1;
88-
end
89-
90-
if not config then
91-
Prometheus.Logger:warn("No config was specified, falling back to Minify preset");
92-
config = Prometheus.Presets.Minify;
93-
end
94-
95-
if not file_exists(sourceFile) then
96-
Prometheus.Logger:error(string.format("The File \"%s\" was not found!", sourceFile));
97-
end
98-
99-
if not outFile then
100-
if sourceFile:sub(-4) == ".lua" then
101-
outFile = sourceFile:sub(0, -5) .. ".obfuscated.lua";
102-
else
103-
outFile = sourceFile .. ".obfuscated.lua";
104-
end
105-
end
106-
107-
local source = table.concat(lines_from(sourceFile), "\n");
108-
local pipeline = Prometheus.Pipeline:fromConfig(config);
109-
local out = pipeline:apply(source, sourceFile);
110-
Prometheus.Logger:info(string.format("Writing output to \"%s\"", outFile));
111-
112-
-- Write Output
113-
local handle = io.open(outFile, "w");
114-
handle:write(out);
115-
handle:close();
12+
require("src.cli");

doc/obfuscating-your-first-script.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ Now run the following command inside of the Prometheus directory:
1818
lua ./cli.lua ./hello_world.lua
1919
```
2020

21+
You may notice, that the console output looks weird. If that is the case, your terminal does not support ansi color escape sequences. You should add the `--nocolors` option:
22+
23+
```batch
24+
lua ./cli.lua --nocolors ./hello_world.lua
25+
```
26+
2127
This should create the following file:
2228

2329
{% code title="hello_world.obfuscated.lua" %}

prometheus-main.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require("cli")

src/cli.lua

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

0 commit comments

Comments
 (0)