JordanTGraves

AutoExecution

Jan 27th, 2021
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.71 KB | None | 0 0
  1. #pragma once
  2. #include <Windows.h>
  3. #include <string>
  4. #include <iostream>
  5. #include <locale>
  6. #include <utility>
  7. #include <codecvt>
  8. #include <fstream>
  9. #include <vector>
  10. #include <sstream>
  11. #include <Psapi.h>
  12. #include <TlHelp32.h>
  13.  
  14. #include <WinInet.h>
  15. #include <Shlwapi.h>
  16.  
  17. #pragma comment(lib, "wininet.lib")
  18. #pragma comment(lib, "Shlwapi.lib")
  19.  
  20. unsigned __int64 _starting_tick;
  21. unsigned __int64 _finish_tick;
  22.  
  23. #define ERRORMSGBOX(s, s1) MessageBox(NULL, s, s1, MB_ICONERROR | MB_OK);
  24. #define INFOMSGBOX(s, s1) MessageBox(NULL, s, s1, MB_ICONINFORMATION | MB_OK);
  25.  
  26. #define MSFOUND(o) throw std::exception("malicious item '" o "' found");
  27. #define CHECKPROC(p) strcmp(entry.szExeFile, p) == 0
  28.  
  29. #define DebugPurple(...) std::cout << ipurple << "[" << __FUNCTION__ << "] -> " << __VA_ARGS__ << "\n";
  30. #define DebugOutput(...) std::cout << white << "[" << __FUNCTION__ << "] -> " << __VA_ARGS__ << "\n";
  31. #define DebugInfo(...) std::cout << iblue << "[" << __FUNCTION__ << "] -> " << __VA_ARGS__ << "\n";
  32. #define DebugWarn(...) std::cout << iyellow << "[" << __FUNCTION__ << "] -> " << __VA_ARGS__ << "\n";
  33. #define DebugError(...) std::cout << ired << "[" << __FUNCTION__ << "] -> " << __VA_ARGS__ << "\n";
  34. #define DebugSuccess(...) std::cout << igreen << "[" << __FUNCTION__ << "] -> " << __VA_ARGS__ << "\n";
  35.  
  36. #define AEONIANXMODULE "CoronaModule.dll"
  37.  
  38. std::string CrashBoxCap;
  39. std::string CrashBoxText;
  40.  
  41. namespace Timer {
  42. void Reset() {
  43. _starting_tick = 0;
  44. _finish_tick = 0;
  45. }
  46.  
  47. void Start() {
  48. Reset();
  49. _starting_tick = GetTickCount64();
  50. }
  51.  
  52. double GetElapsedTime() {
  53. if (_starting_tick & _finish_tick)
  54. return (_finish_tick - _starting_tick) / 1000.0;
  55. return 0.0;
  56. }
  57.  
  58. double Stop() {
  59. _finish_tick = GetTickCount64();
  60. return GetElapsedTime();
  61. }
  62. }
  63.  
  64.  
  65.  
  66. namespace Files {
  67.  
  68. void GetFile(const char* dllName, const char* fileName, char* buffer, int bfSize) {
  69. GetModuleFileName(GetModuleHandle(dllName), buffer, bfSize);
  70. if (strlen(fileName) + strlen(buffer) < MAX_PATH) {
  71. char* pathEnd = strrchr(buffer, '\\');
  72. strcpy(pathEnd + 1, fileName);
  73. }
  74. else {
  75. *buffer = 0;
  76. }
  77. }
  78.  
  79. long int GetFileSize(FILE* ifile) {
  80. long int fsize = 0;
  81. long int fpos = ftell(ifile);
  82. fseek(ifile, 0, SEEK_END);
  83. fsize = ftell(ifile);
  84. fseek(ifile, fpos, SEEK_SET);
  85.  
  86. return fsize;
  87. }
  88.  
  89.  
  90. int ReadFile(const std::string& path, std::string& out, unsigned char binary) {
  91. std::ios::openmode mode = std::ios::in;
  92. if (binary)
  93. mode |= std::ios::binary;
  94.  
  95. std::ifstream file(path, mode);
  96. if (file.is_open()) {
  97. std::stringstream buffer;
  98. buffer << file.rdbuf();
  99. out = buffer.str();
  100. file.close();
  101. return 1;
  102. }
  103.  
  104. file.close();
  105. return 0;
  106. }
  107.  
  108. int WriteFile(const std::string& path, std::string data, unsigned char binary) {
  109. std::ios::openmode mode = std::ios::out;
  110. if (binary)
  111. mode |= std::ios::binary;
  112.  
  113. std::ofstream file(path, mode);
  114. if (file.is_open()) {
  115. file << data;
  116. file.close();
  117. return 1;
  118. }
  119.  
  120. file.close();
  121. return 0;
  122. }
  123.  
  124. std::string ReadFile(std::string path) {
  125. std::ios::openmode mode = std::ios::in;
  126. std::stringstream buffer;
  127.  
  128. std::ifstream file(path, mode);
  129. if (file.is_open()) {
  130. buffer << file.rdbuf();
  131. file.close();
  132. }
  133. else return "";
  134.  
  135. file.close();
  136. return buffer.str();
  137. }
  138.  
  139. void WriteFile(std::string path, std::string data) {
  140. std::ios::openmode mode = std::ios::out;
  141.  
  142. std::ofstream file(path, mode);
  143. if (file.is_open()) {
  144. file << data;
  145. file.close();
  146. }
  147.  
  148. file.close();
  149. }
  150.  
  151. void GetFilesInDirectory(std::vector<std::string>& out, const std::string& directory, unsigned char includePath) // thx stackoverflow
  152. {
  153. HANDLE dir;
  154. WIN32_FIND_DATA file_data;
  155.  
  156. if ((dir = FindFirstFile((directory + "/*").c_str(), &file_data)) == INVALID_HANDLE_VALUE)
  157. return; /* No files found */
  158.  
  159. do {
  160. const std::string file_name = file_data.cFileName;
  161. const std::string full_file_name = directory + "/" + file_name;
  162. const bool is_directory = (file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
  163.  
  164. if (file_name[0] == '.')
  165. continue;
  166.  
  167. if (is_directory)
  168. continue;
  169.  
  170. out.push_back(includePath ? full_file_name : file_name);
  171. } while (FindNextFile(dir, &file_data));
  172.  
  173. FindClose(dir);
  174. }
  175.  
  176. int FileCheck(int pid, std::vector<std::string> list) {
  177. int count = 0;
  178. HANDLE proc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, pid);
  179.  
  180. if (proc) {
  181. char pathRaw[MAX_PATH];
  182. if (GetModuleFileNameEx(proc, NULL, pathRaw, MAX_PATH)) {
  183. std::string path = pathRaw;
  184. path = path.substr(0, path.find_last_of("\\/")); // remove file name
  185.  
  186. std::vector<std::string> files;
  187. GetFilesInDirectory(files, path, false);
  188.  
  189. for (std::vector<std::string>::iterator i = files.begin(); i != files.end(); i++) {
  190. for (std::vector<std::string>::iterator j = list.begin(); j != list.end(); j++) {
  191. if (*i == *j) count++;
  192. }
  193. }
  194. }
  195. }
  196.  
  197. CloseHandle(proc);
  198.  
  199. return count;
  200. }
  201.  
  202. }
  203.  
  204.  
  205.  
  206. namespace Processes {
  207.  
  208. int GetProcessByImageName(const char* imageName) {
  209. PROCESSENTRY32 entry;
  210. entry.dwSize = sizeof(PROCESSENTRY32);
  211.  
  212. HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
  213.  
  214. if (Process32First(snapshot, &entry) == TRUE)
  215. {
  216. while (Process32Next(snapshot, &entry) == TRUE)
  217. {
  218. if (strcmp(entry.szExeFile, imageName) == 0)
  219. {
  220. CloseHandle(snapshot);
  221. return entry.th32ProcessID;
  222. }
  223. }
  224. }
  225.  
  226. CloseHandle(snapshot);
  227. return 0;
  228. }
  229.  
  230. void Pause() {
  231. THREADENTRY32 te32;
  232. te32.dwSize = sizeof(THREADENTRY32);
  233. HANDLE hThreads = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, NULL);
  234. if (Thread32First(hThreads, &te32)) {
  235. while (Thread32Next(hThreads, &te32)) {
  236. if (te32.th32OwnerProcessID == GetCurrentProcessId() && te32.th32ThreadID != GetCurrentThreadId()) {
  237. HANDLE hThread = OpenThread(THREAD_SUSPEND_RESUME, false, te32.th32ThreadID);
  238. SuspendThread(hThread);
  239. CloseHandle(hThread);
  240. }
  241. }
  242. }
  243. CloseHandle(hThreads);
  244. }
  245.  
  246. void Resume() {
  247. THREADENTRY32 te32;
  248. te32.dwSize = sizeof(THREADENTRY32);
  249. HANDLE hThreads = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, NULL);
  250. if (Thread32First(hThreads, &te32)) {
  251. while (Thread32Next(hThreads, &te32)) {
  252. if (te32.th32OwnerProcessID == GetCurrentProcessId() && te32.th32ThreadID != GetCurrentThreadId()) {
  253. HANDLE hThread = OpenThread(THREAD_SUSPEND_RESUME, false, te32.th32ThreadID);
  254. ResumeThread(hThread);
  255. CloseHandle(hThread);
  256. }
  257. }
  258. }
  259. CloseHandle(hThreads);
  260. }
  261. }
  262.  
  263.  
  264.  
  265. namespace Registry {
  266.  
  267. int ReadString(HKEY key, const char* value, std::string& out) {
  268. int val_sz;
  269. int val_type;
  270. char* val;
  271.  
  272. if (RegQueryValueEx(key, value, NULL, (LPDWORD)& val_type, NULL, (LPDWORD)& val_sz) != ERROR_SUCCESS)
  273. return 0;
  274.  
  275. if (val_type != REG_SZ || !val_sz)
  276. return 0;
  277.  
  278. val = new (std::nothrow) char[val_sz];
  279. if (!val) return 0;
  280.  
  281. if (RegQueryValueEx(key, value, NULL, NULL, (LPBYTE)val, (LPDWORD)& val_sz) != ERROR_SUCCESS) {
  282. delete[] val;
  283. return 0;
  284. }
  285.  
  286. out = val;
  287. delete[] val;
  288. return 1;
  289. }
  290.  
  291. }
  292.  
  293.  
  294.  
  295. namespace Internet {
  296.  
  297. using namespace std;
  298.  
  299. string replaceAll(string subject, const string& search,
  300. const string& replace) {
  301. size_t pos = 0;
  302. while ((pos = subject.find(search, pos)) != string::npos) {
  303. subject.replace(pos, search.length(), replace);
  304. pos += replace.length();
  305. }
  306. return subject;
  307. }
  308.  
  309. string DownloadURL(string URL) {
  310. HINTERNET interwebs = InternetOpenA("Mozilla/5.0", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, NULL);
  311. HINTERNET urlFile;
  312. string rtn;
  313. if (interwebs) {
  314. urlFile = InternetOpenUrlA(interwebs, URL.c_str(), NULL, NULL, NULL, NULL);
  315. if (urlFile) {
  316. char buffer[2000];
  317. DWORD bytesRead;
  318. do {
  319. InternetReadFile(urlFile, buffer, 2000, &bytesRead);
  320. rtn.append(buffer, bytesRead);
  321. memset(buffer, 0, 2000);
  322. } while (bytesRead);
  323. InternetCloseHandle(interwebs);
  324. InternetCloseHandle(urlFile);
  325. string p = replaceAll(rtn, "|n", "\r\n");
  326. return p;
  327. }
  328. }
  329. InternetCloseHandle(interwebs);
  330. string p = replaceAll(rtn, "|n", "\r\n");
  331. return p;
  332. }
  333. }
  334.  
  335.  
  336.  
  337. namespace AeonianX {
  338.  
  339. enum OutputType {
  340. Text,
  341. Info,
  342. Warn,
  343. Error,
  344. Success
  345. };
  346.  
  347. void SendOutput(std::string ToOutput, OutputType Type) {
  348.  
  349. char Path[MAX_PATH];
  350. Files::GetFile(AEONIANXMODULE, "", Path, MAX_PATH);
  351.  
  352. std::string FileAbsolutePath = Path;
  353. std::string FinalisedPath = FileAbsolutePath + "Output.txt";
  354.  
  355. if (Type == Text) {
  356. std::string ToSend = "TEXT|" + ToOutput;
  357. Files::WriteFile(FinalisedPath, ToSend, 0);
  358. }
  359. else if (Type == Info) {
  360. std::string ToSend = "INFO|" + ToOutput;
  361. Files::WriteFile(FinalisedPath, ToSend, 0);
  362. }
  363. else if (Type == Warn) {
  364. std::string ToSend = "WARN|" + ToOutput;
  365. Files::WriteFile(FinalisedPath, ToSend, 0);
  366. }
  367. else if (Type == Error) {
  368. std::string ToSend = "ERROR|" + ToOutput;
  369. Files::WriteFile(FinalisedPath, ToSend, 0);
  370. }
  371. else if (Type == Success) {
  372. std::string ToSend = "SUCCESS|" + ToOutput;
  373. Files::WriteFile(FinalisedPath, ToSend, 0);
  374. }
  375. }
  376.  
  377. bool CheckConsoleEnabled() {
  378. char ConsoleFilePath[MAX_PATH];
  379. Files::GetFile(AEONIANXMODULE, "Settings\\", ConsoleFilePath, MAX_PATH);
  380.  
  381. std::string FileAbsolutePath = ConsoleFilePath;
  382. std::string FinalisedPath = FileAbsolutePath + "Console.txt";
  383.  
  384. std::string ConsoleBuffer;
  385. if (!Files::ReadFile(FinalisedPath, ConsoleBuffer, 0)) {
  386. ERRORMSGBOX("Failed to read settings file! Loading will continue with default settings!", "Error");
  387. return false;
  388. }
  389.  
  390. if (ConsoleBuffer == "ENABLED")
  391. {
  392. return true;
  393. }
  394. return false;
  395. }
  396.  
  397. }
Add Comment
Please, Sign In to add comment