Skip to content

Commit

Permalink
Merge pull request #9 from levno-710/develop
Browse files Browse the repository at this point in the history
Added Windows build and binaries
  • Loading branch information
levno-710 authored Jan 1, 2022
2 parents 1755eb6 + c792951 commit 92c7915
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 107 deletions.
11 changes: 9 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Ignore Vscode Folder
.vscode
# Ignore Lua Implementation

# Ignore Lua Implementation and srlua
lua51.dll
luajit.exe
luajit.exe
srlua
luajit
buildnotes.txt
srlua.exe
glue.exe
build
10 changes: 10 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@echo off
ECHO Building Prometheus ...
RMDIR /s /q build
MKDIR build
glue.exe ./srlua.exe prometheus-main.lua build/prometheus.exe
robocopy ./src ./build/lua /E>nul

robocopy . ./build lua51.dll>nul

ECHO Done!
107 changes: 2 additions & 105 deletions cli.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,110 +6,7 @@
-- Configure package.path for requiring Prometheus
local function script_path()
local str = debug.getinfo(2, "S").source:sub(2)
return str:match("(.*[/%\\])")
return str:match("(.*[/%\\])") or "";
end
package.path = script_path() .. "?.lua;" .. package.path;
local Prometheus = require("src.prometheus");
Prometheus.Logger.logLevel = Prometheus.Logger.LogLevel.Info;

-- see if the file exists
local function file_exists(file)
local f = io.open(file, "rb")
if f then f:close() end
return f ~= nil
end

