@@ -1119,50 +1119,6 @@ public static string checksum(string filename)
11191119 return result ;
11201120 }
11211121
1122- public static void LogEvent ( string content )
1123- {
1124- string exeName = Path . GetFileNameWithoutExtension ( System . Reflection . Assembly . GetEntryAssembly ( ) . Location ) ;
1125-
1126- string logDirectory = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . CommonApplicationData ) , "KeyAuth" , "debug" , exeName ) ;
1127- if ( ! Directory . Exists ( logDirectory ) )
1128- {
1129- Directory . CreateDirectory ( logDirectory ) ;
1130- }
1131-
1132- string logFileName = $ "{ DateTime . Now : MMM_dd_yyyy} _logs.txt";
1133- string logFilePath = Path . Combine ( logDirectory , logFileName ) ;
1134-
1135- try
1136- {
1137- // Redact sensitive fields - Add more if you would like.
1138- content = RedactField ( content , "sessionid" ) ;
1139- content = RedactField ( content , "ownerid" ) ;
1140- content = RedactField ( content , "app" ) ;
1141- content = RedactField ( content , "version" ) ;
1142- content = RedactField ( content , "fileid" ) ;
1143- content = RedactField ( content , "webhooks" ) ;
1144- content = RedactField ( content , "nonce" ) ;
1145-
1146- using ( StreamWriter writer = File . AppendText ( logFilePath ) )
1147- {
1148- writer . WriteLine ( $ "[{ DateTime . Now } ] [{ AppDomain . CurrentDomain . FriendlyName } ] { content } ") ;
1149- }
1150- }
1151- catch ( Exception ex )
1152- {
1153- Console . WriteLine ( $ "Error logging data: { ex . Message } ") ;
1154- }
1155- }
1156-
1157- private static string RedactField ( string content , string fieldName )
1158- {
1159- // Basic pattern matching to replace values of sensitive fields
1160- string pattern = $ "\" { fieldName } \" :\" [^\" ]*\" ";
1161- string replacement = $ "\" { fieldName } \" :\" REDACTED\" ";
1162-
1163- return System . Text . RegularExpressions . Regex . Replace ( content , pattern , replacement ) ;
1164- }
1165-
11661122 public static void error ( string message )
11671123 {
11681124 string folder = @"Logs" , file = Path . Combine ( folder , "ErrorLogs.txt" ) ;
@@ -1208,7 +1164,7 @@ private static string req(NameValueCollection post_data)
12081164
12091165 sigCheck ( Encoding . UTF8 . GetString ( raw_response ) , client . ResponseHeaders , post_data . Get ( 0 ) ) ;
12101166
1211- LogEvent ( Encoding . Default . GetString ( raw_response ) + "\n " ) ;
1167+ Logger . LogEvent ( Encoding . Default . GetString ( raw_response ) + "\n " ) ;
12121168
12131169 return Encoding . Default . GetString ( raw_response ) ;
12141170 }
@@ -1220,12 +1176,12 @@ private static string req(NameValueCollection post_data)
12201176 {
12211177 case ( HttpStatusCode ) 429 : // client hit our rate limit
12221178 error ( "You're connecting too fast to loader, slow down." ) ;
1223- LogEvent ( "You're connecting too fast to loader, slow down." ) ;
1179+ Logger . LogEvent ( "You're connecting too fast to loader, slow down." ) ;
12241180 TerminateProcess ( GetCurrentProcess ( ) , 1 ) ;
12251181 return "" ;
12261182 default : // site won't resolve. you should use keyauth.uk domain since it's not blocked by any ISPs
12271183 error ( "Connection failure. Please try again, or contact us for help." ) ;
1228- LogEvent ( "Connection failure. Please try again, or contact us for help." ) ;
1184+ Logger . LogEvent ( "Connection failure. Please try again, or contact us for help." ) ;
12291185 TerminateProcess ( GetCurrentProcess ( ) , 1 ) ;
12301186 return "" ;
12311187 }
@@ -1237,7 +1193,7 @@ private static bool assertSSL(object sender, X509Certificate certificate, X509Ch
12371193 if ( ( ! certificate . Issuer . Contains ( "Google Trust Services" ) && ! certificate . Issuer . Contains ( "Let's Encrypt" ) ) || sslPolicyErrors != SslPolicyErrors . None )
12381194 {
12391195 error ( "SSL assertion fail, make sure you're not debugging Network. Disable internet firewall on router if possible. & echo: & echo If not, ask the developer of the program to use custom domains to fix this." ) ;
1240- LogEvent ( "SSL assertion fail, make sure you're not debugging Network. Disable internet firewall on router if possible. If not, ask the developer of the program to use custom domains to fix this." ) ;
1196+ Logger . LogEvent ( "SSL assertion fail, make sure you're not debugging Network. Disable internet firewall on router if possible. If not, ask the developer of the program to use custom domains to fix this." ) ;
12411197 return false ;
12421198 }
12431199 return true ;
@@ -1289,14 +1245,14 @@ private static void sigCheck(string resp, WebHeaderCollection headers, string ty
12891245 if ( ! signatureValid )
12901246 {
12911247 error ( "Signature checksum failed. Request was tampered with or session ended most likely. & echo: & echo Response: " + resp ) ;
1292- LogEvent ( resp + "\n " ) ;
1248+ Logger . LogEvent ( resp + "\n " ) ;
12931249 TerminateProcess ( GetCurrentProcess ( ) , 1 ) ;
12941250 }
12951251 }
12961252 catch
12971253 {
12981254 error ( "Signature checksum failed. Request was tampered with or session ended most likely. & echo: & echo Response: " + resp ) ;
1299- LogEvent ( resp + "\n " ) ;
1255+ Logger . LogEvent ( resp + "\n " ) ;
13001256 TerminateProcess ( GetCurrentProcess ( ) , 1 ) ;
13011257 }
13021258 }
@@ -1383,6 +1339,60 @@ private void load_response_struct(response_structure data)
13831339 private json_wrapper response_decoder = new json_wrapper ( new response_structure ( ) ) ;
13841340 }
13851341
1342+ public static class Logger
1343+ {
1344+ public static bool IsLoggingEnabled { get ; set ; } = false ; // Disabled by default
1345+ public static void LogEvent ( string content )
1346+ {
1347+ if ( ! IsLoggingEnabled )
1348+ {
1349+ //Console.WriteLine("Debug mode disabled."); // Optional: Message when logging is disabled
1350+ return ; // Exit the method if logging is disabled
1351+ }
1352+
1353+ string exeName = Path . GetFileNameWithoutExtension ( System . Reflection . Assembly . GetEntryAssembly ( ) . Location ) ;
1354+
1355+ string logDirectory = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . CommonApplicationData ) , "KeyAuth" , "debug" , exeName ) ;
1356+ if ( ! Directory . Exists ( logDirectory ) )
1357+ {
1358+ Directory . CreateDirectory ( logDirectory ) ;
1359+ }
1360+
1361+ string logFileName = $ "{ DateTime . Now : MMM_dd_yyyy} _logs.txt";
1362+ string logFilePath = Path . Combine ( logDirectory , logFileName ) ;
1363+
1364+ try
1365+ {
1366+ // Redact sensitive fields - Add more if you would like.
1367+ content = RedactField ( content , "sessionid" ) ;
1368+ content = RedactField ( content , "ownerid" ) ;
1369+ content = RedactField ( content , "app" ) ;
1370+ content = RedactField ( content , "version" ) ;
1371+ content = RedactField ( content , "fileid" ) ;
1372+ content = RedactField ( content , "webhooks" ) ;
1373+ content = RedactField ( content , "nonce" ) ;
1374+
1375+ using ( StreamWriter writer = File . AppendText ( logFilePath ) )
1376+ {
1377+ writer . WriteLine ( $ "[{ DateTime . Now } ] [{ AppDomain . CurrentDomain . FriendlyName } ] { content } ") ;
1378+ }
1379+ }
1380+ catch ( Exception ex )
1381+ {
1382+ Console . WriteLine ( $ "Error logging data: { ex . Message } ") ;
1383+ }
1384+ }
1385+
1386+ private static string RedactField ( string content , string fieldName )
1387+ {
1388+ // Basic pattern matching to replace values of sensitive fields
1389+ string pattern = $ "\" { fieldName } \" :\" [^\" ]*\" ";
1390+ string replacement = $ "\" { fieldName } \" :\" REDACTED\" ";
1391+
1392+ return System . Text . RegularExpressions . Regex . Replace ( content , pattern , replacement ) ;
1393+ }
1394+ }
1395+
13861396 public static class encryption
13871397 {
13881398 [ DllImport ( "kernel32.dll" , SetLastError = true ) ]
0 commit comments