- Timestamp:
- May 21, 2013 12:04:48 AM (12 years ago)
- Location:
- trunk/src/VBox/Additions/WINNT
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxHook/VBoxHook.cpp
-
Property svn:keywords
changed from
Id Revision
toAuthor Date Id Revision
r45703 r46182 1 /* $Id$ */ 1 2 /** @file 2 *3 3 * VBoxHook -- Global windows hook dll 4 * 4 */ 5 6 /* 5 7 * Copyright (C) 2006-2010 Oracle Corporation 6 8 * … … 13 15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 14 16 */ 17 15 18 #include <Windows.h> 16 19 #include <VBoxHook.h> … … 28 31 29 32 #ifdef DEBUG 30 void WriteLog(char *String, ...);31 # define dprintf(a) do { WriteLog a; } while (0)33 static void WriteLog(const char *pszFormat, ...); 34 # define dprintf(a) do { WriteLog a; } while (0) 32 35 #else 33 # define dprintf(a) do {} while (0)34 #endif /* DEBUG */36 # define dprintf(a) do {} while (0) 37 #endif /* !DEBUG */ 35 38 36 39 37 40 static void CALLBACK VBoxHandleWinEvent(HWINEVENTHOOK hook, DWORD event, HWND hwnd, 38 LONG idObject, LONG idChild,39 DWORD dwEventThread, DWORD dwmsEventTime)41 LONG idObject, LONG idChild, 42 DWORD dwEventThread, DWORD dwmsEventTime) 40 43 { 41 44 DWORD dwStyle; … … 90 93 91 94 static void CALLBACK VBoxHandleDesktopEvent(HWINEVENTHOOK hook, DWORD event, HWND hwnd, 92 LONG idObject, LONG idChild,93 DWORD dwEventThread, DWORD dwmsEventTime)95 LONG idObject, LONG idChild, 96 DWORD dwEventThread, DWORD dwmsEventTime) 94 97 { 95 98 if (!hDesktopNotifyEvent) … … 109 112 CoInitialize(NULL); 110 113 hDesktopEventHook = SetWinEventHook(EVENT_SYSTEM_DESKTOPSWITCH, EVENT_SYSTEM_DESKTOPSWITCH, 111 hDll,112 VBoxHandleDesktopEvent,113 0, 0,114 0);114 hDll, 115 VBoxHandleDesktopEvent, 116 0, 0, 117 0); 115 118 116 119 return !!hDesktopEventHook; … … 129 132 } 130 133 131 /* Install the global message hook */134 /** Install the global message hook */ 132 135 BOOL VBoxHookInstallWindowTracker(HMODULE hDll) 133 136 { … … 137 140 CoInitialize(NULL); 138 141 hWinEventHook[0] = SetWinEventHook(EVENT_OBJECT_LOCATIONCHANGE, EVENT_OBJECT_LOCATIONCHANGE, 139 hDll,140 VBoxHandleWinEvent,141 0, 0,142 WINEVENT_INCONTEXT | WINEVENT_SKIPOWNPROCESS);142 hDll, 143 VBoxHandleWinEvent, 144 0, 0, 145 WINEVENT_INCONTEXT | WINEVENT_SKIPOWNPROCESS); 143 146 144 147 hWinEventHook[1] = SetWinEventHook(EVENT_OBJECT_CREATE, EVENT_OBJECT_HIDE, 145 hDll,146 VBoxHandleWinEvent,147 0, 0,148 WINEVENT_INCONTEXT | WINEVENT_SKIPOWNPROCESS);148 hDll, 149 VBoxHandleWinEvent, 150 0, 0, 151 WINEVENT_INCONTEXT | WINEVENT_SKIPOWNPROCESS); 149 152 return !!hWinEventHook[0]; 150 153 } 151 154 152 /* Remove the global message hook */155 /** Remove the global message hook */ 153 156 BOOL VBoxHookRemoveWindowTracker() 154 157 { … … 165 168 166 169 #ifdef DEBUG 167 #include <VBox/VBoxGuest.h> 168 #include <VBox/VMMDev.h> 169 170 static char LogBuffer[1024]; 171 static HANDLE gVBoxDriver = INVALID_HANDLE_VALUE; 172 173 VBGLR3DECL(int) VbglR3GRPerform(VMMDevRequestHeader *pReq) 174 { 170 # include <VBox/VBoxGuest.h> 171 # include <VBox/VMMDev.h> 172 173 /** 174 * dprintf worker using VBoxGuest.sys and VMMDevReq_LogString. 175 */ 176 static void WriteLog(const char *pszFormat, ...) 177 { 178 /* 179 * Open VBox guest driver once. 180 */ 181 static HANDLE s_hVBoxGuest = INVALID_HANDLE_VALUE; 182 HANDLE hVBoxGuest = s_hVBoxGuest; 183 if (hVBoxGuest == INVALID_HANDLE_VALUE) 184 { 185 hVBoxGuest = CreateFile(VBOXGUEST_DEVICE_NAME, 186 GENERIC_READ | GENERIC_WRITE, 187 FILE_SHARE_READ | FILE_SHARE_WRITE, 188 NULL, 189 OPEN_EXISTING, 190 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, 191 NULL); 192 if (hVBoxGuest == INVALID_HANDLE_VALUE) 193 return; 194 s_hVBoxGuest = hVBoxGuest; 195 } 196 197 /* 198 * We're apparently afraid of using stack here, so we use a static buffer 199 * instead and pray we won't be here at the same time on two threads... 200 */ 201 static union 202 { 203 VMMDevReqLogString Req; 204 uint8_t abBuf[1024]; 205 } s_uBuf; 206 207 vmmdevInitRequest(&s_uBuf.Req.header, VMMDevReq_LogString); 208 209 va_list va; 210 va_start(va, pszFormat); 211 size_t cch = vsprintf(s_uBuf.Req.szString, pszFormat, va); 212 va_end(va); 213 214 s_uBuf.Req.header.size += (uint32_t)cch; 215 if (s_uBuf.Req.header.size > sizeof(s_uBuf)) 216 __debugbreak(); 217 175 218 DWORD cbReturned; 176 DeviceIoControl(gVBoxDriver, VBOXGUEST_IOCTL_VMMREQUEST(pReq->size), pReq, pReq->size, 177 pReq, pReq->size, &cbReturned, NULL); 178 return VINF_SUCCESS; 179 } 180 181 void WriteLog(char *pszStr, ...) 182 { 183 VMMDevReqLogString *pReq = (VMMDevReqLogString *)LogBuffer; 184 int rc; 185 186 /* open VBox guest driver */ 187 if (gVBoxDriver == INVALID_HANDLE_VALUE) 188 gVBoxDriver = CreateFile(VBOXGUEST_DEVICE_NAME, 189 GENERIC_READ | GENERIC_WRITE, 190 FILE_SHARE_READ | FILE_SHARE_WRITE, 191 NULL, 192 OPEN_EXISTING, 193 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, 194 NULL); 195 196 if (gVBoxDriver == INVALID_HANDLE_VALUE) 197 return; 198 199 va_list va; 200 201 va_start(va, pszStr); 202 203 vmmdevInitRequest(&pReq->header, VMMDevReq_LogString); 204 vsprintf(pReq->szString, pszStr, va); 205 pReq->header.size += strlen(pReq->szString); 206 rc = VbglR3GRPerform(&pReq->header); 207 208 va_end (va); 209 return; 210 } 211 212 #endif 219 DeviceIoControl(hVBoxGuest, VBOXGUEST_IOCTL_VMMREQUEST(s_uBuf.Req.size), 220 &s_uBuf.Req, s_uBuf.Req.header.size, 221 &s_uBuf.Req, s_uBuf.Req.header.size, 222 &cbReturned, NULL); 223 } 224 225 #endif /* DEBUG */ 226 -
Property svn:keywords
changed from
-
trunk/src/VBox/Additions/WINNT/VBoxHook/VBoxHook.def
-
Property svn:keywords
set to
Author Date Id Revision
r45703 r46182 1 ;/** @file 2 ; * 3 ; * VBoxHook -- Global windows hook dll 4 ; * 1 ; $Id$ 2 ;; @file 3 ; VBoxHook -- Global windows hook dll 4 ; 5 6 ; 5 7 ; Copyright (C) 2006-2010 Oracle Corporation 6 8 ; … … 13 15 ; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 14 16 ; 15 ; */16 17 17 18 LIBRARY VBoxHook 18 19 19 20 20 EXPORTS -
Property svn:keywords
set to
-
trunk/src/VBox/Additions/WINNT/VBoxHook/dllmain.cpp
-
Property svn:keywords
changed from
Id Revision
toAuthor Date Id Revision
r44528 r46182 1 /* $Id$ */ 1 2 /** @file 2 *3 3 * VBoxHook -- Global windows hook dll 4 * 4 */ 5 6 /* 5 7 * Copyright (C) 2006-2010 Oracle Corporation 6 8 * … … 13 15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 14 16 */ 15 #include <windows.h> 17 18 19 #include <Windows.h> 16 20 17 21 … … 26 30 BOOL WINAPI DllMain(HINSTANCE hDLLInst, DWORD fdwReason, LPVOID lpvReserved) 27 31 { 28 BOOL bStatus = TRUE;29 30 32 switch (fdwReason) 31 33 { 32 case DLL_PROCESS_ATTACH:33 return TRUE;34 case DLL_PROCESS_ATTACH: 35 return TRUE; 34 36 35 case DLL_PROCESS_DETACH:36 return TRUE;37 case DLL_PROCESS_DETACH: 38 return TRUE; 37 39 38 case DLL_THREAD_ATTACH:39 break;40 case DLL_THREAD_ATTACH: 41 return TRUE; 40 42 41 case DLL_THREAD_DETACH:42 return TRUE;43 case DLL_THREAD_DETACH: 44 return TRUE; 43 45 44 default:45 break;46 default: 47 return TRUE; 46 48 } 47 48 return bStatus;49 49 } 50 50 -
Property svn:keywords
changed from
-
trunk/src/VBox/Additions/WINNT/include/VBoxHook.h
-
Property svn:keywords
set to
Author Date Id Revision
r45760 r46182 1 /* $Id$ */ 1 2 /** @file 2 * 3 * VBoxHook -- Global windows hook dll 4 * 3 * VBoxHook -- Global windows hook dll. 4 */ 5 6 /* 5 7 * Copyright (C) 2006-2010 Oracle Corporation 6 8 * … … 13 15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 14 16 */ 15 #ifndef __ VBoxHook_h__16 #define __ VBoxHook_h__17 #ifndef ___winnt_include_VBoxHook_h 18 #define ___winnt_include_VBoxHook_h 17 19 18 20 /* custom messages as we must install the hook from the main thread */ … … 34 36 BOOL VBoxHookRemoveWindowTracker(); 35 37 36 #endif /* __VBoxHook_h__ */ 38 #endif 39 -
Property svn:keywords
set to
Note:
See TracChangeset
for help on using the changeset viewer.