Example #1
36
        /// <summary>
        /// Create a new keyboard hooker instance.
        /// </summary>
        private KeyboardHook()
        {
            hotkeys = new Dictionary<Int32, HashSet<Keys>>();

            hotkeysToNames = new Dictionary<Hotkey, String>();
            namesToHotkeys = new Dictionary<String, Hotkey>();
            hotkeysForward = new Dictionary<Hotkey, Boolean>();

            dispatcher = Dispatcher.CurrentDispatcher;
            hookID = IntPtr.Zero;
            hookedCallback = Callback;
        }
        public LowLevelKeyHook()
        {
            pressedKey = new List <int>();

            hookProcDelegate = KeyboardHookCallback;
            setGlobalHook(true);
        }
Example #3
0
        /// <summary>
        /// Event handler that's called when the window is loaded; shows <see cref="_layeredWindow" /> and installs the mouse hook via
        /// <see cref="User32.SetWindowsHookEx" />.
        /// </summary>
        /// <param name="e">Arguments associated with this event.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            _initialized = true;

            UpdateLayeredBackground();

            _layeredWindow.Show();
            _layeredWindow.Enabled = false;

            // Installs the mouse hook
            if (!_hookInstalled)
            {
                using (Process curProcess = Process.GetCurrentProcess())
                {
                    using (ProcessModule curModule = curProcess.MainModule)
                    {
                        _hookproc = MouseHookCallback;
                        _hookId   = User32.SetWindowsHookEx(WH.WH_MOUSE_LL, _hookproc, Kernel32.GetModuleHandle(curModule.ModuleName), 0);
                    }
                }

                _hookInstalled = true;
            }
        }
Example #4
0
        /// <summary>
        /// Initializes the UI, loads the bookmark and history data, and sets up the IPC remoting channel and low-level keyboard hook.
        /// </summary>
        protected void Init()
        {
            AeroPeekEnabled = false;

            // Create a remoting channel used to tell this window to open historical connections when entries in the jump list are clicked
            if (_ipcChannel == null)
            {
                _ipcChannel = new IpcServerChannel("EasyConnect");
                ChannelServices.RegisterChannel(_ipcChannel, false);
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(HistoryMethods), "HistoryMethods", WellKnownObjectMode.SingleCall);
            }

            // Wire up the tab event handlers
            TabClicked += MainForm_TabClicked;

            ActiveInstance         = this;
            ConnectToHistoryMethod = ConnectToHistory;

            TabRenderer = new ChromeTabRenderer(this);

            // Get the low-level keyboard hook that will be used to process shortcut keys
            using (Process curProcess = Process.GetCurrentProcess())
                using (ProcessModule curModule = curProcess.MainModule)
                {
                    _hookproc = KeyboardHookCallback;
                    _hookId   = User32.SetWindowsHookEx(WH.WH_KEYBOARD_LL, _hookproc, Kernel32.GetModuleHandle(curModule.ModuleName), 0);
                }
        }
