DllExport BOOL UnSetHook(HWND hWnd) { BOOL unHooked = TRUE; // Remove the extra property value from all local windows EnumWindows((WNDENUMPROC) &KillPropsProc, NULL); // Stop the keyboard & mouse hooks unHooked = unHooked && SetKeyboardFilterHook(FALSE); unHooked = unHooked && SetMouseFilterHook(FALSE); // Is the window handle valid? if (hWnd == NULL) MessageBox(NULL, "Window pointer is null", "Message", MB_OK); // Is the correct application calling UnSetHook? if (hWnd != hVeneto) return FALSE; // Unhook the procs if (hCallWndHook != NULL) { unHooked = unHooked && UnhookWindowsHookEx(hCallWndHook); hCallWndHook = NULL; } if (hGetMsgHook != NULL) { unHooked = unHooked && UnhookWindowsHookEx(hGetMsgHook); hGetMsgHook = NULL; } if (hDialogMsgHook != NULL) { unHooked = unHooked && UnhookWindowsHookEx(hDialogMsgHook); hDialogMsgHook = NULL; } // If we managed to unhook then reset if (unHooked) { hVeneto = NULL; HookMaster = FALSE; } return unHooked; }
DllExport BOOL UnSetHooks(DWORD thread_id) { BOOL unHooked = TRUE; // Remove the extra property value from all local windows EnumWindows((WNDENUMPROC) &KillPropsProc, NULL); // Stop the keyboard & mouse hooks unHooked = unHooked && SetKeyboardFilterHook(FALSE); unHooked = unHooked && SetMouseFilterHook(FALSE); // Is the window handle valid? //if (thread_id != vnc_thread_id) // Max: do not think this check is needed // return FALSE; // Unhook the procs if (hCallWndHook != NULL) { unHooked = unHooked && UnhookWindowsHookEx(hCallWndHook); hCallWndHook = NULL; } if (hGetMsgHook != NULL) { unHooked = unHooked && UnhookWindowsHookEx(hGetMsgHook); hGetMsgHook = NULL; } if (hDialogMsgHook != NULL) { unHooked = unHooked && UnhookWindowsHookEx(hDialogMsgHook); hDialogMsgHook = NULL; } // If we managed to unhook then reset if (unHooked) { vnc_thread_id = 0; HookMaster = FALSE; } #ifdef _MSC_VER _RPT0(_CRT_WARN, "vncHooks : Hooking stopped"); #endif return unHooked; }
DllExport BOOL UnSetHooks(DWORD thread_id) { BOOL unHooked = TRUE; // Remove the extra property value from all local windows EnumWindows((WNDENUMPROC) &KillPropsProc, NULL); // Stop the keyboard & mouse hooks unHooked = unHooked && SetKeyboardFilterHook(FALSE); unHooked = unHooked && SetMouseFilterHook(FALSE); // Is the window handle valid? if (thread_id != vnc_thread_id) return FALSE; // Unhook the procs if (hCallWndHook != NULL) { unHooked = unHooked && UnhookWindowsHookEx(hCallWndHook); hCallWndHook = NULL; } if (hGetMsgHook != NULL) { unHooked = unHooked && UnhookWindowsHookEx(hGetMsgHook); hGetMsgHook = NULL; } if (hDialogMsgHook != NULL) { unHooked = unHooked && UnhookWindowsHookEx(hDialogMsgHook); hDialogMsgHook = NULL; } // If we managed to unhook then reset if (unHooked) { vnc_thread_id = 0; HookMaster = FALSE; } return unHooked; }
DllExport BOOL SetHook(HWND hWnd, UINT UpdateMsg, UINT CopyMsg, UINT MouseMsg, UINT WndMsg) { // Don't add the hook if the window ID is NULL if (hWnd == NULL) return FALSE; // Don't add a hook if there is already one added if (hVeneto != NULL) return FALSE; // check only window change message ? m_wndonly = (UpdateMsg == NULL && CopyMsg == NULL && MouseMsg == NULL); // Add the CallWnd hook hCallWndHook = SetWindowsHookEx( WH_CALLWNDPROC, // Hook in before msg reaches app (HOOKPROC) CallWndProc, // Hook procedure hInstance, // This DLL instance 0L // Hook in to all apps // GetCurrentThreadId() // DEBUG : HOOK ONLY WinVNC ); if (!m_wndonly) { // Add the GetMessage hook hGetMsgHook = SetWindowsHookEx( WH_GETMESSAGE, // Hook in before msg reaches app (HOOKPROC) GetMessageProc, // Hook procedure hInstance, // This DLL instance 0L // Hook in to all apps // GetCurrentThreadId() // DEBUG : HOOK ONLY WinVNC ); // Add the GetMessage hook hDialogMsgHook = SetWindowsHookEx( WH_SYSMSGFILTER, // Hook in dialogs, menus and scrollbars (HOOKPROC) DialogMessageProc, // Hook procedure hInstance, // This DLL instance 0L // Hook in to all apps ); } // Check that it worked if ((m_wndonly && (hCallWndHook != NULL)) || ((hCallWndHook != NULL) && (hGetMsgHook != NULL) && (hDialogMsgHook != NULL))) { hVeneto = hWnd; // Save the WinRFB window handle UpdateRectMessage = UpdateMsg; // Save the message ID to use for rectangle updates CopyRectMessage = CopyMsg; // Save the message ID to use for copyrect MouseMoveMessage = MouseMsg; // Save the message ID to send when mouse moves WndChangeMessage = WndMsg; // Save the message ID to send when window created/closed HookMaster = TRUE; // Set the HookMaster flag for this instance #ifdef _MSC_VER _RPT1(_CRT_WARN, "Window : %d\n", hWnd); #endif return TRUE; } else { // Stop the keyboard hook SetKeyboardFilterHook(FALSE); SetMouseFilterHook(FALSE); // Kill the main hooks if (hCallWndHook != NULL) UnhookWindowsHookEx(hCallWndHook); if (hGetMsgHook != NULL) UnhookWindowsHookEx(hGetMsgHook); if (hDialogMsgHook != NULL) UnhookWindowsHookEx(hDialogMsgHook); hCallWndHook = NULL; hGetMsgHook = NULL; hDialogMsgHook = NULL; } // The hook failed, so return an error code return FALSE; }
DllExport BOOL SetHooks(DWORD thread_id, UINT UpdateMsg, UINT CopyMsg, UINT MouseMsg,BOOL ddihook) { // Don't add the hook if the thread id is NULL if (!thread_id) return FALSE; m_ddihook=ddihook; // Don't add a hook if there is already one added if (vnc_thread_id) return FALSE; // Add the CallWnd hook hCallWndHook = SetWindowsHookEx( WH_CALLWNDPROC, // Hook in before msg reaches app (HOOKPROC) CallWndProc, // Hook procedure hInstance, // This DLL instance 0L // Hook in to all apps // GetCurrentThreadId() // DEBUG : HOOK ONLY WinVNC ); // Add the GetMessage hook hGetMsgHook = SetWindowsHookEx( WH_GETMESSAGE, // Hook in before msg reaches app (HOOKPROC) GetMessageProc, // Hook procedure hInstance, // This DLL instance 0L // Hook in to all apps // GetCurrentThreadId() // DEBUG : HOOK ONLY WinVNC ); // Add the GetMessage hook hDialogMsgHook = SetWindowsHookEx( WH_SYSMSGFILTER, // Hook in dialogs, menus and scrollbars (HOOKPROC) DialogMessageProc, // Hook procedure hInstance, // This DLL instance 0L // Hook in to all apps ); // Check that it worked if ((hCallWndHook != NULL) && (hGetMsgHook != NULL) && (hDialogMsgHook != NULL)) { vnc_thread_id = thread_id; // Save the WinVNC thread id UpdateRectMessage = UpdateMsg; // Save the message ID to use for rectangle updates CopyRectMessage = CopyMsg; // Save the message ID to use for copyrect MouseMoveMessage = MouseMsg; // Save the message ID to send when mouse moves HookMaster = TRUE; // Set the HookMaster flag for this instance return TRUE; } else { // Stop the keyboard hook SetKeyboardFilterHook(FALSE); SetMouseFilterHook(FALSE); // Kill the main hooks if (hCallWndHook != NULL) UnhookWindowsHookEx(hCallWndHook); if (hGetMsgHook != NULL) UnhookWindowsHookEx(hGetMsgHook); if (hDialogMsgHook != NULL) UnhookWindowsHookEx(hDialogMsgHook); hCallWndHook = NULL; hGetMsgHook = NULL; hDialogMsgHook = NULL; } if (ddihook) { if (hCallWndHook != NULL) UnhookWindowsHookEx(hCallWndHook); if (hDialogMsgHook != NULL) UnhookWindowsHookEx(hDialogMsgHook); hCallWndHook = NULL; hDialogMsgHook = NULL; } // The hook failed, so return an error code return FALSE; }