-- get all lines from a file, returns an empty
-- list/table if the file does not exist
local function lines_from(file)
if not file_exists(file) then return {} end
local lines = {}
for line in io.lines(file) do
lines[#lines + 1] = line
end
return lines
end

-- CLI
local config;
local sourceFile;
local outFile;

Prometheus.colors.enabled = true;

-- Parse Arguments
local i = 1;
while i <= #arg do
local curr = arg[i];
if curr:sub(1, 2) == "--" then
if curr == "--preset" or curr == "--p" then
if config then
Prometheus.Logger:warn("The config was set multiple times");
end

i = i + 1;
local preset = Prometheus.Presets[arg[i]];
if not preset then
Prometheus.Logger:error(string.format("A Preset with the name \"%s\" was not found!", tostring(arg[i])));
end

config = preset;
elseif curr == "--config" or curr == "--c" then
i = i + 1;
local filename = tostring(arg[i]);
if not file_exists(filename) then
Prometheus.Logger:error(string.format("The config file \"%s\" was not found!", filename));
end

local content = table.concat(lines_from(filename), "\n");
-- Load Config from File
local func = loadstring(content);
-- Sandboxing
setfenv(func, {});
config = func();
elseif curr == "--out" or curr == "--o" then
i = i + 1;
if(outFile) then
Prometheus.Logger:warn("The output file was specified multiple times!");
end
outFile = arg[i];
elseif curr == "--nocolors" then
Prometheus.colors.enabled = false;
else
Prometheus.Logger:warn(string.format("The option \"%s\" is not valid and therefore ignored"));
end
else
if sourceFile then
Prometheus.Logger:error(string.format("Unexpected argument \"%s\"", arg[i]));
end
sourceFile = tostring(arg[i]);
end
i = i + 1;
end

if not config then
Prometheus.Logger:warn("No config was specified, falling back to Minify preset");
config = Prometheus.Presets.Minify;
end

if not file_exists(sourceFile) then
Prometheus.Logger:error(string.format("The File \"%s\" was not found!", sourceFile));
end

if not outFile then
if sourceFile:sub(-4) == ".lua" then
outFile = sourceFile:sub(0, -5) .. ".obfuscated.lua";
else
outFile = sourceFile .. ".obfuscated.lua";
end
end

local source = table.concat(lines_from(sourceFile), "\n");
local pipeline = Prometheus.Pipeline:fromConfig(config);
local out = pipeline:apply(source, sourceFile);
Prometheus.Logger:info(string.format("Writing output to \"%s\"", outFile));

-- Write Output
local handle = io.open(outFile, "w");
handle:write(out);
handle:close();
require("src.cli");
6 changes: 6 additions & 0 deletions doc/obfuscating-your-first-script.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ Now run the following command inside of the Prometheus directory:
lua ./cli.lua ./hello_world.lua
```

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:

```batch
lua ./cli.lua --nocolors ./hello_world.lua
```

This should create the following file:

{% code title="hello_world.obfuscated.lua" %}
Expand Down
1 change: 1 addition & 0 deletions prometheus-main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("cli")
120 changes: 120 additions & 0 deletions src/cli.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
-- This Script is Part of the Prometheus Obfuscator by Levno_710
--
-- test.lua
-- This script contains the Code for the Prometheus CLI

-- Configure package.path for requiring Prometheus
local function script_path()
local str = debug.getinfo(2, "S").source:sub(2)
return str:match("(.*[/%\\])")
end
package.path = script_path() .. "?.lua;" .. package.path;
---@diagnostic disable-next-line: different-requires
local Prometheus = require("prometheus");
Prometheus.Logger.logLevel = Prometheus.Logger.LogLevel.Info;

-- see if the file exists
local function file_exists(file)
local f = io.open(file, "rb")
if f then f:close() end
return f ~= nil
end

-- get all lines from a file, returns an empty
-- list/table if the file does not exist
local function lines_from(file)
if not file_exists(file) then return {} end
local lines = {}
for line in io.lines(file) do
lines[#lines + 1] = line
end
return lines
end

-- CLI
local config;
local sourceFile;
local outFile;

Prometheus.colors.enabled = true;

-- Parse Arguments
local i = 1;
while i <= #arg do
local curr = arg[i];
if curr:sub(1, 2) == "--" then
if curr == "--preset" or curr == "--p" then
if config then
Prometheus.Logger:warn("The config was set multiple times");
end

i = i + 1;
local preset = Prometheus.Presets[arg[i]];
if not preset then
Prometheus.Logger:error(string.format("A Preset with the name \"%s\" was not found!", tostring(arg[i])));
end

config = preset;
elseif curr == "--config" or curr == "--c" then
i = i + 1;
local filename = tostring(arg[i]);
if not file_exists(filename) then
Prometheus.Logger:error(string.format("The config file \"%s\" was not found!", filename));
end

local content = table.concat(lines_from(filename), "\n");
-- Load Config from File
local func = loadstring(content);
-- Sandboxing
setfenv(func, {});
config = func();
elseif curr == "--out" or curr == "--o" then
i = i + 1;
if(outFile) then
Prometheus.Logger:warn("The output file was specified multiple times!");
end
outFile = arg[i];
elseif curr == "--nocolors" then
Prometheus.colors.enabled = false;
else
Prometheus.Logger:warn(string.format("The option \"%s\" is not valid and therefore ignored"));
end
else
if sourceFile then
Prometheus.Logger:error(string.format("Unexpected argument \"%s\"", arg[i]));
end
sourceFile = tostring(arg[i]);
end
i = i + 1;
end

if not sourceFile then
Prometheus.Logger:error("No input file was specified!")
end

if not config then
Prometheus.Logger:warn("No config was specified, falling back to Minify preset");
config = Prometheus.Presets.Minify;
end

if not file_exists(sourceFile) then
Prometheus.Logger:error(string.format("The File \"%s\" was not found!", sourceFile));
end

if not outFile then
if sourceFile:sub(-4) == ".lua" then
outFile = sourceFile:sub(0, -5) .. ".obfuscated.lua";
else
outFile = sourceFile .. ".obfuscated.lua";
end
end

local source = table.concat(lines_from(sourceFile), "\n");
local pipeline = Prometheus.Pipeline:fromConfig(config);
local out = pipeline:apply(source, sourceFile);
Prometheus.Logger:info(string.format("Writing output to \"%s\"", outFile));

-- Write Output
local handle = io.open(outFile, "w");
handle:write(out);
handle:close();

0 comments on commit 92c7915

Please sign in to comment.