Example #5
0
        private static IntPtr MsLLHookCallback(int nCode, HOOKPROC wParam, TagMSLLHOOKSTRUCT lParam)
        {
            MouseEventArgs MsEventArgs = new MouseEventArgs();

            MsEventArgs.LowLevelMsInfo.dwExtraInfo = lParam.dwExtraInfo;
            MsEventArgs.LowLevelMsInfo.flags       = lParam.flags;
            MsEventArgs.LowLevelMsInfo.mouseData   = lParam.mouseData;
            MsEventArgs.LowLevelMsInfo.pt          = lParam.pt;
            MsEventArgs.LowLevelMsInfo.time        = lParam.time;
            switch (wParam)
            {
            case HOOKPROC.WM_LBUTTONDOWN:
                OnMouseLBtnDownEvent?.Invoke(nCode, MsEventArgs);
                break;

            case HOOKPROC.WM_LBUTTONUP:
                OnMouseLBtnUpEvent?.Invoke(nCode, MsEventArgs);
                break;

            case HOOKPROC.WM_RBUTTONDOWN:
                OnMouseRBtnDownEvent?.Invoke(nCode, MsEventArgs);
                break;

            case HOOKPROC.WM_RBUTTONUP:
                OnMouseRBtnUpEvent?.Invoke(nCode, MsEventArgs);
                break;
            }
            return(CallNextHookEx(_LowLevelMsHookID, nCode, wParam, lParam));
        }
        /// <summary>
        /// Attaches the various event handlers to <see cref="_parentForm" /> so that the overlay is moved in synchronization to
        /// <see cref="_parentForm" />.
        /// </summary>
        protected void AttachHandlers()
        {
            _parentForm.Closing             += _parentForm_Closing;
            _parentForm.Disposed            += _parentForm_Disposed;
            _parentForm.Deactivate          += _parentForm_Deactivate;
            _parentForm.Activated           += _parentForm_Activated;
            _parentForm.SizeChanged         += _parentForm_Refresh;
            _parentForm.Shown               += _parentForm_Refresh;
            _parentForm.VisibleChanged      += _parentForm_Refresh;
            _parentForm.Move                += _parentForm_Refresh;
            _parentForm.SystemColorsChanged += _parentForm_SystemColorsChanged;

            if (_hookproc == null)
            {
                // Spin up a consumer thread to process mouse events from _mouseEvents
                _mouseEventsThread = new Thread(InterpretMouseEvents)
                {
                    Name = "Low level mouse hooks processing thread"
                };
                _mouseEventsThread.Priority = ThreadPriority.Highest;
                _mouseEventsThread.Start();

                using (Process curProcess = Process.GetCurrentProcess())
                {
                    using (ProcessModule curModule = curProcess.MainModule)
                    {
                        // Install the low level mouse hook that will put events into _mouseEvents
                        _hookproc = MouseHookCallback;
                        _hookId   = User32.SetWindowsHookEx(WH.WH_MOUSE_LL, _hookproc, Kernel32.GetModuleHandle(curModule.ModuleName), 0);
                    }
                }
            }
        }
Example #7
0
 public bool InstallHookKey(HOOKPROC prc)
 {
     IntPtr intPtr=GetModuleHandle (System.Diagnostics.Process.GetCurrentProcess().MainModule .ModuleName );
     hookKeyResult = SetWindowsHookEx(IdHook.WH_KEYBOARD_LL, prc, intPtr, 0);
     if (hookKeyResult == 0)
         return false;
     return true;
 }
Example #8
0
        public void InstallKeyboardHook()
        {
            m_keyboardHookProcedure = new HOOKPROC(KeyboardHookProc);
            m_keyboardHook          = new NuGenHookHandle(WinUser.WH_KEYBOARD_LL, m_keyboardHookProcedure);

            if (m_keyboardHook.IsInvalid)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), Resources.Win32_InvalidKbdLLHookHandle);
            }
        }
Example #9
0
 public static IntPtr SetHook(WH hookType, HOOKPROC proc)
 {
     using (var curProcess = Process.GetCurrentProcess())
     {
         using (var curModule = curProcess.MainModule)
         {
             return(SetWindowsHookExW(hookType, proc, Kernel32.GetModuleHandleW(curModule.ModuleName), 0));
         }
     }
 }
Example #10
0
		public void InstallKeyboardHook()
		{
			m_keyboardHookProcedure = new HOOKPROC(KeyboardHookProc);
			m_keyboardHook = new NuGenHookHandle(WinUser.WH_KEYBOARD_LL, m_keyboardHookProcedure);

			if (m_keyboardHook.IsInvalid)
			{
				throw new Win32Exception(Marshal.GetLastWin32Error(), Resources.Win32_InvalidKbdLLHookHandle);
			}
		}
