forked from prometheus-lua/Prometheus
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtests.lua
More file actions
129 lines (105 loc) · 3.54 KB
/
tests.lua
File metadata and controls
129 lines (105 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
-- This Script is Part of the Prometheus Obfuscator by Levno_710
--
-- test.lua
-- This file will Perform tests using all lua files within the tests directory
-- Require Prometheus
local Prometheus = require("src.prometheus")
-- Enable Debugging
-- logger.logLevel = logger.LogLevel.Debug;
-- Config Variables - Later passed as Parameters
local noColors = false; -- Wether Colors in the Console output should be enabled
local noHighlight = false; -- Disable Syntax Highlighting of Outputed Code
local isWindows = true; -- Wether the Test are Performed on a Windows or Linux System
-- The Code to Obfuscate
local code = [=[
]=];
-- 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
Prometheus.colors.enabled = not noColors;
-- Apply Obfuscation Pipeline
local pipeline = Prometheus.Pipeline:new({
Seed = 0; -- For Using Time as Seed
VarNamePrefix = ""; -- No Custom Prefix
});
-- "Mangled" for names like this : a, b, c, d, ...
-- "MangledShuffled" is the same except the chars come in a different order - Recomended
-- "Il" for weird names like this : IlIIl1llI11l1 - Recomended to make less readable
-- "Number" for names like this : _1, _2, _3, ... - Not recomended
pipeline:setNameGenerator("MangledShuffled");
print("Performing Prometheus Tests ...")
local function scandir(directory)
local i, t, popen = 0, {}, io.popen
local pfile = popen(isWindows and 'dir "'..directory..'" /b' or 'ls -a "'..directory..'"')
for filename in pfile:lines() do
i = i + 1
t[i] = filename
end
pfile:close()
return t
end
local function shallowcopy(orig)
local orig_type = type(orig)
local copy
if orig_type == 'table' then
copy = {}
for orig_key, orig_value in pairs(orig) do
copy[orig_key] = orig_value
end
else -- number, string, boolean, etc
copy = orig
end
return copy
end
local function validate(a, b)
local outa = "";
local outb = "";
local enva = shallowcopy(getfenv(a));
local envb = shallowcopy(getfenv(a));
enva.print = function(...)
for i, v in ipairs({...}) do
outa = outa .. tostring(v);
end
end
envb.print = function(...)
for i, v in ipairs({...}) do
outb = outb .. tostring(v);
end
end
setfenv(a, enva);
setfenv(b, envb);
if(not pcall(a)) then error("Expected Reference Program not to Fail!") end
if(not pcall(b)) then return false, outa, nil end
return outa == outb, outa, outb
end
local steps = pipeline.Steps;
local testdir = "./tests/"
local failed = {};
Prometheus.Logger.logLevel = Prometheus.Logger.LogLevel.Error;
local fc = 0;
for i, filename in ipairs(scandir(testdir)) do
local path = testdir .. filename;
local file = io.open(path,"r");
local code = file:read("*a");
print(Prometheus.colors("[CURRENT] ", "magenta") .. filename);
for key, step in pairs(steps) do
pipeline:resetSteps();
pipeline:addStep(step:new({}));
local obfuscated = pipeline:apply(code);
local funca = loadstring(code);
local funcb = loadstring(obfuscated);
local validated, outa, outb = validate(funca, funcb);
if not validated then
print(Prometheus.colors("[FAILED] ", "red") .. "(" .. filename .. ") " .. step.Name);
print("[OUTA] ", outa);
print("[OUTB] ", outb);
fc = fc + 1;
end
end
file:close();
end
if fc < 1 then
print(Prometheus.colors("[PASSED] ", "green") .. "All tests passed!");
return 0;
else
print(Prometheus.colors("[FAILED] ", "red") .. "Some tests failed!");
return -1;
end