Esempio n. 1
0
void StopWatcher(PHVNC lpServer)
{
    lpServer->WndWatcherInfo.bWatcherStarted=false;
    UnhookWinEvent(lpServer->WndWatcherInfo.hHook1);
    UnhookWinEvent(lpServer->WndWatcherInfo.hHook2);
    UnhookWinEvent(lpServer->WndWatcherInfo.hHook3);
    lpServer->WndWatcherInfo.bMessageBoxIsShown=false;
    return;
}
Esempio n. 2
0
/** Remove the global message hook */
BOOL VBoxHookRemoveWindowTracker()
{
    if (g_ahWinEventHook[0] && g_ahWinEventHook[1])
    {
        UnhookWinEvent(g_ahWinEventHook[0]);
        UnhookWinEvent(g_ahWinEventHook[1]);
        CoUninitialize();
    }
    g_ahWinEventHook[0] = g_ahWinEventHook[1] = 0;
    return TRUE;
}
EventHookManager::~EventHookManager()
{
	for (auto it = hooks.begin(); it != hooks.end(); ++it)
		if (it->second.winEventHook) UnhookWinEvent(it->second.winEventHook);

	hooks.clear();
}
Esempio n. 4
0
extern "C" int __declspec(dllexport) Unload(void)
{
	UninitIdleTimer();

	if (g_hWinHook != 0)
		UnhookWinEvent(g_hWinHook);

	DestroyServiceFunction(g_hHideService);

	if (g_hListenWindow)
	{
		WTSUnRegisterSessionNotification(g_hListenWindow);
		DestroyWindow(g_hListenWindow);
	}

	if (hDwmApi)
		FreeLibrary(hDwmApi);

	// free all sessions
	HWND_ITEM *pTemp = g_pMirWnds;
	while (pTemp != NULL)
	{
		HWND_ITEM *pNext = pTemp->next;
		delete pTemp;
		pTemp = pNext;
	}

	delete[] oldStatus;
	delete[] oldStatusMsg;

	return 0;
}
Esempio n. 5
0
BOOL VBoxHookRemoveActiveDesktopTracker()
{
    if (g_hDesktopEventHook)
    {
        UnhookWinEvent(g_hDesktopEventHook);
        CoUninitialize();
    }
    g_hDesktopEventHook = 0;
    return TRUE;
}
bool EventHookManager::RemoveHook(HWND const & targetWindow, UINT const & eventMin, UINT const & eventMax)
{
	// Check map for existing entry
	auto hash = std::hash<HWND>()(targetWindow) ^ std::hash<UINT>()(eventMin) ^ std::hash<UINT>()(eventMax);
	auto it = hooks.find(hash);
	if (it == hooks.end()) return false;

	// Erase
	if (it->second.winEventHook) UnhookWinEvent(it->second.winEventHook);
	auto erased = hooks.erase(hash);
	return erased == 1;
}
Esempio n. 7
0
// _____________________________________________________________________ //
//
// MAIN
// _____________________________________________________________________ //
int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd)
{
	// One instance is enough
	HANDLE hGlobalLock = CreateMutex(NULL, TRUE, L"RestoreWindowsMutex");
	if(hGlobalLock == INVALID_HANDLE_VALUE || GetLastError() == ERROR_ALREADY_EXISTS)
		return 0;

	const char* tok = 0;
	char* context = NULL;
	const char* delims = " =\t";
	tok = strtok_s(lpCmdLine, delims, &context);
	while(tok)
	{
		if(!_stricmp(tok, "--debuglog"))
		{
			_sopen_s(&logfile, "RestoreWindows.log", _O_WRONLY | _O_BINARY | _O_TRUNC | _O_CREAT, _SH_DENYNO, _S_IWRITE);
		}
		else if(!_stricmp(tok, "--delay"))
		{
			tok = strtok_s(0, delims, &context);
			if(tok)
				ResumeTimerValue = clamp(0, 1000*60*10, atoi(tok));
		}
		tok = strtok_s(0, delims, &context);
	}

	DesiredMonitorPlacements = GetAllMonitors();

	Log("Delay: %d\n\n", ResumeTimerValue);
	for(auto it = DesiredMonitorPlacements.begin(); it != DesiredMonitorPlacements.end(); ++it)
		Log("Monitor: %d, %d\n", it->right-it->left, it->bottom-it->top);
	 Log("\n");

	LoadAllWindowPlacements();

	HWINEVENTHOOK hWinEventHook = SetWinEventHook(EVENT_MIN, EVENT_MAX, NULL, WinEventProc, 0, 0, WINEVENT_OUTOFCONTEXT);
	DetectWindow = CreateDetectionWnd();

	MSG msg;
	while(GetMessage(&msg, NULL, 0, 0) > 0)
	{
		DispatchMessage(&msg);
	}

	// Usually never gets here...
	UnhookWinEvent(hWinEventHook);
	_close(logfile);
	CloseHandle(hGlobalLock);

	return 0;
}
Esempio n. 8
0
CParentWnd::~CParentWnd()
{
	// Since we didn't create a window, we can't call DestroyWindow to let MFC know we're done.
	// We call AfxPostQuitMessage instead
	TRACE_DESTRUCTOR(CLASS);
	UninitializeGDI();
	UnloadAddIns();
	if (m_hwinEventHook) UnhookWinEvent(m_hwinEventHook);
	UninitializeNamedPropCache();
	WriteToRegistry();
	CloseDebugFile();
	// Since we're killing what m_pMainWnd points to here, we need to clear it
	// Else MFC will try to route messages to it
	theApp.m_pMainWnd = NULL;
	AfxPostQuitMessage(0);
} // CParentWnd::~CParentWnd
Esempio n. 9
0
void unregister_running_hooks() {
	// Stop the event hook and any timer still running.
	if (win_event_hhook != NULL) {
		UnhookWinEvent(win_event_hhook);
		win_event_hhook = NULL;
	}

	// Destroy the native hooks.
	if (keyboard_event_hhook != NULL) {
		UnhookWindowsHookEx(keyboard_event_hhook);
		keyboard_event_hhook = NULL;
	}

	if (mouse_event_hhook != NULL) {
		UnhookWindowsHookEx(mouse_event_hhook);
		mouse_event_hhook = NULL;
	}
}
Esempio n. 10
0
UIOHOOK_API int hook_run(event_type _eventsToHook) {
	int status = UIOHOOK_FAILURE;
	eventsToHook = _eventsToHook;

	// Set the thread id we want to signal later.
	hook_thread_id = GetCurrentThreadId();

	// Spot check the hInst incase the library was statically linked and DllMain
	// did not receive a pointer on load.
	if (hInst == NULL) {
		logger(LOG_LEVEL_INFO,	"%s [%u]: hInst was not set by DllMain().\n",
				__FUNCTION__, __LINE__);

		HINSTANCE hInstPE = GetModuleHandle(NULL);

		if (hInstPE != NULL) {
			DllMain(hInstPE, DLL_PROCESS_ATTACH, NULL);
		}
		else {
			logger(LOG_LEVEL_ERROR,	"%s [%u]: Could not determine hInst for SetWindowsHookEx()! (%#lX)\n",
					__FUNCTION__, __LINE__, (unsigned long) GetLastError());

			status = FALSE;
		}
	}

	bool wantsAnyKeyEvents = wants_any_key_events(), wantsAnyMouseEvents = wants_any_mouse_events();
	if (!wantsAnyKeyEvents && !wantsAnyMouseEvents)
		return UIOHOOK_FAILURE;//...maybe?

	// Create the native hooks.
	if (wantsAnyKeyEvents)
		keyboard_event_hhook = SetWindowsHookEx(WH_KEYBOARD_LL, keyboard_hook_event_proc, hInst, 0);
	if (wantsAnyMouseEvents)
		mouse_event_hhook = SetWindowsHookEx(WH_MOUSE_LL, mouse_hook_event_proc, hInst, 0);

	// Create a window event hook to listen for capture change.
	win_event_hhook = SetWinEventHook(
			EVENT_OBJECT_NAMECHANGE, EVENT_OBJECT_NAMECHANGE, 
			NULL, 
			win_hook_event_proc, 
			0, 0, 
			WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);

	bool success = true;
	if (wantsAnyKeyEvents && keyboard_event_hhook == NULL)
		success = false;

	if (wantsAnyMouseEvents && mouse_event_hhook == NULL)
		success = false;

	// If we did not encounter a problem, start processing events.
	if ( success ) {
		if (win_event_hhook == NULL) {
			logger(LOG_LEVEL_WARN,	"%s [%u]: SetWinEventHook() failed!\n",
					__FUNCTION__, __LINE__);
		}

		logger(LOG_LEVEL_DEBUG,	"%s [%u]: SetWindowsHookEx() successful.\n",
				__FUNCTION__, __LINE__);

		// Check and setup modifiers.
		initialize_modifiers();

		// Set the exit status.
		status = UIOHOOK_SUCCESS;

		// Windows does not have a hook start event or callback so we need to
		// manually fake it.
		hook_start_proc();

		// Block until the thread receives an WM_QUIT request.
		MSG message;
		while (GetMessage(&message, (HWND) NULL, 0, 0) > 0) {
			TranslateMessage(&message);
			DispatchMessage(&message);
		}
	}
	else {
		logger(LOG_LEVEL_ERROR,	"%s [%u]: SetWindowsHookEx() failed! (%#lX)\n",
				__FUNCTION__, __LINE__, (unsigned long) GetLastError());

		status = UIOHOOK_ERROR_SET_WINDOWS_HOOK_EX;
	}
	
	
	// Stop the event hook and any timer still running.
	if (win_event_hhook != NULL) {
		UnhookWinEvent(win_event_hhook);
		win_event_hhook = NULL;
	}

	// Destroy the native hooks.
	if (keyboard_event_hhook != NULL) {
		UnhookWindowsHookEx(keyboard_event_hhook);
		keyboard_event_hhook = NULL;
	}

	if (mouse_event_hhook != NULL) {
		UnhookWindowsHookEx(mouse_event_hhook);
		mouse_event_hhook = NULL;
	}

	// We must explicitly call the cleanup handler because Windows does not
	// provide a thread cleanup method like POSIX pthread_cleanup_push/pop.
	hook_stop_proc();

	return status;
}
void EventHookHandler::UnregisterHook(HWINEVENTHOOK hook)
{
	if (hook)
		UnhookWinEvent(hook);
}
Esempio n. 12
0
		void uninstallHooks()
		{
			UnhookWinEvent(g_compatGdiCaretLocationChangeEventHook);
			UnhookWinEvent(g_compatGdiCaretGeneralEventHook);
		}
Esempio n. 13
0
void AccessibleObject::Unhook() {
  if (win_event_hook_ != nullptr) {
    UnhookWinEvent(win_event_hook_);
    win_event_hook_ = nullptr;
  }
}
void Unhook() {
	if (LHook == 0) return;
	UnhookWinEvent(LHook);
	CoUninitialize();
}