Prometheus
/
tests.lua
149 строк · 4.1 Кб
1-- This Script is Part of the Prometheus Obfuscator by Levno_710
2--
3-- test.lua
4-- This file will Perform tests using all lua files within the tests directory
5
6-- Require Prometheus
7local Prometheus = require("src.prometheus")
8
9-- Enable Debugging
10-- logger.logLevel = logger.LogLevel.Debug;
11
12-- Config Variables - Later passed as Parameters
13local noColors = false; -- Wether Colors in the Console output should be enabled
14local isWindows = true; -- Wether the Test are Performed on a Windows or Linux System
15local ciMode = false; -- Wether the Test error are ignored or not
16
17for _, currArg in pairs(arg) do
18if currArg == "--Linux" then
19isWindows = false
20end
21if currArg == "--CI" then
22ciMode = true
23end
24end
25
26-- Enable/Disable Console Colors - this may be needed because cmd.exe and powershell.exe do not support ANSI Color Escape Sequences. The Windows Terminal Application is needed
27Prometheus.colors.enabled = not noColors;
28
29-- Apply Obfuscation Pipeline
30local pipeline = Prometheus.Pipeline:new({
31Seed = 0; -- For Using Time as Seed
32VarNamePrefix = ""; -- No Custom Prefix
33});
34
35-- "Mangled" for names like this : a, b, c, d, ...
36-- "MangledShuffled" is the same except the chars come in a different order - Recomended
37-- "Il" for weird names like this : IlIIl1llI11l1 - Recomended to make less readable
38-- "Number" for names like this : _1, _2, _3, ... - Not recomended
39pipeline:setNameGenerator("MangledShuffled");
40
41print("Performing Prometheus Tests ...")
42local function scandir(directory)
43local i, t, popen = 0, {}, io.popen
44local pfile = popen(isWindows and 'dir "'..directory..'" /b' or 'ls -a "'..directory..'"')
45for filename in pfile:lines() do
46if string.sub(filename, -4) == ".lua" then
47i = i + 1
48t[i] = filename
49end
50end
51pfile:close()
52return t
53end
54
55local function shallowcopy(orig)
56local orig_type = type(orig)
57local copy
58if orig_type == 'table' then
59copy = {}
60for orig_key, orig_value in pairs(orig) do
61copy[orig_key] = orig_value
62end
63else -- number, string, boolean, etc
64copy = orig
65end
66return copy
67end
68
69local function validate(a, b)
70local outa = "";
71local outb = "";
72
73local enva = shallowcopy(getfenv(a));
74local envb = shallowcopy(getfenv(a));
75
76enva.print = function(...)
77for i, v in ipairs({...}) do
78outa = outa .. tostring(v);
79end
80end
81
82envb.print = function(...)
83for i, v in ipairs({...}) do
84outb = outb .. tostring(v);
85end
86end
87
88setfenv(a, enva);
89setfenv(b, envb);
90
91if(not pcall(a)) then error("Expected Reference Program not to Fail!") end
92if(not pcall(b)) then return false, outa, nil end
93
94return outa == outb, outa, outb
95end
96
97
98local presets = Prometheus.Presets;
99local testdir = "./tests/"
100local failed = {};
101Prometheus.Logger.logLevel = Prometheus.Logger.LogLevel.Error;
102local fc = 0;
103for i, filename in ipairs(scandir(testdir)) do
104local path = testdir .. filename;
105local file = io.open(path,"r");
106
107local code = file:read("*a");
108print(Prometheus.colors("[CURRENT] ", "magenta") .. filename);
109for name, preset in pairs(presets) do
110for i = #preset.Steps, 1, -1 do
111if preset.Steps[i].Name == "AntiTamper" then
112table.remove(preset.Steps, i);
113end
114end
115pipeline = Prometheus.Pipeline:fromConfig(preset);
116local obfuscated = pipeline:apply(code);
117
118local funca = loadstring(code);
119local funcb = loadstring(obfuscated);
120
121if funcb == nil then
122print(Prometheus.colors("[FAILED] ", "red") .. "(" .. filename .. "): " .. name .. ", Invalid Lua!");
123print("[SOURCE]", obfuscated);
124fc = fc + 1;
125else
126local validated, outa, outb = validate(funca, funcb);
127
128if not validated then
129print(Prometheus.colors("[FAILED] ", "red") .. "(" .. filename .. "): " .. name);
130print("[OUTA] ", outa);
131print("[OUTB] ", outb);
132print("[SOURCE]", obfuscated);
133fc = fc + 1;
134end
135end
136end
137file:close();
138end
139
140if fc < 1 then
141print(Prometheus.colors("[PASSED] ", "green") .. "All tests passed!");
142return 0;
143else
144print(Prometheus.colors("[FAILED] ", "red") .. "Some tests failed!");
145if ciMode then
146error("Test Failed!")
147end
148return -1;
149end