Changeset 70171 in vbox for trunk/src/VBox
- Timestamp:
- Dec 15, 2017 10:08:07 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 119736
- Location:
- trunk/src/VBox/Additions/common/VBoxService
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxService-win.cpp
r69500 r70171 20 20 * Header Files * 21 21 *********************************************************************************************************************************/ 22 #undef _WIN32_WINNT /// REMOVE WHEN VBoxServiceNT IS GONE 23 #define _WIN32_WINNT 0x0501 /// REMOVE WHEN VBoxServiceNT IS GONE 22 24 #include <iprt/assert.h> 23 25 #include <iprt/err.h> 26 #include <iprt/ldr.h> 24 27 #include <iprt/system.h> /* For querying OS version. */ 25 28 #include <VBox/VBoxGuestLib.h> 26 #include "VBoxServiceInternal.h" 27 28 #include <iprt/win/windows.h> 29 30 #include <iprt/nt/nt-and-windows.h> 29 31 #include <process.h> 30 32 #include <aclapi.h> 33 #include <tlhelp32.h> 34 35 #include "VBoxServiceInternal.h" 31 36 32 37 … … 51 56 }; 52 57 58 /** @name APIs from ADVAPI32.DLL. 59 * @{ */ 60 decltype(RegisterServiceCtrlHandlerExA) *g_pfnRegisterServiceCtrlHandlerExA; /**< W2K+ */ 61 decltype(ChangeServiceConfig2A) *g_pfnChangeServiceConfig2A; /**< W2K+ */ 62 /** @} */ 63 64 /** @name API from KERNEL32.DLL 65 * @{ */ 66 decltype(CreateToolhelp32Snapshot) *g_pfnCreateToolhelp32Snapshot; /**< W2K+, but Geoff says NT4. Hmm. */ 67 decltype(Process32First) *g_pfnProcess32First; /**< W2K+, but Geoff says NT4. Hmm. */ 68 decltype(Process32Next) *g_pfnProcess32Next; /**< W2K+, but Geoff says NT4. Hmm. */ 69 decltype(Module32First) *g_pfnModule32First; /**< W2K+, but Geoff says NT4. Hmm. */ 70 decltype(Module32Next) *g_pfnModule32Next; /**< W2K+, but Geoff says NT4. Hmm. */ 71 /** @} */ 72 73 /** @name API from NTDLL.DLL 74 * @{ */ 75 decltype(ZwQuerySystemInformation) *g_pfnZwQuerySystemInformation; /**< NT4 (where as NtQuerySystemInformation is W2K). */ 76 /** @} */ 77 78 79 /** 80 * Resolve APIs not present on older windows versions. 81 */ 82 void VGSvcWinResolveApis(void) 83 { 84 RTLDRMOD hLdrMod; 85 #define RESOLVE_SYMBOL(a_fn) do { RT_CONCAT(g_pfn, a_fn) = (decltype(a_fn) *)RTLdrGetFunction(hLdrMod, #a_fn); } while (0) 86 87 /* From ADVAPI32.DLL: */ 88 int rc = RTLdrLoadSystem("advapi32.dll", false /*fNoUnload*/, &hLdrMod); 89 AssertRC(rc); 90 if (RT_SUCCESS(rc)) 91 { 92 RESOLVE_SYMBOL(RegisterServiceCtrlHandlerExA); 93 RESOLVE_SYMBOL(ChangeServiceConfig2A); 94 RTLdrClose(hLdrMod); 95 } 96 97 /* From KERNEL32.DLL: */ 98 rc = RTLdrLoadSystem("kernel32.dll", false /*fNoUnload*/, &hLdrMod); 99 AssertRC(rc); 100 if (RT_SUCCESS(rc)) 101 { 102 RESOLVE_SYMBOL(CreateToolhelp32Snapshot); 103 RESOLVE_SYMBOL(Process32First); 104 RESOLVE_SYMBOL(Process32Next); 105 RESOLVE_SYMBOL(Module32First); 106 RESOLVE_SYMBOL(Module32Next); 107 RTLdrClose(hLdrMod); 108 } 109 110 /* From NTDLL.DLL: */ 111 rc = RTLdrLoadSystem("ntdll.dll", false /*fNoUnload*/, &hLdrMod); 112 AssertRC(rc); 113 if (RT_SUCCESS(rc)) 114 { 115 RESOLVE_SYMBOL(ZwQuerySystemInformation); 116 RTLdrClose(hLdrMod); 117 } 118 } 119 53 120 54 121 /** … … 58 125 */ 59 126 static DWORD vgsvcWinAddAceToObjectsSecurityDescriptor(LPTSTR pszObjName, 60 SE_OBJECT_TYPE ObjectType, 61 LPTSTR pszTrustee, 62 TRUSTEE_FORM TrusteeForm, 63 DWORD dwAccessRights, 64 ACCESS_MODE AccessMode, 65 DWORD dwInheritance) 66 { 67 DWORD dwRes = 0; 127 SE_OBJECT_TYPE ObjectType, 128 LPTSTR pszTrustee, 129 TRUSTEE_FORM TrusteeForm, 130 DWORD dwAccessRights, 131 ACCESS_MODE AccessMode, 132 DWORD dwInheritance) 133 { 68 134 PACL pOldDACL = NULL, pNewDACL = NULL; 69 135 PSECURITY_DESCRIPTOR pSD = NULL; … … 74 140 75 141 /* Get a pointer to the existing DACL. */ 76 dwRes = GetNamedSecurityInfo(pszObjName, ObjectType, 77 DACL_SECURITY_INFORMATION, 78 NULL, NULL, &pOldDACL, NULL, &pSD); 142 DWORD dwRes = GetNamedSecurityInfo(pszObjName, ObjectType, DACL_SECURITY_INFORMATION, NULL, NULL, &pOldDACL, NULL, &pSD); 79 143 if (ERROR_SUCCESS != dwRes) 80 144 { … … 103 167 104 168 /* Attach the new ACL as the object's DACL. */ 105 dwRes = SetNamedSecurityInfo(pszObjName, ObjectType, 106 DACL_SECURITY_INFORMATION, 107 NULL, NULL, pNewDACL, NULL); 169 dwRes = SetNamedSecurityInfo(pszObjName, ObjectType, DACL_SECURITY_INFORMATION, NULL, NULL, pNewDACL, NULL); 108 170 if (ERROR_SUCCESS != dwRes) 109 171 { … … 142 204 { 143 205 ss.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN; 144 #ifndef TARGET_NT4 145 /* Don't use SERVICE_ACCEPT_SESSIONCHANGE on Windows 2000. 146 * This makes SCM angry. */ 206 207 /* Don't use SERVICE_ACCEPT_SESSIONCHANGE on Windows 2000 or earlier. This makes SCM angry. */ 147 208 char szOSVersion[32]; 148 int rc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, 149 szOSVersion, sizeof(szOSVersion)); 209 int rc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szOSVersion, sizeof(szOSVersion)); 150 210 if (RT_SUCCESS(rc)) 151 211 { … … 155 215 else 156 216 VGSvcError("Error determining OS version, rc=%Rrc\n", rc); 157 #endif158 217 } 159 218 … … 166 225 if (!fStatusSet) 167 226 VGSvcError("Error reporting service status=%ld (controls=%x, checkpoint=%ld) to SCM: %ld\n", 168 227 dwStatus, ss.dwControlsAccepted, dwCheckPoint, GetLastError()); 169 228 return fStatusSet; 170 229 } … … 184 243 static RTEXITCODE vgsvcWinSetDesc(SC_HANDLE hService) 185 244 { 186 #ifndef TARGET_NT4187 245 /* On W2K+ there's ChangeServiceConfig2() which lets us set some fields 188 246 like a longer service description. */ 189 /** @todo On Vista+ SERVICE_DESCRIPTION also supports localized strings! */ 190 SERVICE_DESCRIPTION desc; 191 desc.lpDescription = VBOXSERVICE_DESCRIPTION; 192 if (!ChangeServiceConfig2(hService, 193 SERVICE_CONFIG_DESCRIPTION, /* Service info level */ 194 &desc)) 195 { 196 VGSvcError("Cannot set the service description! Error: %ld\n", GetLastError()); 197 return RTEXITCODE_FAILURE; 198 } 199 #else 200 RT_NOREF(hService); 201 #endif 247 if (g_pfnChangeServiceConfig2A) 248 { 249 /** @todo On Vista+ SERVICE_DESCRIPTION also supports localized strings! */ 250 SERVICE_DESCRIPTION desc; 251 desc.lpDescription = VBOXSERVICE_DESCRIPTION; 252 if (!g_pfnChangeServiceConfig2A(hService, SERVICE_CONFIG_DESCRIPTION, &desc)) 253 { 254 VGSvcError("Cannot set the service description! Error: %ld\n", GetLastError()); 255 return RTEXITCODE_FAILURE; 256 } 257 } 202 258 return RTEXITCODE_SUCCESS; 203 259 } … … 327 383 int rc = VINF_SUCCESS; 328 384 329 #ifndef TARGET_NT4330 385 /* Create a well-known SID for the "Builtin Users" group. */ 331 PSID pBuiltinUsersSID = NULL; 332 SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_LOCAL_SID_AUTHORITY; 333 334 if (!AllocateAndInitializeSid(&SIDAuthWorld, 1, 335 SECURITY_LOCAL_RID, 336 0, 0, 0, 0, 0, 0, 0, 337 &pBuiltinUsersSID)) 338 { 339 rc = RTErrConvertFromWin32(GetLastError()); 340 } 341 else 386 PSID pBuiltinUsersSID = NULL; 387 SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_LOCAL_SID_AUTHORITY; 388 if (AllocateAndInitializeSid(&SIDAuthWorld, 1, SECURITY_LOCAL_RID, 0, 0, 0, 0, 0, 0, 0, &pBuiltinUsersSID)) 342 389 { 343 390 DWORD dwRes = vgsvcWinAddAceToObjectsSecurityDescriptor(TEXT("\\\\.\\VBoxMiniRdrDN"), 344 345 346 347 348 349 391 SE_FILE_OBJECT, 392 (LPTSTR)pBuiltinUsersSID, 393 TRUSTEE_IS_SID, 394 FILE_GENERIC_READ | FILE_GENERIC_WRITE, 395 SET_ACCESS, 396 NO_INHERITANCE); 350 397 if (dwRes != ERROR_SUCCESS) 351 398 { … … 361 408 } 362 409 } 363 #endif 410 else 411 rc = RTErrConvertFromWin32(GetLastError()); 364 412 365 413 if (RT_SUCCESS(rc)) … … 404 452 if (!StartServiceCtrlDispatcher(&g_aServiceTable[0])) 405 453 return VGSvcError("StartServiceCtrlDispatcher: %u. Please start %s with option -f (foreground)!\n", 406 454 GetLastError(), g_pszProgName); 407 455 return RTEXITCODE_SUCCESS; 408 456 } 409 457 410 458 411 #ifndef TARGET_NT4 412 static const char* vgsvcWTSStateToString(DWORD dwEvent) 459 /** 460 * Event code to description. 461 * 462 * @returns String. 463 * @param dwEvent The event code. 464 */ 465 static const char *vgsvcWTSStateToString(DWORD dwEvent) 413 466 { 414 467 switch (dwEvent) 415 468 { 416 case WTS_CONSOLE_CONNECT: 417 return "A session was connected to the console terminal"; 418 419 case WTS_CONSOLE_DISCONNECT: 420 return "A session was disconnected from the console terminal"; 421 422 case WTS_REMOTE_CONNECT: 423 return "A session connected to the remote terminal"; 424 425 case WTS_REMOTE_DISCONNECT: 426 return "A session was disconnected from the remote terminal"; 427 428 case WTS_SESSION_LOGON: 429 return "A user has logged on to a session"; 430 431 case WTS_SESSION_LOGOFF: 432 return "A user has logged off the session"; 433 434 case WTS_SESSION_LOCK: 435 return "A session has been locked"; 436 437 case WTS_SESSION_UNLOCK: 438 return "A session has been unlocked"; 439 440 case WTS_SESSION_REMOTE_CONTROL: 441 return "A session has changed its remote controlled status"; 442 #if 0 443 case WTS_SESSION_CREATE: 444 return "A session has been created"; 445 446 case WTS_SESSION_TERMINATE: 447 return "The session has been terminated"; 469 case WTS_CONSOLE_CONNECT: return "A session was connected to the console terminal"; 470 case WTS_CONSOLE_DISCONNECT: return "A session was disconnected from the console terminal"; 471 case WTS_REMOTE_CONNECT: return "A session connected to the remote terminal"; 472 case WTS_REMOTE_DISCONNECT: return "A session was disconnected from the remote terminal"; 473 case WTS_SESSION_LOGON: return "A user has logged on to a session"; 474 case WTS_SESSION_LOGOFF: return "A user has logged off the session"; 475 case WTS_SESSION_LOCK: return "A session has been locked"; 476 case WTS_SESSION_UNLOCK: return "A session has been unlocked"; 477 case WTS_SESSION_REMOTE_CONTROL: return "A session has changed its remote controlled status"; 478 #ifdef WTS_SESSION_CREATE 479 case WTS_SESSION_CREATE: return "A session has been created"; 448 480 #endif 449 default: 450 break; 451 } 452 453 return "Uknonwn state"; 454 } 455 #endif /* !TARGET_NT4 */ 456 457 458 #ifdef TARGET_NT4 459 static VOID WINAPI vgsvcWinCtrlHandler(DWORD dwControl) 460 #else 461 static DWORD WINAPI vgsvcWinCtrlHandler(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext) 481 #ifdef WTS_SESSION_TERMINATE 482 case WTS_SESSION_TERMINATE: return "The session has been terminated"; 462 483 #endif 463 { 464 #ifdef TARGET_NT4 465 VGSvcVerbose(2, "Control handler: Control=%#x\n", dwControl); 466 #else 467 RT_NOREF1(lpContext); 468 VGSvcVerbose(2, "Control handler: Control=%#x, EventType=%#x\n", dwControl, dwEventType); 469 #endif 470 484 default: return "Uknonwn state"; 485 } 486 } 487 488 489 /** 490 * Common control handler. 491 * 492 * @returns Return code for NT5+. 493 * @param dwControl The control code. 494 */ 495 static DWORD vgsvcWinCtrlHandlerCommon(DWORD dwControl) 496 { 471 497 DWORD rcRet = NO_ERROR; 472 498 switch (dwControl) … … 494 520 } 495 521 496 # ifndef TARGET_NT4497 case SERVICE_CONTROL_SESSIONCHANGE: /* Only Windows 2000 and up. */498 {499 AssertPtr(lpEventData);500 PWTSSESSION_NOTIFICATION pNotify = (PWTSSESSION_NOTIFICATION)lpEventData;501 Assert(pNotify->cbSize == sizeof(WTSSESSION_NOTIFICATION));502 503 VGSvcVerbose(1, "Control handler: %s (Session=%ld, Event=%#x)\n",504 vgsvcWTSStateToString(dwEventType),505 pNotify->dwSessionId, dwEventType);506 507 /* Handle all events, regardless of dwEventType. */508 int rc2 = VGSvcVMInfoSignal();509 AssertRC(rc2);510 break;511 }512 # endif /* !TARGET_NT4 */513 514 522 default: 515 523 VGSvcVerbose(1, "Control handler: Function not implemented: %#x\n", dwControl); … … 518 526 } 519 527 520 #ifndef TARGET_NT4521 528 return rcRet; 522 #endif 529 } 530 531 532 /** 533 * Callback registered by RegisterServiceCtrlHandler on NT4 and earlier. 534 */ 535 static VOID WINAPI vgsvcWinCtrlHandlerNt4(DWORD dwControl) 536 { 537 VGSvcVerbose(2, "Control handler (NT4): dwControl=%#x\n", dwControl); 538 vgsvcWinCtrlHandlerCommon(dwControl); 539 } 540 541 542 /** 543 * Callback registered by RegisterServiceCtrlHandler on NT5 and later. 544 */ 545 static DWORD WINAPI vgsvcWinCtrlHandlerNt5Plus(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext) 546 { 547 VGSvcVerbose(2, "Control handler: dwControl=%#x, dwEventType=%#x\n", dwControl, dwEventType); 548 RT_NOREF1(lpContext); 549 550 switch (dwControl) 551 { 552 default: 553 return vgsvcWinCtrlHandlerCommon(dwControl); 554 555 case SERVICE_CONTROL_SESSIONCHANGE: /* Only Windows 2000 and up. */ 556 { 557 AssertPtr(lpEventData); 558 PWTSSESSION_NOTIFICATION pNotify = (PWTSSESSION_NOTIFICATION)lpEventData; 559 Assert(pNotify->cbSize == sizeof(WTSSESSION_NOTIFICATION)); 560 561 VGSvcVerbose(1, "Control handler: %s (Session=%ld, Event=%#x)\n", 562 vgsvcWTSStateToString(dwEventType), pNotify->dwSessionId, dwEventType); 563 564 /* Handle all events, regardless of dwEventType. */ 565 int rc2 = VGSvcVMInfoSignal(); 566 AssertRC(rc2); 567 568 return NO_ERROR; 569 } 570 } 523 571 } 524 572 … … 528 576 RT_NOREF2(argc, argv); 529 577 VGSvcVerbose(2, "Registering service control handler ...\n"); 530 #ifdef TARGET_NT4 531 g_hWinServiceStatus = RegisterServiceCtrlHandler(VBOXSERVICE_NAME, vgsvcWinCtrlHandler); 532 #else 533 g_hWinServiceStatus = RegisterServiceCtrlHandlerEx(VBOXSERVICE_NAME, vgsvcWinCtrlHandler, NULL); 534 #endif 578 if (g_pfnRegisterServiceCtrlHandlerExA) 579 g_hWinServiceStatus = g_pfnRegisterServiceCtrlHandlerExA(VBOXSERVICE_NAME, vgsvcWinCtrlHandlerNt5Plus, NULL); 580 else 581 g_hWinServiceStatus = RegisterServiceCtrlHandlerA(VBOXSERVICE_NAME, vgsvcWinCtrlHandlerNt4); 535 582 if (g_hWinServiceStatus != NULL) 536 583 { -
trunk/src/VBox/Additions/common/VBoxService/VBoxService.cpp
r69997 r70171 882 882 return RTMsgInitFailure(rc); 883 883 g_pszProgName = RTPathFilename(argv[0]); 884 #ifdef RT_OS_WINDOWS 885 VGSvcWinResolveApis(); 886 #endif 884 887 #ifdef DEBUG 885 888 rc = RTCritSectInit(&g_csLog); -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceInternal.h
r69997 r70171 197 197 extern int VGSvcReportStatus(VBoxGuestFacilityStatus enmStatus); 198 198 #ifdef RT_OS_WINDOWS 199 extern void VGSvcWinResolveApis(void); 199 200 extern RTEXITCODE VGSvcWinInstall(void); 200 201 extern RTEXITCODE VGSvcWinUninstall(void); 201 202 extern RTEXITCODE VGSvcWinEnterCtrlDispatcher(void); 202 203 extern void VGSvcWinSetStopPendingStatus(uint32_t uCheckPoint); 204 # ifdef TH32CS_SNAPHEAPLIST 205 extern decltype(CreateToolhelp32Snapshot) *g_pfnCreateToolhelp32Snapshot; 206 extern decltype(Process32First) *g_pfnProcess32First; 207 extern decltype(Process32Next) *g_pfnProcess32Next; 208 extern decltype(Module32First) *g_pfnModule32First; 209 extern decltype(Module32Next) *g_pfnModule32Next; 210 # endif 211 # ifdef ___iprt_nt_nt_h___ 212 extern decltype(ZwQuerySystemInformation) *g_pfnZwQuerySystemInformation; 213 # endif 203 214 #endif 204 215 -
trunk/src/VBox/Additions/common/VBoxService/VBoxServicePageSharing.cpp
r69500 r70171 45 45 * Header Files * 46 46 *********************************************************************************************************************************/ 47 #undef _WIN32_WINNT /// REMOVE WHEN VBoxServiceNT IS GONE 48 #define _WIN32_WINNT 0x0501 /// REMOVE WHEN VBoxServiceNT IS GONE 47 49 #include <iprt/assert.h> 48 50 #include <iprt/avl.h> … … 62 64 #include <VBox/VMMDev.h> 63 65 #include <VBox/VBoxGuestLib.h> 64 #include "VBoxServiceInternal.h" 65 #include "VBoxServiceUtils.h" 66 67 #if defined(RT_OS_WINDOWS) && !defined(TARGET_NT4) 66 67 #ifdef RT_OS_WINDOWS 68 #include <iprt/nt/nt-and-windows.h> 68 69 # include <tlhelp32.h> 69 70 # include <psapi.h> … … 71 72 #endif 72 73 74 #include "VBoxServiceInternal.h" 75 #include "VBoxServiceUtils.h" 76 73 77 74 78 /********************************************************************************************************************************* … … 81 85 HMODULE hModule; 82 86 char szFileVersion[16]; 83 # ifndef TARGET_NT484 87 MODULEENTRY32 Info; 85 # endif 86 #endif /* RT_OS_WINDOWS */ 88 #endif 87 89 } VGSVCPGSHKNOWNMOD, *PVGSVCPGSHKNOWNMOD; 88 89 90 #ifdef RT_OS_WINDOWS91 /* NTDLL API we want to use: */92 # define SystemModuleInformation 1193 94 typedef struct _RTL_PROCESS_MODULE_INFORMATION95 {96 ULONG Section;97 PVOID MappedBase;98 PVOID ImageBase;99 ULONG ImageSize;100 ULONG Flags;101 USHORT LoadOrderIndex;102 USHORT InitOrderIndex;103 USHORT LoadCount;104 USHORT OffsetToFileName;105 CHAR FullPathName[256];106 } RTL_PROCESS_MODULE_INFORMATION, *PRTL_PROCESS_MODULE_INFORMATION;107 108 typedef struct _RTL_PROCESS_MODULES109 {110 ULONG NumberOfModules;111 RTL_PROCESS_MODULE_INFORMATION Modules[1];112 } RTL_PROCESS_MODULES, *PRTL_PROCESS_MODULES;113 114 typedef NTSTATUS (WINAPI *PFNZWQUERYSYSTEMINFORMATION)(ULONG, PVOID, ULONG, PULONG);115 116 #endif /* RT_OS_WINDOWS */117 90 118 91 … … 120 93 * Global Variables * 121 94 *********************************************************************************************************************************/ 122 #ifdef RT_OS_WINDOWS123 static PFNZWQUERYSYSTEMINFORMATION g_pfnZwQuerySystemInformation = NULL;124 #endif125 126 95 /** The semaphore we're blocking on. */ 127 96 static RTSEMEVENTMULTI g_PageSharingEvent = NIL_RTSEMEVENTMULTI; 128 97 129 98 static PAVLPVNODECORE g_pKnownModuleTree = NULL; 130 static uint64_t g_idSession = 0;99 static uint64_t g_idSession = 0; 131 100 132 101 … … 137 106 138 107 139 #if defined(RT_OS_WINDOWS) && !defined(TARGET_NT4)108 #ifdef RT_OS_WINDOWS 140 109 141 110 /** … … 149 118 DWORD dwModuleSize = pModule->Info.modBaseSize; 150 119 BYTE *pBaseAddress = pModule->Info.modBaseAddr; 151 DWORD cbVersionSize, dummy;152 BYTE *pVersionInfo;153 120 154 121 VGSvcVerbose(3, "vgsvcPageSharingRegisterModule\n"); 155 122 156 cbVersionSize = GetFileVersionInfoSize(pModule->Info.szExePath, &dummy); 157 if (!cbVersionSize) 123 DWORD dwDummy; 124 DWORD cbVersion = GetFileVersionInfoSize(pModule->Info.szExePath, &dwDummy); 125 if (!cbVersion) 158 126 { 159 127 VGSvcVerbose(3, "vgsvcPageSharingRegisterModule: GetFileVersionInfoSize failed with %d\n", GetLastError()); 160 128 return; 161 129 } 162 pVersionInfo = (BYTE *)RTMemAlloc(cbVersionSize);130 BYTE *pVersionInfo = (BYTE *)RTMemAllocZ(cbVersion); 163 131 if (!pVersionInfo) 164 132 return; 165 133 166 if (!GetFileVersionInfo(pModule->Info.szExePath, 0, cbVersion Size, pVersionInfo))134 if (!GetFileVersionInfo(pModule->Info.szExePath, 0, cbVersion, pVersionInfo)) 167 135 { 168 136 VGSvcVerbose(3, "vgsvcPageSharingRegisterModule: GetFileVersionInfo failed with %d\n", GetLastError()); … … 177 145 } *lpTranslate; 178 146 179 UINT 147 UINT cbTranslate; 180 148 BOOL fRet = VerQueryValue(pVersionInfo, TEXT("\\VarFileInfo\\Translation"), (LPVOID *)&lpTranslate, &cbTranslate); 181 149 if ( !fRet … … 322 290 } 323 291 324 HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwProcessId);292 HANDLE hSnapshot = g_pfnCreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwProcessId); 325 293 if (hSnapshot == INVALID_HANDLE_VALUE) 326 294 { … … 336 304 337 305 ModuleInfo.dwSize = sizeof(ModuleInfo); 338 bRet = Module32First(hSnapshot, &ModuleInfo);306 bRet = g_pfnModule32First(hSnapshot, &ModuleInfo); 339 307 do 340 308 { … … 375 343 Assert(ret); NOREF(ret); 376 344 } 377 } while ( Module32Next(hSnapshot, &ModuleInfo));345 } while (g_pfnModule32Next(hSnapshot, &ModuleInfo)); 378 346 379 347 CloseHandle(hSnapshot); … … 389 357 static void vgsvcPageSharingInspectGuest(void) 390 358 { 391 HANDLE hSnapshot;359 VGSvcVerbose(3, "vgsvcPageSharingInspectGuest\n"); 392 360 PAVLPVNODECORE pNewTree = NULL; 393 DWORD dwProcessId = GetCurrentProcessId(); 394 395 VGSvcVerbose(3, "vgsvcPageSharingInspectGuest\n"); 396 397 hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 398 if (hSnapshot == INVALID_HANDLE_VALUE) 399 { 400 VGSvcVerbose(3, "vgsvcPageSharingInspectGuest: CreateToolhelp32Snapshot failed with %d\n", GetLastError()); 401 return; 402 } 403 404 /* Check loaded modules for all running processes. */ 405 PROCESSENTRY32 ProcessInfo; 406 407 ProcessInfo.dwSize = sizeof(ProcessInfo); 408 Process32First(hSnapshot, &ProcessInfo); 409 410 do 411 { 412 /* Skip our own process. */ 413 if (ProcessInfo.th32ProcessID != dwProcessId) 414 vgsvcPageSharingInspectModules(ProcessInfo.th32ProcessID, &pNewTree); 415 } 416 while (Process32Next(hSnapshot, &ProcessInfo)); 417 418 CloseHandle(hSnapshot); 419 420 /* Check all loaded kernel modules. */ 361 362 /* 363 * Check loaded modules for all running processes. 364 */ 365 if ( g_pfnProcess32First 366 && g_pfnProcess32Next 367 && g_pfnModule32First 368 && g_pfnModule32Next 369 && g_pfnCreateToolhelp32Snapshot) 370 { 371 HANDLE hSnapshot = g_pfnCreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 372 if (hSnapshot == INVALID_HANDLE_VALUE) 373 { 374 VGSvcVerbose(3, "vgsvcPageSharingInspectGuest: CreateToolhelp32Snapshot failed with %d\n", GetLastError()); 375 return; 376 } 377 378 DWORD const dwProcessId = GetCurrentProcessId(); 379 380 PROCESSENTRY32 ProcessInfo; 381 ProcessInfo.dwSize = sizeof(ProcessInfo); 382 g_pfnProcess32First(hSnapshot, &ProcessInfo); 383 384 do 385 { 386 /* Skip our own process. */ 387 if (ProcessInfo.th32ProcessID != dwProcessId) 388 vgsvcPageSharingInspectModules(ProcessInfo.th32ProcessID, &pNewTree); 389 } 390 while (g_pfnProcess32Next(hSnapshot, &ProcessInfo)); 391 392 CloseHandle(hSnapshot); 393 } 394 395 /* 396 * Check all loaded kernel modules. 397 */ 421 398 if (g_pfnZwQuerySystemInformation) 422 399 { … … 468 445 break; 469 446 470 /** @todo Use unicode APIs! */ 471 strcpy(pModule->Info.szModule, &pSystemModules->Modules[i].FullPathName[pSystemModules->Modules[i].OffsetToFileName]); 447 /** @todo FullPathName not an UTF-8 string is! An ANSI string it is. */ 448 strcpy(pModule->Info.szModule, 449 (const char *)&pSystemModules->Modules[i].FullPathName[pSystemModules->Modules[i].OffsetToFileName]); 472 450 GetSystemDirectoryA(szFullFilePath, sizeof(szFullFilePath)); 473 451 474 452 /* skip \Systemroot\system32 */ 475 char *lpPath = strchr( &pSystemModules->Modules[i].FullPathName[1], '\\');453 char *lpPath = strchr((char *)&pSystemModules->Modules[i].FullPathName[1], '\\'); 476 454 if (!lpPath) 477 455 { 478 456 /* Seen just file names in XP; try to locate the file in the system32 and system32\drivers directories. */ 479 457 strcat(szFullFilePath, "\\"); 480 strcat(szFullFilePath, pSystemModules->Modules[i].FullPathName);458 strcat(szFullFilePath, (const char *)pSystemModules->Modules[i].FullPathName); 481 459 VGSvcVerbose(3, "Unexpected kernel module name try %s\n", szFullFilePath); 482 460 if (RTFileExists(szFullFilePath) == false) … … 484 462 GetSystemDirectoryA(szFullFilePath, sizeof(szFullFilePath)); 485 463 strcat(szFullFilePath, "\\drivers\\"); 486 strcat(szFullFilePath, pSystemModules->Modules[i].FullPathName);464 strcat(szFullFilePath, (const char *)pSystemModules->Modules[i].FullPathName); 487 465 VGSvcVerbose(3, "Unexpected kernel module name try %s\n", szFullFilePath); 488 466 if (RTFileExists(szFullFilePath) == false) … … 496 474 else 497 475 { 498 lpPath = strchr(lpPath +1, '\\');476 lpPath = strchr(lpPath + 1, '\\'); 499 477 if (!lpPath) 500 478 { … … 568 546 569 547 570 #el if TARGET_NT4548 #else /* !RT_OS_WINDOWS */ 571 549 572 550 static void vgsvcPageSharingInspectGuest(void) 573 551 { 574 /* not implemented */575 }576 577 #else578 579 static void vgsvcPageSharingInspectGuest(void)580 {581 552 /** @todo other platforms */ 582 553 } 583 554 584 #endif 555 #endif /* !RT_OS_WINDOWS */ 585 556 586 557 /** @interface_method_impl{VBOXSERVICE,pfnInit} */ … … 592 563 AssertRCReturn(rc, rc); 593 564 594 #if defined(RT_OS_WINDOWS) && !defined(TARGET_NT4) 595 g_pfnZwQuerySystemInformation = (PFNZWQUERYSYSTEMINFORMATION)RTLdrGetSystemSymbol("ntdll.dll", "ZwQuerySystemInformation"); 596 565 #ifdef RT_OS_WINDOWS 597 566 rc = VbglR3GetSessionId(&g_idSession); 598 567 if (RT_FAILURE(rc)) … … 653 622 break; 654 623 } 655 #if defined(RT_OS_WINDOWS) && !defined(TARGET_NT4)624 #ifdef RT_OS_WINDOWS 656 625 uint64_t idNewSession = g_idSession; 657 626 rc = VbglR3GetSessionId(&idNewSession); -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceStats.cpp
r69500 r70171 31 31 #if defined(RT_OS_WINDOWS) 32 32 # ifdef TARGET_NT4 33 # undef _WIN32_WINNT 34 # define _WIN32_WINNT 0x 50133 # undef _WIN32_WINNT /// REMOVE WHEN VBoxServiceNT IS GONE 34 # define _WIN32_WINNT 0x0501 /// REMOVE WHEN VBoxServiceNT IS GONE 35 35 # endif 36 36 # include <iprt/win/windows.h> … … 63 63 #include <VBox/VMMDev.h> /* For VMMDevReportGuestStats and indirectly VbglR3StatReport. */ 64 64 #include <VBox/VBoxGuestLib.h> 65 65 66 #include "VBoxServiceInternal.h" 66 67 #include "VBoxServiceUtils.h"
Note:
See TracChangeset
for help on using the changeset viewer.