Esempio n. 1
0
 protected override bool Hook()
 {
     if (IsHooked)
     {
         return(false);
     }
     if (IsConsole)
     {
         AppSim = ApplicationSimulator.Create();
         AppSim.Invoke(() => hook(
                           AppSim.InvokeReturn(() =>
                                               NativeWin32.LoadLibrary("user32.dll"))
                           ));
     }
     else
     {
         hook(NativeWin32.LoadLibrary("user32.dll"));
     }
     if (IsThreadRunning == false)
     {
         ProcessorStart();
     }
     return(true);
 }
Esempio n. 2
0
        public void Start()
        {
            if (!_isStarted && _hookType != 0)
            {
                // Make sure we keep a reference to this delegate!
                // If not, GC randomly collects it, and a NullReference exception is thrown
                _hookCallback = HookCallbackProcedure;
                _handleToHook = SetWindowsHookEx(
                    _hookType,
                    _hookCallback,
                    NativeWin32.LoadLibrary("User32"),
                    0);

                // Were we able to sucessfully start hook?
                if (_handleToHook != 0)
                {
                    _isStarted = true;
                }
                else
                {
                    Console.WriteLine("Hooking error id: " + Marshal.GetLastWin32Error());
                }
            }
        }