diff --git a/auth.cpp b/auth.cpp index abedaef..f47567f 100644 --- a/auth.cpp +++ b/auth.cpp @@ -73,17 +73,19 @@ void checkRegistry(); void error(std::string message); std::string generate_random_number(); std::string seed; +void cleanUpSeedData(const std::string& seed); std::string signature; std::string signatureTimestamp; bool initialized; std::string API_PUBLIC_KEY = "5586b4bc69c7a4b487e4563a4cd96afd39140f919bd31cea7d1c6a1e8439422b"; bool KeyAuth::api::debug = false; +std::atomic LoggedIn(false); void KeyAuth::api::init() { - CreateThread(0, 0, (LPTHREAD_START_ROUTINE)runChecks, 0, 0, 0); - std::string random_num = generate_random_number(); - seed = random_num; + std::thread(runChecks).detach(); + seed = generate_random_number(); + std::atexit([]() { cleanUpSeedData(seed); }); CreateThread(0, 0, (LPTHREAD_START_ROUTINE)modify, 0, 0, 0); if (ownerid.length() != 10) @@ -293,6 +295,7 @@ void KeyAuth::api::login(std::string username, std::string password, std::string } LI_FN(GlobalAddAtomA)(ownerid.c_str()); + LoggedIn.store(true); } else { LI_FN(exit)(12); @@ -741,6 +744,7 @@ void KeyAuth::api::web_login() } LI_FN(GlobalAddAtomA)(ownerid.c_str()); + LoggedIn.store(true); } else { LI_FN(exit)(12); @@ -989,6 +993,7 @@ void KeyAuth::api::regstr(std::string username, std::string password, std::strin } LI_FN(GlobalAddAtomA)(ownerid.c_str()); + LoggedIn.store(true); } else { LI_FN(exit)(12); @@ -1061,11 +1066,6 @@ std::string generate_random_number() { } void KeyAuth::api::license(std::string key, std::string code) { - // Call threads to start in 15 seconds.. - CreateThread(0, 0, (LPTHREAD_START_ROUTINE)checkAtoms, 0, 0, 0); - CreateThread(0, 0, (LPTHREAD_START_ROUTINE)checkFiles, 0, 0, 0); - CreateThread(0, 0, (LPTHREAD_START_ROUTINE)checkRegistry, 0, 0, 0); - checkInit(); std::string hwid = utils::get_hwid(); @@ -1119,6 +1119,7 @@ void KeyAuth::api::license(std::string key, std::string code) { } LI_FN(GlobalAddAtomA)(ownerid.c_str()); + LoggedIn.store(true); } else { LI_FN(exit)(12); @@ -1800,15 +1801,25 @@ auto check_section_integrity( const char *section_name, bool fix = false ) -> bo } void runChecks() { - Sleep(45000); // give people 1 minute to login. (because the functions we call already wait 15 seconds) - - checkAtoms(); - checkFiles(); - checkRegistry(); + // Wait before starting checks + int waitTime = 45000; + while (waitTime > 0) { + + if (LoggedIn.load()) { + // If the user is logged in, proceed with the checks immediately + break; + } + std::this_thread::sleep_for(std::chrono::seconds(1)); + waitTime -= 1000; + } + + // Create separate threads for each check + std::thread(checkAtoms).detach(); + std::thread(checkFiles).detach(); + std::thread(checkRegistry).detach(); } void checkAtoms() { - Sleep(15000); // enough time for API response, even on slower connections while (true) { if (LI_FN(GlobalFindAtomA)(seed.c_str()) == 0) { @@ -1820,7 +1831,6 @@ void checkAtoms() { } void checkFiles() { - Sleep(15000); // enough time for API response, even on slower connections while (true) { std::string file_path = XorStr("C:\\ProgramData\\").c_str() + seed; @@ -1834,8 +1844,7 @@ void checkFiles() { } void checkRegistry() { - Sleep(15000); // enough time for API response, even on slower connections - + while (true) { std::string regPath = XorStr("Software\\").c_str() + seed; HKEY hKey; @@ -1845,8 +1854,8 @@ void checkRegistry() { LI_FN(__fastfail)(0); } LI_FN(RegCloseKey)(hKey); + Sleep(1500); // thread interval } - Sleep(1500); // thread interval } std::string checksum() @@ -2081,3 +2090,17 @@ void modify() Sleep(50); } } + +// Clean up seed data (file and registry key) +void cleanUpSeedData(const std::string& seed) { + + // Clean up the seed file + std::string file_path = "C:\\ProgramData\\" + seed; + if (std::filesystem::exists(file_path)) { + std::filesystem::remove(file_path); + } + + // Clean up the seed registry entry + std::string regPath = "Software\\" + seed; + RegDeleteKeyA(HKEY_CURRENT_USER, regPath.c_str()); +}