1 | /* $Id: VBoxMMR.cpp 47231 2013-07-18 11:57:16Z 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(const VBOXSERVICEENV *pEnv, void **ppInstance, bool *pfStartThread)
|
---|
49 | {
|
---|
50 | LogRel2(("VBoxMMR: Initializing\n"));
|
---|
51 |
|
---|
52 | int rc = RTLdrLoadAppPriv(g_pszMMRDLL, &gCtx.hModHook);
|
---|
53 | if (RT_SUCCESS(rc))
|
---|
54 | {
|
---|
55 | HOOKPROC pHook = (HOOKPROC)RTLdrGetFunction(gCtx.hModHook, g_pszMMRPROC);
|
---|
56 | if (pHook)
|
---|
57 | {
|
---|
58 | HMODULE hMod = (HMODULE)RTLdrGetNativeHandle(gCtx.hModHook);
|
---|
59 | Assert(hMod != (HMODULE)~(uintptr_t)0);
|
---|
60 | gCtx.hHook = SetWindowsHookEx(WH_CBT, pHook, hMod, 0);
|
---|
61 | if (gCtx.hHook)
|
---|
62 | {
|
---|
63 | *ppInstance = &gCtx;
|
---|
64 | return VINF_SUCCESS;
|
---|
65 | }
|
---|
66 |
|
---|
67 | rc = RTErrConvertFromWin32(GetLastError());
|
---|
68 | LogRel2(("VBoxMMR: Error installing hooking proc: %Rrc\n", rc));
|
---|
69 | }
|
---|
70 | else
|
---|
71 | {
|
---|
72 | LogRel2(("VBoxMMR: Hooking proc not found\n"));
|
---|
73 | rc = VERR_NOT_FOUND;
|
---|
74 | }
|
---|
75 |
|
---|
76 | RTLdrClose(gCtx.hModHook);
|
---|
77 | gCtx.hModHook = NIL_RTLDRMOD;
|
---|
78 | }
|
---|
79 | else
|
---|
80 | LogRel2(("VBoxMMR: Hooking library not found (%Rrc)\n", rc));
|
---|
81 |
|
---|
82 | return rc;
|
---|
83 | }
|
---|
84 |
|
---|
85 | void VBoxMMRDestroy(const VBOXSERVICEENV *pEnv, void *pInstance)
|
---|
86 | {
|
---|
87 | VBOXMMRCONTEXT *pCtx = (VBOXMMRCONTEXT *) pInstance;
|
---|
88 |
|
---|
89 | VBoxMMRCleanup(pCtx);
|
---|
90 | }
|
---|
91 |
|
---|
92 | unsigned __stdcall VBoxMMRThread(void *pInstance)
|
---|
93 | {
|
---|
94 | return 0;
|
---|
95 | }
|
---|
96 |
|
---|