コード例 #1
0
ファイル: desktop.c プロジェクト: hoangduit/reactos
void do_InitialDesktop_child(int i)
{
    HDESK hdesktop;
    HWINSTA hwinsta;
    WCHAR buffer[100];
    DWORD size;
    BOOL ret;

    if(TestResults[i].ExpectedWinsta == NULL)
    {
        trace("Process should have failed to initialize\n");
        return;
    }

    IsGUIThread(TRUE);

    hdesktop = GetThreadDesktop(GetCurrentThreadId());
    hwinsta = GetProcessWindowStation();

    ret = GetUserObjectInformationW( hwinsta, UOI_NAME, buffer, sizeof(buffer), &size );
    ok(ret == TRUE, "ret = %d\n", ret);
    ok(wcscmp(buffer, TestResults[i].ExpectedWinsta) == 0, "Wrong winsta %S insted of %S\n", buffer, TestResults[i].ExpectedWinsta);

    ret = GetUserObjectInformationW( hdesktop, UOI_NAME, buffer, sizeof(buffer), &size );
    ok(ret == TRUE, "ret = %d\n", ret);
    ok(wcscmp(buffer, TestResults[i].ExpectedDesktp) == 0, "Wrong desktop %S insted of %S\n", buffer, TestResults[i].ExpectedDesktp);
}
コード例 #2
0
ファイル: monitor.cpp プロジェクト: JayceM6/pcmonitor
VOID
	PrepareMainThread()
{
	PMONITOR Monitor = GetMonitor();
	HMODULE hModule = NULL;
	HWINSTA hWinsta = NULL;
	HDESK hDesk = NULL;
	PCLIENT_THREAD_SETUP ClientThreadSetup = NULL;

	hModule = LoadLibrary(L"user32.dll");
	if (hModule == NULL) {
		DebugPrint(L"LoadLibrary failed\n");
		return;
	}
	
	DebugPrint(L"IsGUIThread=%x\n", IsGUIThread(TRUE));

	ClientThreadSetup = (PCLIENT_THREAD_SETUP)GetProcAddress(hModule, "ClientThreadSetup");
	if (ClientThreadSetup == NULL) {
		DebugPrint(L"ClientThreadSetup not found in mod=%p\n", hModule);
		goto cleanup;
	}
	
	BOOL Result = ClientThreadSetup();
	DebugPrint(L"ClientThreadSetup=%x\n", Result);
	hWinsta = DeviceOpenWinsta(L"WinSta0");
	if (hWinsta != NULL) {
		hDesk = DeviceOpenDesktop(hWinsta, L"Default");
	}
	
	DebugPrint(L"Opened hwinsta=%p, hdesk=%p\n", hWinsta, hDesk);

	if (hWinsta != NULL) {
		if (!SetProcessWindowStation(hWinsta)) {
			DebugPrint(L"SetProcessWindowStation failed, err=%d, hWinsta=%x\n", GetLastError(), hWinsta);
		}
	}

	if (hDesk != NULL) {
		if (!SetThreadDesktop(hDesk)) {
			DebugPrint(L"SetThreadDesktop failed, error=%d\n", GetLastError());
		}
	}

	if (hDesk != NULL)
		CloseDesktop(hDesk);

	if (hWinsta != NULL)
		CloseWindowStation(hWinsta);
	
cleanup:	
	FreeLibrary(hModule);
}
コード例 #3
0
VOID UnloadDriver()
{
	if(CommDevice)
	{
		DWORD dwReturn;

		IsGUIThread(TRUE);

		if (0 == (DeviceIoControl(CommDevice, IO_UNHOOK_SYSTEM_SERVICES, NULL, 0, 
			NULL, 0, &dwReturn, NULL)))
		{
			int error = GetLastError();

			FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, 
				GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 
				0, NULL);

			MessageBox(NULL, (LPTSTR)lpMsgBuf, "GetLastError", MB_OK|MB_ICONINFORMATION);

			return;
		}
	}

	if(CommDevice)
	{
		CloseHandle(CommDevice);
	}

	if (bResult)
	{
		SERVICE_STATUS status;
		::ControlService(Driver, SERVICE_CONTROL_STOP, &status);

		::DeleteService(Driver);

		if (Driver != NULL)
		{
			::CloseServiceHandle(Driver);
			::CloseServiceHandle(SCManager);
			Driver = NULL;
		}
	}

	bResult = FALSE;
}
コード例 #4
0
VOID CMainDialog::OnHideWindowHandles()
{
	CHAR ProcessName[MAX_PATH];
	CEdit *pProcessName = (CEdit *)GetDlgItem(IDC_PROCESSNAME);
	CButton *pHideWindowHandlesButton = (CButton *)GetDlgItem(IDHIDEWINDOWHANDLES);
	CButton *pShowWindowHandlesButton = (CButton *)GetDlgItem(IDSHOWWINDOWHANDLES);

	pProcessName->GetWindowText(ProcessName, sizeof(ProcessName));
	strcat(ProcessName, ".exe");

	DWORD HiddenWindowHandleProcessId;
	LPVOID pHiddenWindowHandleProcessId = &HiddenWindowHandleProcessId;

	if(FALSE != (HiddenWindowHandleProcessId = GetProcessID(ProcessName)))
	{
		pHideWindowHandlesButton->EnableWindow(FALSE);
		pShowWindowHandlesButton->EnableWindow(TRUE);
	}
	else
	{
		MessageBox("Process Does Not Exist!", "Error", MB_ICONERROR);
		return;
	}

	if (DriverLoaded)
	{
		UnloadDriver();
		DriverLoaded = FALSE;
	}

	LoadDriver();
	DriverLoaded = TRUE;

	CommDevice = CreateFile("\\\\.\\ShadowTableHookDriver", GENERIC_READ | GENERIC_WRITE,
			0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
	
	if(CommDevice == INVALID_HANDLE_VALUE)
	{
		int error = GetLastError();

		FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, 
			GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 
			0, NULL);

		MessageBox((LPTSTR)lpMsgBuf, "GetLastError", MB_OK|MB_ICONINFORMATION);

		return;
	}

	if(CommDevice)
	{
		DWORD dwReturn;

		if (0 == (DeviceIoControl(CommDevice, IO_SEND_HIDDEN_PROCESS_ID, 
			pHiddenWindowHandleProcessId, sizeof(HiddenWindowHandleProcessId), 
			NULL, 0, &dwReturn, NULL)))
		{
			int error = GetLastError();

			FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, 
				GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 
				0, NULL);

			MessageBox((LPCSTR)lpMsgBuf, "GetLastError", MB_OK|MB_ICONINFORMATION);

			return;
		}
	}

	if(CommDevice)
	{
		DWORD dwReturn;

		IsGUIThread(TRUE);

		if (0 == (DeviceIoControl(CommDevice, IO_HOOK_SYSTEM_SERVICES, NULL, 0, 
			NULL, 0, &dwReturn, NULL)))
		{
			int error = GetLastError();

			FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, 
				GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 
				0, NULL);

			MessageBox((LPCSTR)lpMsgBuf, "GetLastError", MB_OK|MB_ICONINFORMATION);

			return;
		}
	}

}