1 | /* $Id: VBoxMMR.cpp 46593 2013-06-17 14:32:51Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxMMR - Multimedia Redirection
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #include "VBoxTray.h"
|
---|
19 | #include "VBoxMMR.h"
|
---|
20 | #include <iprt/ldr.h>
|
---|
21 |
|
---|
22 | struct VBOXMMRCONTEXT
|
---|
23 | {
|
---|
24 | RTLDRMOD hModHook;
|
---|
25 | HHOOK hHook;
|
---|
26 | };
|
---|
27 |
|
---|
28 | static VBOXMMRCONTEXT gCtx = {0};
|
---|
29 |
|
---|
30 | static const char *g_pszMMRDLL = "VBoxMMRHook";
|
---|
31 | static const char *g_pszMMRPROC = "CBTProc";
|
---|
32 |
|
---|
33 | void VBoxMMRCleanup(VBOXMMRCONTEXT *pCtx)
|
---|
34 | {
|
---|
35 | if (pCtx->hHook)
|
---|
36 | {
|
---|
37 | UnhookWindowsHookEx(pCtx->hHook);
|
---|
38 | pCtx->hHook = NULL;
|
---|
39 | }
|
---|
40 |
|
---|
41 | if (pCtx->hModHook != NIL_RTLDRMOD)
|
---|
42 | {
|
---|
43 | RTLdrClose(pCtx->hModHook);
|
---|
44 | pCtx->hModHook = NIL_RTLDRMOD;
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | int VBoxMMRInit(
|
---|
49 | const VBOXSERVICEENV *pEnv,
|
---|
50 | void **ppInstance,
|
---|
51 | bool *pfStartThread)
|
---|
52 | {
|
---|
53 | LogRel2(("VBoxMMR: Initializing\n"));
|
---|
54 |
|
---|
55 | int rc = RTLdrLoadAppPriv(g_pszMMRDLL, &gCtx.hModHook);
|
---|
56 | if (RT_SUCCESS(rc))
|
---|
57 | {
|
---|
58 | HOOKPROC pHook = (HOOKPROC)RTLdrGetFunction(gCtx.hModHook, g_pszMMRPROC);
|
---|
59 | if (pHook)
|
---|
60 | {
|
---|
61 | HMODULE hMod = (HMODULE)RTLdrGetNativeHandle(gCtx.hModHook);
|
---|
62 | Assert(hMod != (HMODULE)~(uintptr_t)0);
|
---|
63 | gCtx.hHook = SetWindowsHookEx(WH_CBT, pHook, hMod, 0);
|
---|
64 | if (gCtx.hHook)
|
---|
65 | {
|
---|
66 | *ppInstance = &gCtx;
|
---|
67 | return VINF_SUCCESS;
|
---|
68 | }
|
---|
69 |
|
---|
70 | rc = RTErrConvertFromWin32(GetLastError());
|
---|
71 | LogRel2(("VBoxMMR: Error installing hooking proc: %Rrc\n", rc));
|
---|
72 | }
|
---|
73 | else
|
---|
74 | {
|
---|
75 | LogRel2(("VBoxMMR: Hooking proc not found\n"));
|
---|
76 | rc = VERR_NOT_FOUND;
|
---|
77 | }
|
---|
78 | }
|
---|
79 | else
|
---|
80 | LogRel2(("VBoxMMR: Hooking library not found (%Rrc)\n", rc));
|
---|
81 |
|
---|
82 | RTLdrClose(gCtx.hModHook);
|
---|
83 | gCtx.hModHook = NIL_RTLDRMOD;
|
---|
84 | return rc;
|
---|
85 | }
|
---|
86 |
|
---|
87 | void VBoxMMRDestroy(const VBOXSERVICEENV *pEnv, void *pInstance)
|
---|
88 | {
|
---|
89 | VBOXMMRCONTEXT *pCtx = (VBOXMMRCONTEXT *) pInstance;
|
---|
90 |
|
---|
91 | VBoxMMRCleanup(pCtx);
|
---|
92 | }
|
---|
93 |
|
---|
94 | unsigned __stdcall VBoxMMRThread(void *pInstance)
|
---|
95 | {
|
---|
96 | return 0;
|
---|
97 | }
|
---|
98 |
|
---|