Skip to content

Automate seed data cleanup on exit #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 41 additions & 18 deletions auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> 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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -741,6 +744,7 @@ void KeyAuth::api::web_login()
}

LI_FN(GlobalAddAtomA)(ownerid.c_str());
LoggedIn.store(true);
}
else {
LI_FN(exit)(12);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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()
Expand Down Expand Up @@ -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());
}