Skip to content

Commit 13292a3

Browse files
Improved LogEvent function
1 parent 5a9943f commit 13292a3

File tree

2 files changed

+120
-100
lines changed

2 files changed

+120
-100
lines changed

Console/KeyAuth.cs

Lines changed: 60 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -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)]

Form/KeyAuth.cs

Lines changed: 60 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,50 +1115,6 @@ public static string checksum(string filename)
11151115
return result;
11161116
}
11171117

1118-
public static void LogEvent(string content)
1119-
{
1120-
string exeName = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location);
1121-
1122-
string logDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "KeyAuth", "debug", exeName);
1123-
if (!Directory.Exists(logDirectory))
1124-
{
1125-
Directory.CreateDirectory(logDirectory);
1126-
}
1127-
1128-
string logFileName = $"{DateTime.Now:MMM_dd_yyyy}_logs.txt";
1129-
string logFilePath = Path.Combine(logDirectory, logFileName);
1130-
1131-
try
1132-
{
1133-
// Redact sensitive fields - Add more if you would like.
1134-
content = RedactField(content, "sessionid");
1135-
content = RedactField(content, "ownerid");
1136-
content = RedactField(content, "app");
1137-
content = RedactField(content, "version");
1138-
content = RedactField(content, "fileid");
1139-
content = RedactField(content, "webhooks");
1140-
content = RedactField(content, "nonce");
1141-
1142-
using (StreamWriter writer = File.AppendText(logFilePath))
1143-
{
1144-
writer.WriteLine($"[{DateTime.Now}] [{AppDomain.CurrentDomain.FriendlyName}] {content}");
1145-
}
1146-
}
1147-
catch (Exception ex)
1148-
{
1149-
Console.WriteLine($"Error logging data: {ex.Message}");
1150-
}
1151-
}
1152-
1153-
private static string RedactField(string content, string fieldName)
1154-
{
1155-
// Basic pattern matching to replace values of sensitive fields
1156-
string pattern = $"\"{fieldName}\":\"[^\"]*\"";
1157-
string replacement = $"\"{fieldName}\":\"REDACTED\"";
1158-
1159-
return System.Text.RegularExpressions.Regex.Replace(content, pattern, replacement);
1160-
}
1161-
11621118
public static void error(string message)
11631119
{
11641120
string folder = @"Logs", file = Path.Combine(folder, "ErrorLogs.txt");
@@ -1204,7 +1160,7 @@ private static string req(NameValueCollection post_data)
12041160

12051161
sigCheck(Encoding.UTF8.GetString(raw_response), client.ResponseHeaders, post_data.Get(0));
12061162

1207-
LogEvent(Encoding.Default.GetString(raw_response) + "\n");
1163+
Logger.LogEvent(Encoding.Default.GetString(raw_response) + "\n");
12081164

12091165
return Encoding.Default.GetString(raw_response);
12101166
}
@@ -1216,12 +1172,12 @@ private static string req(NameValueCollection post_data)
12161172
{
12171173
case (HttpStatusCode)429: // client hit our rate limit
12181174
error("You're connecting too fast to loader, slow down.");
1219-
LogEvent("You're connecting too fast to loader, slow down.");
1175+
Logger.LogEvent("You're connecting too fast to loader, slow down.");
12201176
TerminateProcess(GetCurrentProcess(), 1);
12211177
return "";
12221178
default: // site won't resolve. you should use keyauth.uk domain since it's not blocked by any ISPs
12231179
error("Connection failure. Please try again, or contact us for help.");
1224-
LogEvent("Connection failure. Please try again, or contact us for help.");
1180+
Logger.LogEvent("Connection failure. Please try again, or contact us for help.");
12251181
TerminateProcess(GetCurrentProcess(), 1);
12261182
return "";
12271183
}
@@ -1233,7 +1189,7 @@ private static bool assertSSL(object sender, X509Certificate certificate, X509Ch
12331189
if ((!certificate.Issuer.Contains("Google Trust Services") && !certificate.Issuer.Contains("Let's Encrypt")) || sslPolicyErrors != SslPolicyErrors.None)
12341190
{
12351191
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.");
1236-
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.");
1192+
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.");
12371193
return false;
12381194
}
12391195
return true;
@@ -1285,14 +1241,14 @@ private static void sigCheck(string resp, WebHeaderCollection headers, string ty
12851241
if (!signatureValid)
12861242
{
12871243
error("Signature checksum failed. Request was tampered with or session ended most likely. & echo: & echo Response: " + resp);
1288-
LogEvent(resp + "\n");
1244+
Logger.LogEvent(resp + "\n");
12891245
TerminateProcess(GetCurrentProcess(), 1);
12901246
}
12911247
}
12921248
catch
12931249
{
12941250
error("Signature checksum failed. Request was tampered with or session ended most likely. & echo: & echo Response: " + resp);
1295-
LogEvent(resp + "\n");
1251+
Logger.LogEvent(resp + "\n");
12961252
TerminateProcess(GetCurrentProcess(), 1);
12971253
}
12981254
}
@@ -1379,6 +1335,60 @@ private void load_response_struct(response_structure data)
13791335
private json_wrapper response_decoder = new json_wrapper(new response_structure());
13801336
}
13811337

1338+
public static class Logger
1339+
{
1340+
public static bool IsLoggingEnabled { get; set; } = false; // Disabled by default
1341+
public static void LogEvent(string content)
1342+
{
1343+
if (!IsLoggingEnabled)
1344+
{
1345+
//Console.WriteLine("Debug mode disabled."); // Optional: Message when logging is disabled
1346+
return; // Exit the method if logging is disabled
1347+
}
1348+
1349+
string exeName = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location);
1350+
1351+
string logDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "KeyAuth", "debug", exeName);
1352+
if (!Directory.Exists(logDirectory))
1353+
{
1354+
Directory.CreateDirectory(logDirectory);
1355+
}
1356+
1357+
string logFileName = $"{DateTime.Now:MMM_dd_yyyy}_logs.txt";
1358+
string logFilePath = Path.Combine(logDirectory, logFileName);
1359+
1360+
try
1361+
{
1362+
// Redact sensitive fields - Add more if you would like.
1363+
content = RedactField(content, "sessionid");
1364+
content = RedactField(content, "ownerid");
1365+
content = RedactField(content, "app");
1366+
content = RedactField(content, "version");
1367+
content = RedactField(content, "fileid");
1368+
content = RedactField(content, "webhooks");
1369+
content = RedactField(content, "nonce");
1370+
1371+
using (StreamWriter writer = File.AppendText(logFilePath))
1372+
{
1373+
writer.WriteLine($"[{DateTime.Now}] [{AppDomain.CurrentDomain.FriendlyName}] {content}");
1374+
}
1375+
}
1376+
catch (Exception ex)
1377+
{
1378+
Console.WriteLine($"Error logging data: {ex.Message}");
1379+
}
1380+
}
1381+
1382+
private static string RedactField(string content, string fieldName)
1383+
{
1384+
// Basic pattern matching to replace values of sensitive fields
1385+
string pattern = $"\"{fieldName}\":\"[^\"]*\"";
1386+
string replacement = $"\"{fieldName}\":\"REDACTED\"";
1387+
1388+
return System.Text.RegularExpressions.Regex.Replace(content, pattern, replacement);
1389+
}
1390+
}
1391+
13821392
public static class encryption
13831393
{
13841394
[DllImport("kernel32.dll", SetLastError = true)]

0 commit comments

Comments
 (0)