Example #11
0
        public bool InstallHookKey(HOOKPROC prc)
        {
            IntPtr intPtr = GetModuleHandle(System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName);

            hookKeyResult = SetWindowsHookEx(IdHook.WH_KEYBOARD_LL, prc, intPtr, 0);
            if (hookKeyResult == 0)
            {
                return(false);
            }
            return(true);
        }
Example #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NuGenKeyInterceptor"/> class.
        /// </summary>
        public NuGenKeyInterceptor()
        {
            _hotKeys      = new NuGenHotKeysLL();
            _hookCallBack = new HOOKPROC(this.HookCallback);
            _handle       = new NuGenHookHandle(WinUser.WH_KEYBOARD_LL, _hookCallBack);

            if (_handle.IsInvalid)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), Resources.Win32_InvalidKbdLLHookHandle);
            }
        }
Example #13
0
        public static void UnHook()
        {
            if (!hooking)
            {
                return;
            }
            hooking = false;

            UnhookWindowsHookEx(handle);
            handle    = IntPtr.Zero;
            hookProc -= HookProc;
        }
Example #14
0
        /// <summary>
        /// Create a new keyboard hooker instance.
        /// </summary>
        private KeyboardHook()
        {
            hotkeys = new Dictionary <Int32, HashSet <Keys> >();

            hotkeysToNames = new Dictionary <Hotkey, String>();
            namesToHotkeys = new Dictionary <String, Hotkey>();
            hotkeysForward = new Dictionary <Hotkey, Boolean>();

            dispatcher     = Dispatcher.CurrentDispatcher;
            hookID         = IntPtr.Zero;
            hookedCallback = Callback;
        }
Example #15
0
        private static Func <Keys, bool> _hak; // hookActionKeyboard

        public static void HookKeyboard(Func <Keys, bool> action)
        {
            const int WH_KEYBOARD_LL = 13;

            if (_hhkk != IntPtr.Zero)
            {
                throw new StackOverflowException();
            }

            _hak  = action;
            _hpk  = new HOOKPROC(LowLevelKeyboardProc);
            _hhkk = SetWindowsHookEx(WH_KEYBOARD_LL, _hpk, IntPtr.Zero, 0);
        }
