Changeset 53332 in vbox
- Timestamp:
- Nov 14, 2014 4:08:39 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo-win.cpp
r50025 r53332 98 98 int vboxServiceVMInfoWinWriteLastInput(PVBOXSERVICEVEPROPCACHE pCache, const char *pszUser, const char *pszDomain); 99 99 100 typedef BOOL WINAPI FNQUERYFULLPROCESSIMAGENAME(HANDLE, DWORD, LP TSTR, PDWORD);100 typedef BOOL WINAPI FNQUERYFULLPROCESSIMAGENAME(HANDLE, DWORD, LPWSTR, PDWORD); 101 101 typedef FNQUERYFULLPROCESSIMAGENAME *PFNQUERYFULLPROCESSIMAGENAME; 102 102 … … 130 130 * 131 131 * @return IPRT status code. 132 * @param pProc133 * @param pszBuf134 * @param cbBuf135 132 */ 136 static int VBoxServiceVMInfoWinProcessesGetModuleName (PVBOXSERVICEVMINFOPROC const pProc,137 TCHAR *pszName, size_t cbName)133 static int VBoxServiceVMInfoWinProcessesGetModuleNameA(PVBOXSERVICEVMINFOPROC const pProc, 134 char **ppszName) 138 135 { 139 136 AssertPtrReturn(pProc, VERR_INVALID_POINTER); 140 AssertPtrReturn(pszName, VERR_INVALID_POINTER); 141 AssertReturn(cbName, VERR_INVALID_PARAMETER); 137 AssertPtrReturn(ppszName, VERR_INVALID_POINTER); 142 138 143 139 /** @todo Only do this once. Later. */ … … 171 167 /* Since GetModuleFileNameEx has trouble with cross-bitness stuff (32-bit apps cannot query 64-bit 172 168 apps and vice verse) we have to use a different code path for Vista and up. */ 173 174 /* Note: For 2000 + NT4 we might just use GetModuleFileName() instead. */ 169 WCHAR wszName[_1K]; 170 DWORD dwLen = sizeof(wszName); 171 172 /* Note: For 2000 + NT4 we might just use GetModuleFileNameW() instead. */ 175 173 if (OSInfoEx.dwMajorVersion >= 6 /* Vista or later */) 176 174 { … … 179 177 PFNQUERYFULLPROCESSIMAGENAME pfnQueryFullProcessImageName; 180 178 pfnQueryFullProcessImageName = (PFNQUERYFULLPROCESSIMAGENAME) 181 RTLdrGetSystemSymbol("kernel32.dll", "QueryFullProcessImageNameA"); 182 /** @todo r=bird: WTF don't we query the UNICODE name? */ 179 RTLdrGetSystemSymbol("kernel32.dll", "QueryFullProcessImageNameW"); 183 180 if (pfnQueryFullProcessImageName) 184 181 { 185 /** @todo r=bird: Completely bogus use of TCHAR. 186 * !!ALL USE OF TCHAR IS HEREWITH BANNED IN ALL VBOX SOURCES!! 187 * We use WCHAR when talking to windows, everything else is WRONG. (We don't 188 * want Chinese MBCS being treated as UTF-8.) */ 189 DWORD dwLen = cbName / sizeof(TCHAR); 190 if (!pfnQueryFullProcessImageName(h, 0 /*PROCESS_NAME_NATIVE*/, pszName, &dwLen)) 182 if (!pfnQueryFullProcessImageName(h, 0 /*PROCESS_NAME_NATIVE*/, wszName, &dwLen)) 191 183 rc = VERR_ACCESS_DENIED; 192 184 } … … 194 186 else 195 187 { 196 if (!GetModuleFileNameEx (h, NULL /* Get main executable */, pszName, cbName / sizeof(TCHAR)))188 if (!GetModuleFileNameExW(h, NULL /* Get main executable */, wszName, dwLen)) 197 189 rc = VERR_ACCESS_DENIED; 190 } 191 192 if ( RT_FAILURE(rc) 193 && g_cVerbosity > 3) 194 { 195 VBoxServiceError("Unable to retrieve process name for PID=%ld, error=%ld\n", 196 pProc->id, GetLastError()); 197 } 198 else 199 { 200 char *pszName; 201 rc = RTUtf16ToUtf8(wszName, &pszName); 202 if (RT_SUCCESS(rc)) 203 *ppszName = pszName; 198 204 } 199 205 … … 577 583 */ 578 584 uint32_t cNumProcs = 0; 585 579 586 for (DWORD i = 0; i < cProcs; i++) 580 587 { 581 if (g_cVerbosity)582 {583 TCHAR szModule[_1K];584 rc = VBoxServiceVMInfoWinProcessesGetModuleName(&paProcs[i], szModule, sizeof(szModule));585 if (RT_SUCCESS(rc))586 VBoxServiceVerbose(4, "PID=%ld: %s\n",587 paProcs[i].id, szModule);588 }589 590 588 PSID pProcSID = paProcs[i].pSid; 591 589 if ( RT_SUCCESS(rc) … … 593 591 && IsValidSid(pProcSID)) 594 592 { 595 if ( EqualSid(pSessionData->Sid, paProcs[i].pSid) 596 && paProcs[i].fInteractive) 593 if (EqualSid(pSessionData->Sid, paProcs[i].pSid)) 597 594 { 598 cNumProcs++; 599 if (!g_cVerbosity) /* We want a bit more info on higher verbosity. */ 600 break; 595 if (g_cVerbosity) 596 { 597 char *pszName; 598 int rc2 = VBoxServiceVMInfoWinProcessesGetModuleNameA(&paProcs[i], &pszName); 599 VBoxServiceVerbose(4, "Session %RU32: PID=%ld (fInt=%RTbool): %s\n", 600 pSessionData->Session, paProcs[i].id, paProcs[i].fInteractive, 601 RT_SUCCESS(rc2) ? pszName : "<Unknown>"); 602 if (RT_SUCCESS(rc2)) 603 RTStrFree(pszName); 604 } 605 606 if (paProcs[i].fInteractive) 607 { 608 cNumProcs++; 609 if (!g_cVerbosity) /* We want a bit more info on higher verbosity. */ 610 break; 611 } 601 612 } 602 613 }
Note:
See TracChangeset
for help on using the changeset viewer.