-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
304 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
-- 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; | ||
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; | ||
|
||
-- 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]; | ||
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Obfuscating your first script | ||
|
||
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. | ||
|
||
Note that in the following command examples `lua` should be replaced by your lua implementation. | ||
|
||
Create the following file within the Prometheus main directory that you just downloaded: | ||
|
||
{% code title="hello_world.lua" %} | ||
```lua | ||
print("Hello, World") | ||
``` | ||
{% endcode %} | ||
|
||
Now run the following command inside of the Prometheus directory: | ||
|
||
```batch | ||
lua ./cli.lua ./hello_world.lua | ||
``` | ||
|
||
This should create the following file: | ||
|
||
{% code title="hello_world.obfuscated.lua" %} | ||
```lua | ||
print("Hello, World") | ||
``` | ||
{% endcode %} | ||
|
||
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: | ||
|
||
* Minify | ||
* Strong | ||
|
||
In order to perform the obfuscation, you need to specify that Prometheus should use the Strong preset: | ||
|
||
```batch | ||
lua ./cli.lua --preset Strong ./hello_world.lua | ||
``` | ||
|
||
The `hello_world.obfuscated.lua` should now become around 20kB in size, but when running, it should still print "Hello World". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
return { | ||
Mangled = require("obfuscator.namegenerators.mangled"); | ||
MangledShuffled = require("obfuscator.namegenerators.mangled_shuffled"); | ||
Il = require("obfuscator.namegenerators.Il"); | ||
Number = require("obfuscator.namegenerators.number"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
return { | ||
WrapInFunction = require("obfuscator.steps.WrapInFunction"); | ||
SplitStrings = require("obfuscator.steps.SplitStrings"); | ||
LocalsToTable = require("obfuscator.steps.LocalsToTable"); | ||
Vmify = require("obfuscator.steps.Vmify"); | ||
ConstantArray = require("obfuscator.steps.ConstantArray"); | ||
ProxifyLocals = require("obfuscator.steps.ProxifyLocals"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.