Example #16
0
        public static void Hook()
        {
            if (hooking)
            {
                return;
            }
            hooking = true;

            hookProc = HookProc;
            handle   = SetWindowsHookEx(SYS_WH_KEYBORD_LL, hookProc, Marshal.GetHINSTANCE(typeof(SysCaller).Assembly.GetModules()[0]), 0);
            if (IntPtr.Zero == handle)
            {
                hooking = false;
                throw new System.ComponentModel.Win32Exception();
            }
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="NuGenHookHandle"/> class.
		/// </summary>
		/// <param name="idHook">Specifies the type of hook procedure to be installed. See the SetWindowsHookEx Function article on MSDN for more info.</param>
		/// <param name="callbackProc">Specifies the method to be installed into a hook chain.</param>
		/// <exception cref="ArgumentNullException">
		/// <para>
		///		<paramref name="callbackProc"/> is <see langword="null"/>.
		/// </para>
		/// </exception>
		public NuGenHookHandle(Int32 idHook, HOOKPROC callbackProc)
			: base(true)
		{
			if (callbackProc == null)
			{
				throw new ArgumentNullException("proc");
			}

			using (Process curProcess = Process.GetCurrentProcess())
			using (ProcessModule curModule = curProcess.MainModule)
			{
				this.SetHandle(
					User32.SetWindowsHookEx(
						idHook
						, callbackProc
						, Kernel32.GetModuleHandle(curModule.ModuleName)
						, 0
					)
				);
			}
		}
Example #18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NuGenHookHandle"/> class.
        /// </summary>
        /// <param name="idHook">Specifies the type of hook procedure to be installed. See the SetWindowsHookEx Function article on MSDN for more info.</param>
        /// <param name="callbackProc">Specifies the method to be installed into a hook chain.</param>
        /// <exception cref="ArgumentNullException">
        /// <para>
        ///		<paramref name="callbackProc"/> is <see langword="null"/>.
        /// </para>
        /// </exception>
        public NuGenHookHandle(Int32 idHook, HOOKPROC callbackProc)
            : base(true)
        {
            if (callbackProc == null)
            {
                throw new ArgumentNullException("proc");
            }

            using (Process curProcess = Process.GetCurrentProcess())
                using (ProcessModule curModule = curProcess.MainModule)
                {
                    this.SetHandle(
                        User32.SetWindowsHookEx(
                            idHook
                            , callbackProc
                            , Kernel32.GetModuleHandle(curModule.ModuleName)
                            , 0
                            )
                        );
                }
        }
Example #19
0
 public static extern IntPtr SetWindowsHookEx(int idHook, HOOKPROC lpfn, [In] IntPtr hModuleHandle, int threadId);
Example #20
0
 private static extern int SetWindowsHookEx(IdHook idHook, HOOKPROC lpfn, IntPtr hInstance, int threadId);
Example #21
0
 public static IntPtr SetHook(HOOKPROC proc)
 {
     using var curProcess = Process.GetCurrentProcess();
     using var curModule  = curProcess.MainModule;
     return(SetWindowsHookExW(WH.KEYBOARD_LL, proc, Kernel32.GetModuleHandleW(curModule.ModuleName), 0));
 }
Example #22
0
 public static IntPtr SetWindowHookByThreadId(uint threadId, HOOKTYPE type, HOOKPROC callback)
 {
     return NativeMethods.SetWindowsHookEx(type, callback, IntPtr.Zero, threadId);
 }
Example #23
0
 public static extern IntPtr SetWindowsHookEx(int hookType, HOOKPROC lpfn, IntPtr hMod, uint dwThreadId);
Example #24
0
 public static extern int SetWindowsHookEx(int idHook, HOOKPROC lpfn, int hMod, int dwThreadId);
 public static extern IntPtr SetWindowsHookEx(HookType code, HOOKPROC func, IntPtr hInstance, int threadID);
Example #26
0
		public static extern IntPtr SetWindowsHookEx(Int32 idHook, HOOKPROC lpfn, IntPtr hInstance, Int32 threadId);
Example #27
0
 public static extern IntPtr SetWindowsHookEx(int idHook, HOOKPROC lpfn, [In] IntPtr hModuleHandle, int threadId);
Example #28
0
 public static IntPtr SetWindowHookByModule(IntPtr module, HOOKTYPE type, HOOKPROC callback)
 {
     return NativeMethods.SetWindowsHookEx(type, callback, module, 0);
 }
		/// <summary>
		/// Attaches the various event handlers to <see cref="_parentForm" /> so that the overlay is moved in synchronization to
		/// <see cref="_parentForm" />.
		/// </summary>
		protected void AttachHandlers()
		{
			_parentForm.Disposed += _parentForm_Disposed;
			_parentForm.Deactivate += _parentForm_Deactivate;
			_parentForm.Activated += _parentForm_Activated;
			_parentForm.SizeChanged += _parentForm_Refresh;
			_parentForm.Shown += _parentForm_Refresh;
			_parentForm.VisibleChanged += _parentForm_Refresh;
			_parentForm.Move += _parentForm_Refresh;
			_parentForm.SystemColorsChanged += _parentForm_SystemColorsChanged;

			using (Process curProcess = Process.GetCurrentProcess())
			{
				using (ProcessModule curModule = curProcess.MainModule)
				{
					_hookproc = MouseHookCallback;
					_hookId = User32.SetWindowsHookEx(WH.WH_MOUSE_LL, _hookproc, Kernel32.GetModuleHandle(curModule.ModuleName), 0);
				}
			}
		}
Example #30
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="type"></param>
 internal Hook(WINDOWS_HOOK_ID type)
 {
     Type     = type;
     Delegate = Callback;
 }
Example #31
0
 private static extern IntPtr SetWindowsHookEx(Int32 idHook, HOOKPROC lpfn, IntPtr hMod, UInt32 dwThreadId);
Example #32
0
        /// <summary>
        /// Initializes the UI, loads the bookmark and history data, and sets up the IPC remoting channel and low-level keyboard hook.
        /// </summary>
        protected void Init()
        {
            AeroPeekEnabled = false;
            bool convertingToRsa = false;

            // If the user hasn't formally selected an encryption type (either they're starting the application for the first time or are running a legacy
            // version that explicitly used Rijndael), ask them if they want to use RSA
            if (Options.EncryptionType == null)
            {
                string messageBoxText = @"Do you want to use an RSA key container to encrypt your passwords?

            The RSA encryption mode uses cryptographic keys associated with
            your Windows user account to encrypt sensitive data without having
            to enter an encryption password every time you start this
            application. However, your bookmarks file will be tied uniquely to
            this user account and you will be unable to share them between
            multiple users.";

                if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\EasyConnect"))
                    messageBoxText += @"

            The alternative is to derive an encryption key from a password that
            you will need to enter every time that this application starts.";

                else
                    messageBoxText += @"

            Since you've already encrypted your data with a password once,
            you would need to enter it one more time to decrypt it before RSA
            can be used.";

                Options.EncryptionType = MessageBox.Show(messageBoxText, "Use RSA?", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes
                                             ? EncryptionType.Rsa
                                             : EncryptionType.Rijndael;

                // Since they want to use RSA but already have connection data encrypted with Rijndael, we'll have to capture that password so that we can
                // decrypt it using Rijndael and then re-encrypt it using the RSA keypair
                convertingToRsa = Options.EncryptionType == EncryptionType.Rsa &&
                                  Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\EasyConnect");
            }

            // If this is the first time that the user is running the application, pop up and information box informing them that they're going to enter a
            // password used to encrypt sensitive connection details
            if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\EasyConnect"))
            {
                if (Options.EncryptionType == EncryptionType.Rijndael)
                    MessageBox.Show(Resources.FirstRunPasswordText, Resources.FirstRunPasswordTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);

                Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\EasyConnect");
            }

            if (Options.EncryptionType != null)
                Options.Save();

            bool encryptionTypeSet = false;

            while (Bookmarks == null || _history == null)
            {
                // Get the user's encryption password via the password dialog
                if (!encryptionTypeSet && (Options.EncryptionType == EncryptionType.Rijndael || convertingToRsa))
                {
                    PasswordWindow passwordWindow = new PasswordWindow();
                    passwordWindow.ShowDialog();

                    ConnectionFactory.SetEncryptionType(EncryptionType.Rijndael, passwordWindow.Password);
                }

                else
                    ConnectionFactory.SetEncryptionType(Options.EncryptionType.Value);

                // Create the bookmark and history windows which will try to use the password to decrypt sensitive connection details; if it's unable to, an
                // exception will be thrown that wraps a CryptographicException instance
                try
                {
                    _bookmarks = new BookmarksWindow(this);
                    _history = new HistoryWindow(this);

                    ConnectionFactory.GetDefaultProtocol();

                    encryptionTypeSet = true;
                }

                catch (Exception e)
                {
                    if ((Options.EncryptionType == EncryptionType.Rijndael || convertingToRsa) && !ContainsCryptographicException(e))
                        throw;

                    // Tell the user that their password is incorrect and, if they click OK, repeat the process
                    DialogResult result = MessageBox.Show(
                        Resources.IncorrectPasswordText, Resources.ErrorTitle, MessageBoxButtons.OKCancel, MessageBoxIcon.Error);

                    if (result != DialogResult.OK)
                    {
                        IsClosing = true;
                        return;
                    }
                }
            }

            // If we're converting over to RSA, we've already loaded and decrypted the sensitive data using
            if (convertingToRsa)
                SetEncryptionType(Options.EncryptionType.Value, null);

            // Create a remoting channel used to tell this window to open historical connections when entries in the jump list are clicked
            if (_ipcChannel == null)
            {
                _ipcChannel = new IpcServerChannel("EasyConnect");
                ChannelServices.RegisterChannel(_ipcChannel, false);
                RemotingConfiguration.RegisterWellKnownServiceType(typeof (HistoryMethods), "HistoryMethods", WellKnownObjectMode.SingleCall);
            }

            // Wire up the tab event handlers
            TabClicked += MainForm_TabClicked;

            ActiveInstance = this;
            ConnectToHistoryMethod = ConnectToHistory;

            TabRenderer = new ChromeTabRenderer(this);

            // Get the low-level keyboard hook that will be used to process shortcut keys
            using (Process curProcess = Process.GetCurrentProcess())
            using (ProcessModule curModule = curProcess.MainModule)
            {
                _hookproc = KeyboardHookCallback;
                _hookId = User32.SetWindowsHookEx(WH.WH_KEYBOARD_LL, _hookproc, Kernel32.GetModuleHandle(curModule.ModuleName), 0);
            }
        }
		/// <summary>
		/// Attaches the various event handlers to <see cref="_parentForm" /> so that the overlay is moved in synchronization to <see cref="_parentForm" />.
		/// </summary>
		protected void AttachHandlers()
		{
			_parentForm.Closing += _parentForm_Closing;
			_parentForm.Disposed += _parentForm_Disposed;
			_parentForm.Deactivate += _parentForm_Deactivate;
			_parentForm.Activated += _parentForm_Activated;
			_parentForm.SizeChanged += _parentForm_Refresh;
			_parentForm.Shown += _parentForm_Refresh;
			_parentForm.VisibleChanged += _parentForm_Refresh;
			_parentForm.Move += _parentForm_Refresh;
			_parentForm.SystemColorsChanged += _parentForm_SystemColorsChanged;

			if (_hookproc == null)
			{
				// Spin up a consumer thread to process mouse events from _mouseEvents
				_mouseEventsThread = new Thread(InterpretMouseEvents)
					                     {
						                     Name = "Low level mouse hooks processing thread"
					                     };
				_mouseEventsThread.Start();

				using (Process curProcess = Process.GetCurrentProcess())
				{
					using (ProcessModule curModule = curProcess.MainModule)
					{
						// Install the low level mouse hook that will put events into _mouseEvents
						_hookproc = MouseHookCallback;
						_hookId = User32.SetWindowsHookEx(WH.WH_MOUSE_LL, _hookproc, Kernel32.GetModuleHandle(curModule.ModuleName), 0);
					}
				}
			}
		}
Example #34
0
        /// <summary>
        /// Event handler that's called when the window is loaded; shows <see cref="_layeredWindow" /> and installs the mouse hook via
        /// <see cref="User32.SetWindowsHookEx" />.
        /// </summary>
        /// <param name="e">Arguments associated with this event.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            _initialized = true;

            UpdateLayeredBackground();

            _layeredWindow.Show();
            _layeredWindow.Enabled = false;

            // Installs the mouse hook
            if (!_hookInstalled)
            {
                using (Process curProcess = Process.GetCurrentProcess())
                {
                    using (ProcessModule curModule = curProcess.MainModule)
                    {
                        _hookproc = MouseHookCallback;
                        _hookId = User32.SetWindowsHookEx(WH.WH_MOUSE_LL, _hookproc, Kernel32.GetModuleHandle(curModule.ModuleName), 0);
                    }
                }

                _hookInstalled = true;
            }
        }
Example #35
0
 internal static extern IntPtr SetWindowsHookEx(WH idHook, HOOKPROC lpfn, IntPtr hMod, int dwThreadId);
Example #36
0
File: Win32.cs Project: xlgwr/RFID
 public static extern IntPtr SetWindowsHookEx(int idHook, [MarshalAs(UnmanagedType.FunctionPtr)] HOOKPROC lpfn, IntPtr hmod, uint dwThreadId);
 public WindowsHookBase(WH hook)
 {
     _hookID     = IntPtr.Zero;
     _hookType   = hook;
     _filterFunc = new HOOKPROC(this.CoreHookProc);
 }
Example #38
0
        /// <summary>
        /// Initializes the UI, loads the bookmark and history data, and sets up the IPC remoting channel and low-level keyboard hook.
        /// </summary>
        protected void Init()
        {
            AeroPeekEnabled = false;
            bool convertingToRsa = false;

            // If the user hasn't formally selected an encryption type (either they're starting the application for the first time or are running a legacy
            // version that explicitly used Rijndael), ask them if they want to use RSA
            if (Options.EncryptionType == null)
            {
                string messageBoxText = @"Do you want to use an RSA key container to encrypt your passwords?

The RSA encryption mode uses cryptographic keys associated with 
your Windows user account to encrypt sensitive data without having 
to enter an encryption password every time you start this 
application. However, your bookmarks file will be tied uniquely to 
this user account and you will be unable to share them between
multiple users.";

                if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\EasyConnect"))
                {
                    messageBoxText += @"

The alternative is to derive an encryption key from a password that
you will need to enter every time that this application starts.";
                }

                else
                {
                    messageBoxText += @"

Since you've already encrypted your data with a password once, 
you would need to enter it one more time to decrypt it before RSA 
can be used.";
                }

                Options.EncryptionType = MessageBox.Show(messageBoxText, "Use RSA?", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes
                                                                 ? EncryptionType.Rsa
                                                                 : EncryptionType.Rijndael;

                // Since they want to use RSA but already have connection data encrypted with Rijndael, we'll have to capture that password so that we can
                // decrypt it using Rijndael and then re-encrypt it using the RSA keypair
                convertingToRsa = Options.EncryptionType == EncryptionType.Rsa &&
                                  Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\EasyConnect");
            }

            // If this is the first time that the user is running the application, pop up and information box informing them that they're going to enter a
            // password used to encrypt sensitive connection details
            if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\EasyConnect"))
            {
                if (Options.EncryptionType == EncryptionType.Rijndael)
                {
                    MessageBox.Show(Resources.FirstRunPasswordText, Resources.FirstRunPasswordTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\EasyConnect");
            }

            if (Options.EncryptionType != null)
            {
                Options.Save();
            }

            bool encryptionTypeSet = false;

            while (Bookmarks == null || _history == null)
            {
                // Get the user's encryption password via the password dialog
                if (!encryptionTypeSet && (Options.EncryptionType == EncryptionType.Rijndael || convertingToRsa))
                {
                    PasswordWindow passwordWindow = new PasswordWindow();
                    passwordWindow.ShowDialog();

                    ConnectionFactory.SetEncryptionType(EncryptionType.Rijndael, passwordWindow.Password);
                }

                else
                {
                    ConnectionFactory.SetEncryptionType(Options.EncryptionType.Value);
                }

                // Create the bookmark and history windows which will try to use the password to decrypt sensitive connection details; if it's unable to, an
                // exception will be thrown that wraps a CryptographicException instance
                try
                {
                    _bookmarks = new BookmarksWindow(this);
                    _history   = new HistoryWindow(this);

                    ConnectionFactory.GetDefaultProtocol();

                    encryptionTypeSet = true;
                }

                catch (Exception e)
                {
                    if ((Options.EncryptionType == EncryptionType.Rijndael || convertingToRsa) && !ContainsCryptographicException(e))
                    {
                        throw;
                    }

                    // Tell the user that their password is incorrect and, if they click OK, repeat the process
                    DialogResult result = MessageBox.Show(
                        Resources.IncorrectPasswordText, Resources.ErrorTitle, MessageBoxButtons.OKCancel, MessageBoxIcon.Error);

                    if (result != DialogResult.OK)
                    {
                        IsClosing = true;
                        return;
                    }
                }
            }

            // If we're converting over to RSA, we've already loaded and decrypted the sensitive data using
            if (convertingToRsa)
            {
                SetEncryptionType(Options.EncryptionType.Value, null);
            }

            // Create a remoting channel used to tell this window to open historical connections when entries in the jump list are clicked
            if (_ipcChannel == null)
            {
                _ipcChannel = new IpcServerChannel("EasyConnect");
                ChannelServices.RegisterChannel(_ipcChannel, false);
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(HistoryMethods), "HistoryMethods", WellKnownObjectMode.SingleCall);
            }

            // Wire up the tab event handlers
            TabClicked += MainForm_TabClicked;

            ActiveInstance         = this;
            ConnectToHistoryMethod = ConnectToHistory;

            TabRenderer = new ChromeTabRenderer(this);

            // Get the low-level keyboard hook that will be used to process shortcut keys
            using (Process curProcess = Process.GetCurrentProcess())
                using (ProcessModule curModule = curProcess.MainModule)
                {
                    _hookproc = KeyboardHookCallback;
                    _hookId   = User32.SetWindowsHookEx(WH.WH_KEYBOARD_LL, _hookproc, Kernel32.GetModuleHandle(curModule.ModuleName), 0);
                }
        }
Example #39
0
 public static extern IntPtr SetWindowLong(IntPtr hwnd, GWL nIndex, HOOKPROC dwNewLong);
Example #40
0
 private static extern int SetWindowsHookEx(IdHook idHook, HOOKPROC lpfn, IntPtr hInstance, int threadId);
Example #41
0
 public static IntPtr SetWindowHookByModule(IntPtr module, HOOKTYPE type, HOOKPROC callback)
 {
     return(NativeMethods.SetWindowsHookEx(type, callback, module, 0));
 }
Example #42
0
 public static extern IntPtr SetWindowsHookEx(IdHook idHook, HOOKPROC lpfn, IntPtr hmod, uint dwThreadId);
Example #43
0
 public static extern HHOOK SetWindowsHookEx(int idHook, HOOKPROC lpfn, HINSTANCE hMod, DWORD dwThreadId);
Example #44
0
 private static extern IntPtr SetWindowsHookEx(int idHook, HOOKPROC lpfn, IntPtr hMod, IntPtr dwThreadId);
Example #45
0
 public static extern IntPtr SetWindowsHookEx(HOOKTYPE hookType, HOOKPROC lpfn, IntPtr hModule, uint dwThreadId);
Example #46
0
 private static extern IntPtr SetWindowsHookEx(int idHook, HOOKPROC lpfn, IntPtr hInstance, IntPtr threadId);
Example #47
0
		internal static extern IntPtr SetWindowsHookEx(WH idHook, HOOKPROC lpfn, IntPtr hMod, int dwThreadId);
 public WindowsHookBase(WH hook, HOOKPROC func)
 {
     _hookID     = IntPtr.Zero;
     _hookType   = hook;
     _filterFunc = func;
 }
		/// <summary>
		/// Initializes a new instance of the <see cref="NuGenKeyInterceptor"/> class.
		/// </summary>
		public NuGenKeyInterceptor()
		{
			_hotKeys = new NuGenHotKeysLL();
			_hookCallBack = new HOOKPROC(this.HookCallback);
			_handle = new NuGenHookHandle(WinUser.WH_KEYBOARD_LL, _hookCallBack);

			if (_handle.IsInvalid)
			{
				throw new Win32Exception(Marshal.GetLastWin32Error(), Resources.Win32_InvalidKbdLLHookHandle);
			}
		}