diff options
| author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2014-03-26 19:21:20 +0000 |
|---|---|---|
| committer | <> | 2014-05-08 15:03:54 +0000 |
| commit | fb123f93f9f5ce42c8e5785d2f8e0edaf951740e (patch) | |
| tree | c2103d76aec5f1f10892cd1d3a38e24f665ae5db /src/VBox/Additions/WINNT/VBoxMMR | |
| parent | 58ed4748338f9466599adfc8a9171280ed99e23f (diff) | |
| download | VirtualBox-master.tar.gz | |
Imported from /home/lorry/working-area/delta_VirtualBox/VirtualBox-4.3.10.tar.bz2.HEADVirtualBox-4.3.10master
Diffstat (limited to 'src/VBox/Additions/WINNT/VBoxMMR')
| -rw-r--r-- | src/VBox/Additions/WINNT/VBoxMMR/Makefile.kmk | 30 | ||||
| -rw-r--r-- | src/VBox/Additions/WINNT/VBoxMMR/VBoxMMR.rc | 50 | ||||
| -rw-r--r-- | src/VBox/Additions/WINNT/VBoxMMR/VBoxMMRHook.rc | 50 | ||||
| -rw-r--r-- | src/VBox/Additions/WINNT/VBoxMMR/dllmain.cpp | 4 | ||||
| -rw-r--r-- | src/VBox/Additions/WINNT/VBoxMMR/startmmr.cpp | 28 | ||||
| -rw-r--r-- | src/VBox/Additions/WINNT/VBoxMMR/tsmfhook.cpp | 392 | ||||
| -rw-r--r-- | src/VBox/Additions/WINNT/VBoxMMR/tsmfhook.h | 14 |
7 files changed, 345 insertions, 223 deletions
diff --git a/src/VBox/Additions/WINNT/VBoxMMR/Makefile.kmk b/src/VBox/Additions/WINNT/VBoxMMR/Makefile.kmk index 0e019ef4..30641ef9 100644 --- a/src/VBox/Additions/WINNT/VBoxMMR/Makefile.kmk +++ b/src/VBox/Additions/WINNT/VBoxMMR/Makefile.kmk @@ -4,7 +4,7 @@ # # -# Copyright (C) 2012 Oracle Corporation +# Copyright (C) 2012-2013 Oracle Corporation # # This file is part of VirtualBox Open Source Edition (OSE), as # available from http://www.virtualbox.org. This file is free software; @@ -21,18 +21,20 @@ include $(KBUILD_PATH)/subheader.kmk PROGRAMS += VBoxMMR VBoxMMR_TEMPLATE = NewVBoxGuestR3Exe VBoxMMR_DEFS = LOG_TO_BACKDOOR VBOX_WITH_HGCM -VBoxMMR_SOURCES = startmmr.cpp +VBoxMMR_SOURCES = \ + VBoxMMR.rc \ + startmmr.cpp DLLS += VBoxMMRHook VBoxMMRHook_TEMPLATE = VBOXGUESTR3DLL VBoxMMRHook_DEFS = LOG_TO_BACKDOOR VBGL_VBOXGUEST VBOX_WITH_HGCM UNICODE TSMFHOOK_EXPORTS VBOX_WITH_GUEST_PROPS -VBoxMMRHook_SDKS.x86 = WINDDK VBoxMMRHook_SOURCES = \ - VBoxMMRHook.def \ - dllmain.cpp \ - tsmfhook.cpp \ - logging.cpp + VBoxMMRHook.rc \ + VBoxMMRHook.def \ + dllmain.cpp \ + tsmfhook.cpp \ + logging.cpp # # 32-bit versions for inclusion on 64-bit Windows @@ -57,14 +59,16 @@ VBoxMMRHook-x86_DEFS = $(VBoxMMRHook_DEFS) VBOX_WOW64 # # Since this is not the default SDK we have to navigate manually to it. # -VBOX_PATH_PSDK_v71 := \ - $(PATH_DEVTOOLS)/win.x86/sdk/v7.1 +ifndef VBOX_OSE + VBOX_PATH_PSDK_v71 := $(PATH_DEVTOOLS)/win.x86/sdk/v7.1 +else + VBOX_PATH_PSDK_v71 := $(PATH_SDK_WINPSDK71) +endif -VBoxMMRHook_INCS := \ +VBoxMMRHook_INCS := \ $(VBOX_PATH_PSDK_v71)/Include \ - ../include \ - $(SUB_DEPTH)/include - + ../include \ + $(SUB_DEPTH)/include VBoxMMRHook_LIBS.x86 := \ $(VBOX_PATH_PSDK_v71)/Lib/WS2_32.lib diff --git a/src/VBox/Additions/WINNT/VBoxMMR/VBoxMMR.rc b/src/VBox/Additions/WINNT/VBoxMMR/VBoxMMR.rc new file mode 100644 index 00000000..4e3f9681 --- /dev/null +++ b/src/VBox/Additions/WINNT/VBoxMMR/VBoxMMR.rc @@ -0,0 +1,50 @@ +/* $Id: VBoxMMR.rc $ */ +/** @file + * VBoxMMR - Resource file containing version info. + */ + +/* + * Copyright (C) 2012 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#include <windows.h> +#include <VBox/version.h> + +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +VS_VERSION_INFO VERSIONINFO + FILEVERSION VBOX_VERSION_MAJOR_NR,VBOX_VERSION_MINOR_NR,VBOX_VERSION_BUILD_NR,0 + PRODUCTVERSION VBOX_VERSION_MAJOR_NR,VBOX_VERSION_MINOR_NR,VBOX_VERSION_BUILD_NR,0 + FILEFLAGSMASK 0x3fL + FILEFLAGS 0x0L + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", VBOX_RC_COMPANY_NAME + VALUE "FileDescription", "VirtualBox Guest Additions Multimedia Redirection Application\0" + VALUE "FileVersion", VBOX_VERSION_MAJOR "." VBOX_VERSION_MINOR "." VBOX_VERSION_BUILD "." VBOX_SVN_REV "\0" + VALUE "InternalName", "VBoxMMR\0" + VALUE "LegalCopyright", VBOX_RC_LEGAL_COPYRIGHT + VALUE "OriginalFilename", "VBoxMMR.exe\0" + VALUE "ProductName", VBOX_PRODUCT " Guest Additions\0" + VALUE "ProductVersion", VBOX_VERSION_MAJOR "." VBOX_VERSION_MINOR "." VBOX_VERSION_BUILD ".r" VBOX_SVN_REV "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END diff --git a/src/VBox/Additions/WINNT/VBoxMMR/VBoxMMRHook.rc b/src/VBox/Additions/WINNT/VBoxMMR/VBoxMMRHook.rc new file mode 100644 index 00000000..badf1d59 --- /dev/null +++ b/src/VBox/Additions/WINNT/VBoxMMR/VBoxMMRHook.rc @@ -0,0 +1,50 @@ +/* $Id: VBoxMMRHook.rc $ */ +/** @file + * VBoxMMRHook - Resource file containing version info. + */ + +/* + * Copyright (C) 2013 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + */ + +#include <windows.h> +#include <VBox/version.h> + +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +VS_VERSION_INFO VERSIONINFO + FILEVERSION VBOX_VERSION_MAJOR_NR,VBOX_VERSION_MINOR_NR,VBOX_VERSION_BUILD_NR,0 + PRODUCTVERSION VBOX_VERSION_MAJOR_NR,VBOX_VERSION_MINOR_NR,VBOX_VERSION_BUILD_NR,0 + FILEFLAGSMASK 0x3fL + FILEFLAGS 0x0L + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", VBOX_RC_COMPANY_NAME + VALUE "FileDescription", "VirtualBox Guest Additions Multimedia Redirection Hook\0" + VALUE "FileVersion", VBOX_VERSION_MAJOR "." VBOX_VERSION_MINOR "." VBOX_VERSION_BUILD "." VBOX_SVN_REV "\0" + VALUE "InternalName", "VBoxMMRHook\0" + VALUE "LegalCopyright", VBOX_RC_LEGAL_COPYRIGHT + VALUE "OriginalFilename", "VBoxMMRHook.dll\0" + VALUE "ProductName", VBOX_PRODUCT " Guest Additions\0" + VALUE "ProductVersion", VBOX_VERSION_MAJOR "." VBOX_VERSION_MINOR "." VBOX_VERSION_BUILD ".r" VBOX_SVN_REV "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END diff --git a/src/VBox/Additions/WINNT/VBoxMMR/dllmain.cpp b/src/VBox/Additions/WINNT/VBoxMMR/dllmain.cpp index 590199d9..0898ef03 100644 --- a/src/VBox/Additions/WINNT/VBoxMMR/dllmain.cpp +++ b/src/VBox/Additions/WINNT/VBoxMMR/dllmain.cpp @@ -41,10 +41,10 @@ BOOL APIENTRY DllMain( HMODULE hModule, GetModuleFileNameA(NULL, buffer, sizeof(buffer)); const PCHAR pc = strrchr(buffer, '\\'); isWMP = (0 == strcmp(pc + 1, "wmplayer.exe")); - + if (isWMP) { - RTR3InitDll(0); + RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE); VbglR3Init(); VBoxMMRHookLog("VBoxMMR: Hooking wmplayer process\n"); } diff --git a/src/VBox/Additions/WINNT/VBoxMMR/startmmr.cpp b/src/VBox/Additions/WINNT/VBoxMMR/startmmr.cpp index 4583081e..24133867 100644 --- a/src/VBox/Additions/WINNT/VBoxMMR/startmmr.cpp +++ b/src/VBox/Additions/WINNT/VBoxMMR/startmmr.cpp @@ -23,9 +23,7 @@ #include <VBox/Log.h> #include <VBox/VBoxGuestLib.h> -#include <VBox/HostServices/VBoxHostChannel.h> -const char *g_pszVRDETSMF = "/vrde/tsmf"; const char *g_pszMMRDLL = "VBoxMMRHook"; const char *g_pszMMRPROC = "CBTProc"; const WCHAR *g_pwszMMRFlags = L"VBoxMMR"; @@ -69,30 +67,6 @@ BOOL MMRIsEnabled() return fEnabled; } -BOOL TSMFIsAvailable() -{ - uint32_t u32HGCMClientId = 0; - int rc = VbglR3HostChannelInit(&u32HGCMClientId); - - if (RT_SUCCESS(rc)) - { - uint32_t u32Size = 0; - - rc = VbglR3HostChannelQuery(g_pszVRDETSMF, u32HGCMClientId, - VBOX_HOST_CHANNEL_CTRL_EXISTS, NULL, 0, NULL, 0, &u32Size); - - VbglR3HostChannelTerm(u32HGCMClientId); - } - - if (!RT_SUCCESS(rc)) - { - LogRel(("VBoxMMR: TSMF HGCM unavailable: hgcmid: %d, rc: %d\n", - u32HGCMClientId, rc)); - } - - return RT_SUCCESS(rc); -} - BOOL CtrlHandler(DWORD type) { SetEvent(g_hCtrlEvent); @@ -123,7 +97,7 @@ int APIENTRY WinMain( return rc; } - if (MMRIsEnabled() && TSMFIsAvailable()) + if (MMRIsEnabled()) { hMod = LoadLibraryA(g_pszMMRDLL); if (hMod == NULL) diff --git a/src/VBox/Additions/WINNT/VBoxMMR/tsmfhook.cpp b/src/VBox/Additions/WINNT/VBoxMMR/tsmfhook.cpp index 6fe890de..f5f875d2 100644 --- a/src/VBox/Additions/WINNT/VBoxMMR/tsmfhook.cpp +++ b/src/VBox/Additions/WINNT/VBoxMMR/tsmfhook.cpp @@ -48,6 +48,8 @@ const WCHAR *g_pwszMMRFlags = L"VBoxMMR"; const WCHAR *g_pwszMMRAdditions = L"SOFTWARE\\Oracle\\VirtualBox Guest Additions"; +const char *g_pszVRDETSMF = "/vrde/tsmf"; + const DWORD g_dwMMRCodeCavingEnabled = 0x00000002; BOOL g_bMMRCodeCavingIsEnabled = TRUE; @@ -94,8 +96,6 @@ uint32_t nUserData = 1; HANDLE ghVBoxDriver = NULL; -typedef HRESULT (*g_pMFShutdown)(void); - using std::map; using std::list; using std::queue; @@ -299,6 +299,11 @@ public: return false; } + static uint32_t ChannelCount() + { + return ChannelList.size(); + } + DWORD GetId() { return m_Id; } static VBOX_RDP_CHANNEL * GetFromId(DWORD Id) @@ -521,6 +526,131 @@ void InstallHooks(const IMAGE_IMPORT_DESCRIPTOR *pDescriptor, const PBYTE pBaseA } } +int StartMonitor(RTTHREAD *hMonitor, PFNRTTHREAD pMonitorFn, + void *pData, size_t cbStack, RTTHREADTYPE enmType, + uint32_t flags, const char *pszName) +{ + int rc; + + rc = RTThreadCreate(hMonitor, pMonitorFn, pData, + cbStack, enmType, flags, pszName); + + if (RT_FAILURE(rc)) + { + VBoxMMRHookLog("VBoxMMR: Error starting monitor %s: %d\n", pszName, rc); + } + + return rc; +} + +int StopMonitor(RTTHREAD *hMonitor, const char* pszName) +{ + int rc; + + if (*hMonitor != NIL_RTTHREAD) + { + rc = RTThreadUserSignal(*hMonitor); + + if (RT_SUCCESS(rc)) + { + // rc = RTThreadWait(*hMonitor, RT_INDEFINITE_WAIT, NULL); + + if (RT_FAILURE(rc)) + { + VBoxMMRHookLog("VBoxMMR: Error waiting for monitor %s to stop: %d\n", pszName, rc); + } + } + else + { + VBoxMMRHookLog("VBoxMMR: Error sending stop signal to monitor %s: %d\n", pszName, rc); + } + + *hMonitor = NIL_RTTHREAD; + } + + + return rc; +} + +DECLCALLBACK(int) +MonitorDetach(RTTHREAD hThreadSelf, void *pvUser) +{ + VBoxGuestFilterMaskInfo maskInfo; + DWORD cbReturned; + bool bPrevious = FALSE; + bool bCurrent = bPrevious; + + maskInfo.u32OrMask = VMMDEV_EVENT_VRDP; + maskInfo.u32NotMask = 0; + + VBoxMMRHookLog("VBoxMMR: MonitorDetach starting\n"); + + if (DeviceIoControl (ghVBoxDriver, VBOXGUEST_IOCTL_CTL_FILTER_MASK, &maskInfo, sizeof (maskInfo), NULL, 0, &cbReturned, NULL)) + { + VBoxMMRHookLog("VBoxTray: VBoxVRDPThread: DeviceIOControl(CtlMask - or) succeeded\n"); + } + else + { + VBoxMMRHookLog("VBoxTray: VBoxVRDPThread: DeviceIOControl(CtlMask) failed\n"); + return 0; + } + + for(;;) + { + /* Call the host to get VRDP status and the experience level. */ + VMMDevVRDPChangeRequest vrdpChangeRequest = {0}; + + vrdpChangeRequest.header.size = sizeof(VMMDevVRDPChangeRequest); + vrdpChangeRequest.header.version = VMMDEV_REQUEST_HEADER_VERSION; + vrdpChangeRequest.header.requestType = VMMDevReq_GetVRDPChangeRequest; + vrdpChangeRequest.u8VRDPActive = 0; + vrdpChangeRequest.u32VRDPExperienceLevel = 0; + + if (DeviceIoControl (ghVBoxDriver, + VBOXGUEST_IOCTL_VMMREQUEST(sizeof(VMMDevVRDPChangeRequest)), + &vrdpChangeRequest, + sizeof(VMMDevVRDPChangeRequest), + &vrdpChangeRequest, + sizeof(VMMDevVRDPChangeRequest), + &cbReturned, NULL)) + { + bCurrent = ( vrdpChangeRequest.u8VRDPActive == 1) ? TRUE : FALSE; + + if (bCurrent != bPrevious) + { + VBoxMMRHookLog( + "VBoxMMR: VRDP active status changed: %d\n", + vrdpChangeRequest.u8VRDPActive); + + if (bCurrent == FALSE && + VBOX_RDP_CHANNEL::ChannelCount() > 0) + { + VBoxMMRHookLog("VBoxMMR: exiting ...\n"); + ExitProcess(0); + break; + } + } + + bPrevious = bCurrent; + } + else + { + VBoxMMRHookLog("VBoxMMR: VBoxVRDPThread: Error from DeviceIoControl VBOXGUEST_IOCTL_VMMREQUEST\n"); + + } + + if (RTThreadUserWait(hThreadSelf, 1000) == VINF_SUCCESS) + { + VBoxMMRHookLog("VBoxMMR: detach monitor received stop signal\n"); + break; + } + } + + VBoxMMRHookLog("VBoxMMR: MonitorDetach stopping\n"); + + return VINF_SUCCESS; +} + /* * WTSQuerySessionInformationW */ @@ -782,11 +912,22 @@ HANDLE WINAPI MMRWinStationVirtualOpenEx(HANDLE hServer, DWORD hSession, LPSTR p if (RT_SUCCESS(rc)) { - WaitForSingleObject(hCreateEvent, INFINITE); + WaitForSingleObject(hCreateEvent, 5000); if (g_nCreateResult == VBOX_TSMF_HCH_CREATE_ACCEPTED) { h = new VBOX_RDP_CHANNEL(u32ChannelHandle); + + if (hDetachMonitor == NIL_RTTHREAD) + { + StartMonitor(&hDetachMonitor, MonitorDetach, + &nUserData, 0, RTTHREADTYPE_INFREQUENT_POLLER, + RTTHREADFLAGS_WAITABLE, "mmrpoll"); + } + } + else + { + VBoxMMRHookLog("VBoxMMR: Unable to open channel: %d\n", g_nCreateResult); } } else @@ -979,21 +1120,22 @@ FARPROC WINAPI MMRGetProcAddress(HMODULE hModule, LPCSTR lpProcName) CHAR szDllName[512]; if (FALSE == GetModuleFileNameA(hModule, szDllName, sizeof(szDllName))) + { szDllName[0] = '\0'; - + } } - else - if (0 == strcmp(lpProcName, "WTSQuerySessionInformationW")) - { - g_pfnWTSQuerySessionInformation = (BOOL (__stdcall *)(HANDLE,DWORD,WTS_INFO_CLASS,LPWSTR *,DWORD *)) ret; - ret = (FARPROC) LocalWTSQuerySessionInformation; + else if (0 == strcmp(lpProcName, "WTSQuerySessionInformationW")) + { + g_pfnWTSQuerySessionInformation = (BOOL (__stdcall *)(HANDLE,DWORD,WTS_INFO_CLASS,LPWSTR *,DWORD *)) ret; + ret = (FARPROC) LocalWTSQuerySessionInformation; CHAR szDllName[512]; if (FALSE == GetModuleFileNameA(hModule, szDllName, sizeof(szDllName))) + { szDllName[0] = '\0'; - } + } } return ret; @@ -1077,131 +1219,6 @@ static void VBoxMMRCloseBaseDriver(void) } } -DECLCALLBACK(int) -MonitorDetach(RTTHREAD hThreadSelf, void *pvUser) -{ - VBoxGuestFilterMaskInfo maskInfo; - DWORD cbReturned; - bool bPrevious = TRUE; - bool bCurrent = TRUE; - - maskInfo.u32OrMask = VMMDEV_EVENT_VRDP; - maskInfo.u32NotMask = 0; - - VBoxMMRHookLog("VBoxMMR: MonitorDetach starting\n"); - - if (DeviceIoControl (ghVBoxDriver, VBOXGUEST_IOCTL_CTL_FILTER_MASK, &maskInfo, sizeof (maskInfo), NULL, 0, &cbReturned, NULL)) - { - VBoxMMRHookLog("VBoxTray: VBoxVRDPThread: DeviceIOControl(CtlMask - or) succeeded\n"); - } - else - { - VBoxMMRHookLog("VBoxTray: VBoxVRDPThread: DeviceIOControl(CtlMask) failed\n"); - return 0; - } - - g_pMFShutdown ret = (g_pMFShutdown)GetProcAddress(GetModuleHandle(TEXT("Mfplat.dll")),"MFShutdown"); - - - for(;;) - { - /* Call the host to get VRDP status and the experience level. */ - VMMDevVRDPChangeRequest vrdpChangeRequest = {0}; - - vrdpChangeRequest.header.size = sizeof(VMMDevVRDPChangeRequest); - vrdpChangeRequest.header.version = VMMDEV_REQUEST_HEADER_VERSION; - vrdpChangeRequest.header.requestType = VMMDevReq_GetVRDPChangeRequest; - vrdpChangeRequest.u8VRDPActive = 0; - vrdpChangeRequest.u32VRDPExperienceLevel = 0; - - if (DeviceIoControl (ghVBoxDriver, - VBOXGUEST_IOCTL_VMMREQUEST(sizeof(VMMDevVRDPChangeRequest)), - &vrdpChangeRequest, - sizeof(VMMDevVRDPChangeRequest), - &vrdpChangeRequest, - sizeof(VMMDevVRDPChangeRequest), - &cbReturned, NULL)) - { - VBoxMMRHookLog("VBoxMMR: VBoxVRDPThread: u8VRDPActive = %d, level %d\n", vrdpChangeRequest.u8VRDPActive, vrdpChangeRequest.u32VRDPExperienceLevel); - bCurrent = ( vrdpChangeRequest.u8VRDPActive == 1) ? TRUE : FALSE; - if (bCurrent != bPrevious && bCurrent == FALSE) - { - HWND hWnd = FindWindow(L"WMPlayerApp", NULL); - if (hWnd != NULL) - { - VBoxMMRHookLog("VBoxMMR: PostMessage close\n"); - PostMessage(hWnd, WM_COMMAND, (WPARAM) 84345 , NULL); - //g_pMFShutdown(); - - } - } - bPrevious = bCurrent; - - } - else - { - VBoxMMRHookLog("VBoxMMR: VBoxVRDPThread: Error from DeviceIoControl VBOXGUEST_IOCTL_VMMREQUEST\n"); - - } - - if (RTThreadUserWait(hThreadSelf, 1000) == VINF_SUCCESS) - { - VBoxMMRHookLog("VBoxMMR: detach monitor received stop signal\n"); - break; - } - } - - VBoxMMRHookLog("VBoxMMR: MonitorDetach stopping\n"); - - return VINF_SUCCESS; -} - -int StartMonitor(RTTHREAD hMonitor, PFNRTTHREAD pMonitorFn, - void *pData, size_t cbStack, RTTHREADTYPE enmType, - uint32_t flags, const char *pszName) -{ - int rc; - - rc = RTThreadCreate(&hMonitor, pMonitorFn, pData, - cbStack, enmType, flags, pszName); - - if (RT_FAILURE(rc)) - { - VBoxMMRHookLog("VBoxMMR: Error starting monitor %s: %d\n", pszName, rc); - } - - return rc; -} - -int StopMonitor(RTTHREAD hMonitor, const char* pszName) -{ - int rc; - - if (hMonitor != NIL_RTTHREAD) - { - rc = RTThreadUserSignal(hMonitor); - - if (RT_SUCCESS(rc)) - { - // rc = RTThreadWait(hMonitor, RT_INDEFINITE_WAIT, NULL); - - if (RT_FAILURE(rc)) - { - VBoxMMRHookLog("VBoxMMR: Error waiting for monitor %s to stop: %d\n", pszName, rc); - } - } - else - { - VBoxMMRHookLog("VBoxMMR: Error sending stop signal to monitor %s: %d\n", pszName, rc); - } - - hMonitor = NIL_RTTHREAD; - } - - - return rc; -} - void ReadTSMF(uint32_t u32ChannelHandle, uint32_t u32HGCMClientId, uint32_t u32SizeAvailable) { @@ -1325,19 +1342,29 @@ MonitorTSMFChannel(RTTHREAD hThreadSelf, void *pvUser) return VINF_SUCCESS; } -void InstallHooksForModule(const char *pszName, HookEntry hooks[]) +void InstallHooksForSystemModule(const char *pszName, HookEntry hooks[]) { - HMODULE hMod = LoadLibraryA(pszName); - if (hMod != NULL) + /* Construct the full path to the given module and load it. */ + char szPath[MAX_PATH]; + UINT cchPath = GetSystemDirectoryA(szPath, MAX_PATH); + size_t cbName = strlen(pszName) + 1; + if (cchPath + 1 + cbName <= sizeof(szPath)) { - VBoxMMRHookLog("VBoxMMR: Hooking %s -> %x \n", pszName, hMod); - const IMAGE_IMPORT_DESCRIPTOR *pDescriptor = GetImportDescriptor(hMod); - InstallHooks(pDescriptor, (PBYTE) hMod, hooks); + szPath[cchPath] = '\\'; + memcpy(&szPath[cchPath + 1], pszName, cbName); + + HMODULE hMod = LoadLibraryA(szPath); + if (hMod != NULL) + { + VBoxMMRHookLog("VBoxMMR: Hooking %s -> %x \n", pszName, hMod); + const IMAGE_IMPORT_DESCRIPTOR *pDescriptor = GetImportDescriptor(hMod); + InstallHooks(pDescriptor, (PBYTE) hMod, hooks); + } + else + VBoxMMRHookLog("VBoxMMR: Error hooking %s -> not found (last error %u)\n", pszName, GetLastError()); } else - { VBoxMMRHookLog("VBoxMMR: Error hooking %s -> not found\n", pszName); - } } TSMFHOOK_API LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam) @@ -1352,17 +1379,24 @@ TSMFHOOK_API LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam) VBoxMMRHookLog("VBoxMMR: WMP APIs Hooking started ...\n"); - InstallHooksForModule("winmm.dll", g_WinMMHooks); - InstallHooksForModule("tsmf.dll", g_TSMFHooks); - InstallHooksForModule("DSHOWRDPFILTER.dll", g_TSMFHooks); - InstallHooksForModule("MSMPEG2VDEC.dll", g_DShowHooks); - InstallHooksForModule("MFDS.dll", g_DShowHooks); - InstallHooksForModule("mf.dll", g_MFHooks); - HMODULE hMod = GetModuleHandleA("wmp"); - VBoxMMRHookLog("VBoxMMR: Hooking wmp -> %x \n",hMod); - const IMAGE_IMPORT_DESCRIPTOR *pDescriptor = GetImportDescriptor(hMod); - InstallHooks(pDescriptor, (PBYTE) hMod, g_WMPHooks); + if (hMod != NULL) + { + VBoxMMRHookLog("VBoxMMR: Hooking wmp -> %x \n",hMod); + const IMAGE_IMPORT_DESCRIPTOR *pDescriptor = GetImportDescriptor(hMod); + InstallHooks(pDescriptor, (PBYTE) hMod, g_WMPHooks); + } + else + { + VBoxMMRHookLog("VBoxMMR: Error hooking wmp -> not found\n"); + } + + InstallHooksForSystemModule("winmm.dll", g_WinMMHooks); + InstallHooksForSystemModule("tsmf.dll", g_TSMFHooks); + InstallHooksForSystemModule("DSHOWRDPFILTER.dll", g_TSMFHooks); + InstallHooksForSystemModule("MSMPEG2VDEC.dll", g_DShowHooks); + InstallHooksForSystemModule("MFDS.dll", g_DShowHooks); + InstallHooksForSystemModule("mf.dll", g_MFHooks); ULONG ret = RegisterTraceGuids( ControlCallback, NULL, &ProviderId, 0, @@ -1373,36 +1407,45 @@ TSMFHOOK_API LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam) VBoxMMRHookLog("VBoxMMR: RegisterTraceGuids failed with error code: %u\n", GetLastError()); } - int rc = VBoxMMROpenBaseDriver(); - - if (RT_SUCCESS(rc)) - { - StartMonitor(hDetachMonitor, MonitorDetach, - &nUserData, 0, RTTHREADTYPE_INFREQUENT_POLLER, - RTTHREADFLAGS_WAITABLE, "mmrpoll"); - } - bool bInRDPSession = (1 == GetSystemMetrics(0x1000)); if (!bInRDPSession) { uint32_t u32HGCMClientId = 0; - rc = VbglR3HostChannelInit(&u32HGCMClientId); + int rc = VbglR3HostChannelInit(&u32HGCMClientId); if (RT_SUCCESS(rc)) { - hCreateEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - InitializeCriticalSection(&CreateLock); + uint32_t u32Size = 0; - g_HostChannelCtx.thread = NIL_RTTHREAD; - g_HostChannelCtx.u32HGCMClientId = u32HGCMClientId; + rc = VbglR3HostChannelQuery(g_pszVRDETSMF, u32HGCMClientId, + VBOX_HOST_CHANNEL_CTRL_EXISTS, NULL, 0, NULL, 0, &u32Size); - StartMonitor( - g_HostChannelCtx.thread, MonitorTSMFChannel, - &g_HostChannelCtx, 64*_1K, - RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, - "tsmfio"); + if (RT_SUCCESS(rc)) + { + hCreateEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + InitializeCriticalSection(&CreateLock); + + g_HostChannelCtx.thread = NIL_RTTHREAD; + g_HostChannelCtx.u32HGCMClientId = u32HGCMClientId; + + StartMonitor( + &g_HostChannelCtx.thread, MonitorTSMFChannel, + &g_HostChannelCtx, 64*_1K, + RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, + "tsmfio"); + + VBoxMMROpenBaseDriver(); + } + else + { + VBoxMMRHookLog( + "VBoxMMR: TSMF HGCM unavailable: hgcmid: %d, rc: %d\n", + u32HGCMClientId, rc); + + VbglR3HostChannelTerm(u32HGCMClientId); + } } else { @@ -1420,13 +1463,14 @@ void Shutdown() { VBoxMMRHookLog("VBoxMMR: Shutdown\n"); - StopMonitor(hDetachMonitor, "mmrpoll"); + StopMonitor(&hDetachMonitor, "mmrpoll"); VBoxMMRCloseBaseDriver(); if (g_HostChannelCtx.u32HGCMClientId != 0) { g_HostChannelCtx.fShutdown = true; - StopMonitor(g_HostChannelCtx.thread, "tsmfio"); + VbglR3HostChannelEventCancel(0, g_HostChannelCtx.u32HGCMClientId); + StopMonitor(&g_HostChannelCtx.thread, "tsmfio"); VbglR3HostChannelTerm(g_HostChannelCtx.u32HGCMClientId); } diff --git a/src/VBox/Additions/WINNT/VBoxMMR/tsmfhook.h b/src/VBox/Additions/WINNT/VBoxMMR/tsmfhook.h index 0443a322..109576b6 100644 --- a/src/VBox/Additions/WINNT/VBoxMMR/tsmfhook.h +++ b/src/VBox/Additions/WINNT/VBoxMMR/tsmfhook.h @@ -17,10 +17,10 @@ #pragma once -// The following ifdef block is the standard way of creating macros which make exporting +// The following ifdef block is the standard way of creating macros which make exporting // from a DLL simpler. All files within this DLL are compiled with the TSMFHOOK_EXPORTS // symbol defined on the command line. This symbol should not be defined on any project -// that uses this DLL. This way any other project whose source files include this file see +// that uses this DLL. This way any other project whose source files include this file see // TSMFHOOK_API functions as being imported from a DLL, whereas this DLL sees symbols // defined with this macro as being exported. #ifdef TSMFHOOK_EXPORTS @@ -34,23 +34,23 @@ extern "C" TSMFHOOK_API LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARA void Shutdown(); // {56E95534-F42E-4C79-8EED-B121B4823163} -static const GUID ProviderId = +static const GUID ProviderId = { 0x56e95534, 0xf42e, 0x4c79, { 0x8e, 0xed, 0xb1, 0x21, 0xb4, 0x82, 0x31, 0x63 } }; // {06797744-5A74-4782-B2AB-B86D9F6C7B4A} -static const GUID ChannelOpenCategoryId = +static const GUID ChannelOpenCategoryId = { 0x6797744, 0x5a74, 0x4782, { 0xb2, 0xab, 0xb8, 0x6d, 0x9f, 0x6c, 0x7b, 0x4a } }; // {BF94ED39-9585-4822-B69E-DF19549A664C} -static const GUID ChannelWriteCategoryId = +static const GUID ChannelWriteCategoryId = { 0xbf94ed39, 0x9585, 0x4822, { 0xb6, 0x9e, 0xdf, 0x19, 0x54, 0x9a, 0x66, 0x4c } }; // {95375270-AE5F-423E-A4EB-5AE7FC649CF6} -static const GUID ChannelReadCategoryId = +static const GUID ChannelReadCategoryId = { 0x95375270, 0xae5f, 0x423e, { 0xa4, 0xeb, 0x5a, 0xe7, 0xfc, 0x64, 0x9c, 0xf6 } }; // {01F2A23A-4144-45E6-9933-4668915A1758} -static const GUID ChannelCloseCategoryId = +static const GUID ChannelCloseCategoryId = { 0x1f2a23a, 0x4144, 0x45e6, { 0x99, 0x33, 0x46, 0x68, 0x91, 0x5a, 0x17, 0x58 } }; #pragma pack(push, 1) |
