Skip to content

Commit f62d3e7

Browse files
authored
Automate seed data cleanup on exit
Implemented std::atexit() to automatically delete seed-related files and registry entries when the program exits, preventing the accumulation of unused seed data over time.
1 parent b8da7cf commit f62d3e7

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

auth.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ void checkRegistry();
7373
void error(std::string message);
7474
std::string generate_random_number();
7575
std::string seed;
76+
void cleanUpSeedData(const std::string& seed);
7677
std::string signature;
7778
std::string signatureTimestamp;
7879
bool initialized;
@@ -82,8 +83,8 @@ bool KeyAuth::api::debug = false;
8283
void KeyAuth::api::init()
8384
{
8485
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)runChecks, 0, 0, 0);
85-
std::string random_num = generate_random_number();
86-
seed = random_num;
86+
seed = generate_random_number();
87+
std::atexit([]() { cleanUpSeedData(seed); });
8788
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)modify, 0, 0, 0);
8889

8990
if (ownerid.length() != 10)
@@ -2081,3 +2082,17 @@ void modify()
20812082
Sleep(50);
20822083
}
20832084
}
2085+
2086+
// Clean up seed data (file and registry key)
2087+
void cleanUpSeedData(const std::string& seed) {
2088+
2089+
// Clean up the seed file
2090+
std::string file_path = "C:\\ProgramData\\" + seed;
2091+
if (std::filesystem::exists(file_path)) {
2092+
std::filesystem::remove(file_path);
2093+
}
2094+
2095+
// Clean up the seed registry entry
2096+
std::string regPath = "Software\\" + seed;
2097+
RegDeleteKeyA(HKEY_CURRENT_USER, regPath.c_str());
2098+
}

0 commit comments

Comments
 (0)