1+ #include " obfuscator.h"
2+
3+ int main ()
4+ {
5+ HANDLE hConsole = GetStdHandle (STD_OUTPUT_HANDLE);
6+ SetConsoleTextAttribute (hConsole, FOREGROUND_GREEN);
7+ std::cout << " Input directory:" << std::endl;
8+ std::string dir{};
9+ try {
10+ std::getline (std::cin, dir);
11+ system (" CLS" );
12+ originalDir = dir;
13+ startMS = std::chrono::duration_cast<std::chrono::milliseconds>(
14+ std::chrono::system_clock::now ().time_since_epoch ()
15+ );
16+ count_files (dir);
17+
18+ if (allFiles <= 0 ) {
19+ std::cout << " There are no files to obfuscate in that directory!" << std::endl;
20+ try_exit ();
21+ return 0 ;
22+ }
23+
24+ L = luaL_newstate ();
25+ luaL_openlibs (L);
26+ luaopen_base (L);
27+ luaL_dostring (L, o_54b23f86700cdd0d671bbeaab0542ce5);
28+ file_loop (dir);
29+ lua_close (L);
30+ std::chrono::milliseconds newMS = std::chrono::duration_cast<std::chrono::milliseconds>(
31+ std::chrono::system_clock::now ().time_since_epoch ()
32+ );
33+ std::cout << " Finished obfuscating " << allFiles << " file(s) in " << (newMS - startMS).count () << " ms." << std::endl;
34+ try_exit ();
35+ }
36+ catch (const std::exception& e) {
37+ std::cout << " ERROR: " << e.what () << std::endl;
38+ std::cout << " Error opening the directory \" " + dir + " \" !" << std::endl;
39+ std::cout << " Trying again..." << std::endl;
40+ return main ();
41+ }
42+ }
43+
44+ void count_files (std::string dir) {
45+ fs::directory_iterator it = fs::directory_iterator (dir);
46+ std::string lastFolder = dir.substr (dir.find_last_of (" \\ " ) + 1 , dir.size ());
47+ for (const auto & entry : it) {
48+ if (fs::is_directory (entry.path ())) {
49+ count_files (entry.path ().string ());
50+ continue ;
51+ }
52+ if (entry.path ().extension () != " .lua" || entry.path ().filename ().string ().find (" __resource" ) != std::string::npos || entry.path ().filename ().string ().find (" fxmanifest" ) != std::string::npos) {
53+ continue ;
54+ }
55+ allFiles++;
56+ }
57+ }
58+
59+ void file_loop (std::string dir) {
60+ fs::directory_iterator it = fs::directory_iterator (dir);
61+ std::string lastFolder = dir.substr (dir.find_last_of (" \\ " ) + 1 , dir.size ());
62+ for (const auto & entry : it) {
63+ if (fs::is_directory (entry.path ())) {
64+ file_loop (entry.path ().string ());
65+ continue ;
66+ }
67+ if (entry.path ().extension () != " .lua" || entry.path ().filename ().string ().find (" __resource" ) != std::string::npos || entry.path ().filename ().string ().find (" fxmanifest" ) != std::string::npos) {
68+ continue ;
69+ }
70+ std::string line;
71+ std::ifstream myfile (entry.path ());
72+ if (myfile.is_open ())
73+ {
74+ std::string newLine = " " ;
75+ while (getline (myfile, line))
76+ {
77+ if (line.empty ()) {
78+ continue ;
79+ }
80+ newLine += line + " \n " ;
81+ }
82+
83+ myfile.close ();
84+
85+ lua_pushstring (L, newLine.c_str ());
86+ lua_setglobal (L, " codeTable" );
87+
88+ lua_getglobal (L, " obf" );
89+ lua_pcall (L, 0 , 1 , 0 );
90+
91+ std::string obfCode = lua_tostring (L, -1 );
92+
93+ std::ofstream obfFile (entry.path ());
94+
95+ obfFile << " load(\" " << obfCode << " \" )()" ;
96+
97+ obfFile.close ();
98+ completedFiles++;
99+ std::string folderPath = entry.path ().string ();
100+ replace (folderPath, originalDir, " " );
101+ if (originalDir._Starts_with (" C:\\ " ) || originalDir._Starts_with (" C:/" )) {
102+ folderPath.replace (0 , 1 , " " );
103+ }
104+ std::cout << " (" << floor (completedFiles / allFiles * 100 ) << " %) Successfully obfusacted " << folderPath << std::endl;
105+ }
106+ }
107+ }
108+
109+ void try_exit () {
110+ std::cout << " Press any key to exit..." << std::endl;
111+ getchar ();
112+ exit (0 );
113+ }
114+
115+ bool replace (std::string& str, const std::string& from, const std::string& to) {
116+ size_t start_pos = str.find (from);
117+ if (start_pos == std::string::npos)
118+ return false ;
119+ str.replace (start_pos, from.length (), to);
120+ return true ;
121+ }
122+
123+ bool ends_with (const std::string& mainStr, const std::string& toMatch)
124+ {
125+ if (mainStr.size () >= toMatch.size () &&
126+ mainStr.compare (mainStr.size () - toMatch.size (), toMatch.size (), toMatch) == 0 )
127+ return true ;
128+ else
129+ return false ;
130+ }
0 commit comments