Prometheus

Форк
0
/
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
7
local Prometheus = require("src.prometheus")
8

9
-- Enable Debugging
10
-- logger.logLevel = logger.LogLevel.Debug;
11

12
-- Config Variables - Later passed as Parameters
13
local noColors    = false; -- Wether Colors in the Console output should be enabled
14
local isWindows = true;    -- Wether the Test are Performed on a Windows or Linux System
15
local ciMode = false; 	   -- Wether the Test error are ignored or not
16

17
for _, currArg in pairs(arg) do
18
	if currArg == "--Linux" then
19
		isWindows = false
20
	end
21
	if currArg == "--CI" then
22
		ciMode = true
23
	end
24
end
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
27
Prometheus.colors.enabled = not noColors;
28

29
-- Apply Obfuscation Pipeline
30
local pipeline = Prometheus.Pipeline:new({
31
	Seed = 0; -- For Using Time as Seed
32
	VarNamePrefix = ""; -- 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
39
pipeline:setNameGenerator("MangledShuffled");
40

41
print("Performing Prometheus Tests ...")
42
local function scandir(directory)
43
    local i, t, popen = 0, {}, io.popen
44
    local pfile = popen(isWindows and 'dir "'..directory..'" /b' or 'ls -a "'..directory..'"')
45
    for filename in pfile:lines() do
46
		if string.sub(filename, -4) == ".lua" then
47
			i = i + 1
48
			t[i] = filename
49
		end
50
    end
51
    pfile:close()
52
    return t
53
end
54

55
local function shallowcopy(orig)
56
    local orig_type = type(orig)
57
    local copy
58
    if orig_type == 'table' then
59
        copy = {}
60
        for orig_key, orig_value in pairs(orig) do
61
            copy[orig_key] = orig_value
62
        end
63
    else -- number, string, boolean, etc
64
        copy = orig
65
    end
66
    return copy
67
end
68

69
local function validate(a, b)
70
	local outa  = "";
71
	local outb  = "";
72

73
	local enva = shallowcopy(getfenv(a));
74
	local envb = shallowcopy(getfenv(a));
75

76
	enva.print = function(...)
77
		for i, v in ipairs({...}) do
78
			outa = outa .. tostring(v);
79
		end
80
	end
81
	
82
	envb.print = function(...)
83
		for i, v in ipairs({...}) do
84
			outb = outb .. tostring(v);
85
		end
86
	end
87

88
	setfenv(a, enva);
89
	setfenv(b, envb);
90

91
	if(not pcall(a)) then error("Expected Reference Program not to Fail!") end
92
	if(not pcall(b)) then return false, outa, nil end
93

94
	return outa == outb, outa, outb
95
end
96

97

98
local presets = Prometheus.Presets;
99
local testdir = "./tests/"
100
local failed = {};
101
Prometheus.Logger.logLevel = Prometheus.Logger.LogLevel.Error;
102
local fc = 0;
103
for i, filename in ipairs(scandir(testdir)) do
104
	local path = testdir .. filename;
105
	local file = io.open(path,"r");
106

107
	local code = file:read("*a");
108
	print(Prometheus.colors("[CURRENT] ", "magenta") .. filename);
109
	for name, preset in pairs(presets) do
110
		for i = #preset.Steps, 1, -1 do
111
			if preset.Steps[i].Name == "AntiTamper" then
112
				table.remove(preset.Steps, i);
113
			end
114
		end
115
		pipeline = Prometheus.Pipeline:fromConfig(preset);
116
		local obfuscated = pipeline:apply(code);
117

118
		local funca = loadstring(code);
119
		local funcb = loadstring(obfuscated);
120

121
		if funcb == nil then
122
			print(Prometheus.colors("[FAILED]  ", "red") .. "(" .. filename .. "): " .. name .. ", Invalid Lua!");
123
			print("[SOURCE]", obfuscated);
124
			fc = fc + 1;
125
		else
126
			local validated, outa, outb = validate(funca, funcb);
127
	
128
			if not validated then
129
				print(Prometheus.colors("[FAILED]  ", "red") .. "(" .. filename .. "): " .. name);
130
				print("[OUTA]    ",    outa);
131
				print("[OUTB]    ", outb);
132
				print("[SOURCE]", obfuscated);
133
				fc = fc + 1;
134
			end
135
		end
136
	end
137
	file:close();
138
end
139

140
if fc < 1 then
141
	print(Prometheus.colors("[PASSED]  ", "green") .. "All tests passed!");
142
	return 0;
143
else
144
	print(Prometheus.colors("[FAILED]  ", "red") .. "Some tests failed!");
145
	if ciMode then
146
		error("Test Failed!")
147
	end
148
	return -1;
149
end

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.