1+ -- This Script is Part of the Prometheus Obfuscator by Levno_710
2+ --
3+ -- test.lua
4+ -- This script contains the Code for the Prometheus CLI
5+
6+ -- Configure package.path for requiring Prometheus
7+ local function script_path ()
8+ local str = debug.getinfo (2 , " S" ).source :sub (2 )
9+ return str :match (" (.*[/%\\ ])" )
10+ end
11+ package.path = script_path () .. " ?.lua;" .. package.path ;
12+ --- @diagnostic disable-next-line : different-requires
13+ local Prometheus = require (" prometheus" );
14+ Prometheus .Logger .logLevel = Prometheus .Logger .LogLevel .Info ;
15+
16+ -- see if the file exists
17+ local function file_exists (file )
18+ local f = io.open (file , " rb" )
19+ if f then f :close () end
20+ return f ~= nil
21+ end
22+
23+ -- get all lines from a file, returns an empty
24+ -- list/table if the file does not exist
25+ local function lines_from (file )
26+ if not file_exists (file ) then return {} end
27+ local lines = {}
28+ for line in io.lines (file ) do
29+ lines [# lines + 1 ] = line
30+ end
31+ return lines
32+ end
33+
34+ -- CLI
35+ local config ;
36+ local sourceFile ;
37+ local outFile ;
38+
39+ Prometheus .colors .enabled = true ;
40+
41+ -- Parse Arguments
42+ local i = 1 ;
43+ while i <= # arg do
44+ local curr = arg [i ];
45+ if curr :sub (1 , 2 ) == " --" then
46+ if curr == " --preset" or curr == " --p" then
47+ if config then
48+ Prometheus .Logger :warn (" The config was set multiple times" );
49+ end
50+
51+ i = i + 1 ;
52+ local preset = Prometheus .Presets [arg [i ]];
53+ if not preset then
54+ Prometheus .Logger :error (string.format (" A Preset with the name \" %s\" was not found!" , tostring (arg [i ])));
55+ end
56+
57+ config = preset ;
58+ elseif curr == " --config" or curr == " --c" then
59+ i = i + 1 ;
60+ local filename = tostring (arg [i ]);
61+ if not file_exists (filename ) then
62+ Prometheus .Logger :error (string.format (" The config file \" %s\" was not found!" , filename ));
63+ end
64+
65+ local content = table.concat (lines_from (filename ), " \n " );
66+ -- Load Config from File
67+ local func = loadstring (content );
68+ -- Sandboxing
69+ setfenv (func , {});
70+ config = func ();
71+ elseif curr == " --out" or curr == " --o" then
72+ i = i + 1 ;
73+ if (outFile ) then
74+ Prometheus .Logger :warn (" The output file was specified multiple times!" );
75+ end
76+ outFile = arg [i ];
77+ elseif curr == " --nocolors" then
78+ Prometheus .colors .enabled = false ;
79+ else
80+ Prometheus .Logger :warn (string.format (" The option \" %s\" is not valid and therefore ignored" ));
81+ end
82+ else
83+ if sourceFile then
84+ Prometheus .Logger :error (string.format (" Unexpected argument \" %s\" " , arg [i ]));
85+ end
86+ sourceFile = tostring (arg [i ]);
87+ end
88+ i = i + 1 ;
89+ end
90+
91+ if not sourceFile then
92+ Prometheus .Logger :error (" No input file was specified!" )
93+ end
94+
95+ if not config then
96+ Prometheus .Logger :warn (" No config was specified, falling back to Minify preset" );
97+ config = Prometheus .Presets .Minify ;
98+ end
99+
100+ if not file_exists (sourceFile ) then
101+ Prometheus .Logger :error (string.format (" The File \" %s\" was not found!" , sourceFile ));
102+ end
103+
104+ if not outFile then
105+ if sourceFile :sub (- 4 ) == " .lua" then
106+ outFile = sourceFile :sub (0 , - 5 ) .. " .obfuscated.lua" ;
107+ else
108+ outFile = sourceFile .. " .obfuscated.lua" ;
109+ end
110+ end
111+
112+ local source = table.concat (lines_from (sourceFile ), " \n " );
113+ local pipeline = Prometheus .Pipeline :fromConfig (config );
114+ local out = pipeline :apply (source , sourceFile );
115+ Prometheus .Logger :info (string.format (" Writing output to \" %s\" " , outFile ));
116+
117+ -- Write Output
118+ local handle = io.open (outFile , " w" );
119+ handle :write (out );
120+ handle :close ();
0 commit comments