@@ -73,17 +73,19 @@ void checkRegistry();
73
73
void error (std::string message);
74
74
std::string generate_random_number ();
75
75
std::string seed;
76
+ void cleanUpSeedData (const std::string& seed);
76
77
std::string signature;
77
78
std::string signatureTimestamp;
78
79
bool initialized;
79
80
std::string API_PUBLIC_KEY = " 5586b4bc69c7a4b487e4563a4cd96afd39140f919bd31cea7d1c6a1e8439422b" ;
80
81
bool KeyAuth::api::debug = false ;
82
+ std::atomic<bool > LoggedIn (false );
81
83
82
84
void KeyAuth::api::init ()
83
85
{
84
- CreateThread ( 0 , 0 , (LPTHREAD_START_ROUTINE) runChecks, 0 , 0 , 0 );
85
- std::string random_num = generate_random_number ();
86
- seed = random_num ;
86
+ std::thread ( runChecks). detach ( );
87
+ seed = generate_random_number ();
88
+ std::atexit ([]() { cleanUpSeedData (seed); }) ;
87
89
CreateThread (0 , 0 , (LPTHREAD_START_ROUTINE)modify, 0 , 0 , 0 );
88
90
89
91
if (ownerid.length () != 10 )
@@ -293,6 +295,7 @@ void KeyAuth::api::login(std::string username, std::string password, std::string
293
295
}
294
296
295
297
LI_FN (GlobalAddAtomA)(ownerid.c_str ());
298
+ LoggedIn.store (true );
296
299
}
297
300
else {
298
301
LI_FN (exit)(12 );
@@ -741,6 +744,7 @@ void KeyAuth::api::web_login()
741
744
}
742
745
743
746
LI_FN (GlobalAddAtomA)(ownerid.c_str ());
747
+ LoggedIn.store (true );
744
748
}
745
749
else {
746
750
LI_FN (exit)(12 );
@@ -989,6 +993,7 @@ void KeyAuth::api::regstr(std::string username, std::string password, std::strin
989
993
}
990
994
991
995
LI_FN (GlobalAddAtomA)(ownerid.c_str ());
996
+ LoggedIn.store (true );
992
997
}
993
998
else {
994
999
LI_FN (exit)(12 );
@@ -1061,11 +1066,6 @@ std::string generate_random_number() {
1061
1066
}
1062
1067
1063
1068
void KeyAuth::api::license (std::string key, std::string code) {
1064
- // Call threads to start in 15 seconds..
1065
- CreateThread (0 , 0 , (LPTHREAD_START_ROUTINE)checkAtoms, 0 , 0 , 0 );
1066
- CreateThread (0 , 0 , (LPTHREAD_START_ROUTINE)checkFiles, 0 , 0 , 0 );
1067
- CreateThread (0 , 0 , (LPTHREAD_START_ROUTINE)checkRegistry, 0 , 0 , 0 );
1068
-
1069
1069
checkInit ();
1070
1070
1071
1071
std::string hwid = utils::get_hwid ();
@@ -1119,6 +1119,7 @@ void KeyAuth::api::license(std::string key, std::string code) {
1119
1119
}
1120
1120
1121
1121
LI_FN (GlobalAddAtomA)(ownerid.c_str ());
1122
+ LoggedIn.store (true );
1122
1123
}
1123
1124
else {
1124
1125
LI_FN (exit)(12 );
@@ -1800,15 +1801,25 @@ auto check_section_integrity( const char *section_name, bool fix = false ) -> bo
1800
1801
}
1801
1802
1802
1803
void runChecks () {
1803
- Sleep (45000 ); // give people 1 minute to login. (because the functions we call already wait 15 seconds)
1804
-
1805
- checkAtoms ();
1806
- checkFiles ();
1807
- checkRegistry ();
1804
+ // Wait before starting checks
1805
+ int waitTime = 45000 ;
1806
+ while (waitTime > 0 ) {
1807
+
1808
+ if (LoggedIn.load ()) {
1809
+ // If the user is logged in, proceed with the checks immediately
1810
+ break ;
1811
+ }
1812
+ std::this_thread::sleep_for (std::chrono::seconds (1 ));
1813
+ waitTime -= 1000 ;
1814
+ }
1815
+
1816
+ // Create separate threads for each check
1817
+ std::thread (checkAtoms).detach ();
1818
+ std::thread (checkFiles).detach ();
1819
+ std::thread (checkRegistry).detach ();
1808
1820
}
1809
1821
1810
1822
void checkAtoms () {
1811
- Sleep (15000 ); // enough time for API response, even on slower connections
1812
1823
1813
1824
while (true ) {
1814
1825
if (LI_FN (GlobalFindAtomA)(seed.c_str ()) == 0 ) {
@@ -1820,7 +1831,6 @@ void checkAtoms() {
1820
1831
}
1821
1832
1822
1833
void checkFiles () {
1823
- Sleep (15000 ); // enough time for API response, even on slower connections
1824
1834
1825
1835
while (true ) {
1826
1836
std::string file_path = XorStr (" C:\\ ProgramData\\ " ).c_str () + seed;
@@ -1834,8 +1844,7 @@ void checkFiles() {
1834
1844
}
1835
1845
1836
1846
void checkRegistry () {
1837
- Sleep (15000 ); // enough time for API response, even on slower connections
1838
-
1847
+
1839
1848
while (true ) {
1840
1849
std::string regPath = XorStr (" Software\\ " ).c_str () + seed;
1841
1850
HKEY hKey;
@@ -1845,8 +1854,8 @@ void checkRegistry() {
1845
1854
LI_FN (__fastfail)(0 );
1846
1855
}
1847
1856
LI_FN (RegCloseKey)(hKey);
1857
+ Sleep (1500 ); // thread interval
1848
1858
}
1849
- Sleep (1500 ); // thread interval
1850
1859
}
1851
1860
1852
1861
std::string checksum ()
@@ -2081,3 +2090,17 @@ void modify()
2081
2090
Sleep (50 );
2082
2091
}
2083
2092
}
2093
+
2094
+ // Clean up seed data (file and registry key)
2095
+ void cleanUpSeedData (const std::string& seed) {
2096
+
2097
+ // Clean up the seed file
2098
+ std::string file_path = " C:\\ ProgramData\\ " + seed;
2099
+ if (std::filesystem::exists (file_path)) {
2100
+ std::filesystem::remove (file_path);
2101
+ }
2102
+
2103
+ // Clean up the seed registry entry
2104
+ std::string regPath = " Software\\ " + seed;
2105
+ RegDeleteKeyA (HKEY_CURRENT_USER, regPath.c_str ());
2106
+ }
0 commit comments