- Timestamp:
- Dec 19, 2019 4:15:07 PM (5 years ago)
- Location:
- trunk/src/VBox/Additions/WINNT/Installer
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/Installer/InstallHelper/Makefile.kmk
r82615 r82625 31 31 VBoxGuestInstallHelper_INST = repack/resources/VBoxGuestInstallHelper/ 32 32 ifdef VBOX_SIGN_ADDITIONS # (See the parent makefile.) 33 VBoxGuestInstallHelper_INSTTYPE = stage33 VBoxGuestInstallHelper_INSTTYPE = stage 34 34 VBoxGuestInstallHelper_DEBUG_INSTTYPE = both 35 35 endif 36 VBoxGuestInstallHelper_DEFS = _WIN32_WINNT=0x0400 WIN32_LEAN_AND_MEAN=136 VBoxGuestInstallHelper_DEFS = _WIN32_WINNT=0x0400 WIN32_LEAN_AND_MEAN=1 UNICODE _UNICODE 37 37 VBoxGuestInstallHelper_BLD_TRG_ARCH = x86 38 38 VBoxGuestInstallHelper_SOURCES = \ … … 41 41 42 42 include $(FILE_KBUILD_SUB_FOOTER) 43 -
trunk/src/VBox/Additions/WINNT/Installer/InstallHelper/VBoxGuestInstallHelper.cpp
r82616 r82625 30 30 #pragma warning(pop) 31 31 32 #include <iprt/err core.h>32 #include <iprt/err.h> 33 33 #include <iprt/initterm.h> 34 34 #include <iprt/ldr.h> … … 37 37 #include <iprt/process.h> 38 38 #include <iprt/string.h> 39 #ifdef UNICODE 40 # include <iprt/utf16.h> 41 #endif 39 42 40 43 /* Required structures/defines of VBoxTray. */ … … 70 73 * overflows, use vboxPopString() instead! 71 74 * 72 * @return HRESULT75 * @return VBox status code. 73 76 * @param pszDest Pointer to pre-allocated string to store result. 74 77 * @param cchDest Size (in characters) of pre-allocated string. 75 78 */ 76 static HRESULT vboxPopString(TCHAR *pszDest, size_t cchDest) 77 { 78 HRESULT hr = S_OK; 79 static int vboxPopString(TCHAR *pszDest, size_t cchDest) 80 { 81 int rc = VINF_SUCCESS; 82 79 83 if (!g_stacktop || !*g_stacktop) 80 hr = __HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE); 84 { 85 rc = VERR_NO_DATA; 86 } 81 87 else 82 88 { 83 89 stack_t *pStack = (*g_stacktop); 84 if (pStack) 85 { 86 hr = StringCchCopy(pszDest, cchDest, pStack->text); 87 if (SUCCEEDED(hr)) 88 { 89 *g_stacktop = pStack->next; 90 GlobalFree((HGLOBAL)pStack); 91 } 92 } 93 else 94 hr = __HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE); 95 } 96 return hr; 97 } 98 99 static HRESULT vboxPopULong(PULONG pulValue) 100 { 101 HRESULT hr = S_OK; 102 if (!g_stacktop || !*g_stacktop) 103 hr = __HRESULT_FROM_WIN32(ERROR_EMPTY); 104 else 105 { 106 stack_t *pStack = (*g_stacktop); 107 if (pStack) 108 { 109 *pulValue = strtoul(pStack->text, NULL, 10 /* Base */); 110 90 AssertPtr(pStack); 91 92 HRESULT hr = StringCchCopy(pszDest, cchDest, pStack->text); 93 if (SUCCEEDED(hr)) 94 { 111 95 *g_stacktop = pStack->next; 112 96 GlobalFree((HGLOBAL)pStack); 113 97 } 114 } 115 return hr; 116 } 117 118 static void vboxPushResultAsString(HRESULT hr) 119 { 120 TCHAR szErr[MAX_PATH + 1]; 98 else 99 rc = VERR_INVALID_PARAMETER; 100 } 101 return rc; 102 } 103 104 static int vboxPopULong(PULONG pulValue) 105 { 106 int rc = VINF_SUCCESS; 107 108 if (!g_stacktop || !*g_stacktop) 109 { 110 rc = VERR_NO_DATA; 111 } 112 else 113 { 114 stack_t *pStack = (*g_stacktop); 115 AssertPtr(pStack); 116 117 *pulValue = _tcstoul(pStack->text, NULL, 10 /* Base */); 118 119 *g_stacktop = pStack->next; 120 GlobalFree((HGLOBAL)pStack); 121 } 122 123 return rc; 124 } 125 126 static void vboxPushHResultAsString(HRESULT hr) 127 { 128 TCHAR szErr[NSIS_MAX_STRLEN]; 121 129 if (FAILED(hr)) 122 130 { … … 125 133 else 126 134 StringCchPrintf(szErr, sizeof(szErr), 127 "FormatMessage failed! Error = %ld", GetLastError());135 _T("FormatMessage failed! Error = %ld"), GetLastError()); 128 136 } 129 137 else 130 StringCchPrintf(szErr, sizeof(szErr), "0"); 138 StringCchPrintf(szErr, sizeof(szErr), _T("0")); 139 pushstring(szErr); 140 } 141 142 static void vboxPushRcAsString(int rc) 143 { 144 TCHAR szErr[NSIS_MAX_STRLEN]; 145 if (RT_FAILURE(rc)) 146 { 147 148 #ifdef UNICODE 149 TCHAR *pszErrAsString; 150 int rc2 = RTStrToUtf16(RTErrGetDefine(rc), &pszErrAsString); 151 if (RT_SUCCESS(rc2)) 152 { 153 #else 154 TCHAR *pszErrAsString = RTErrGetDefine(rc); 155 #endif 156 StringCchPrintf(szErr, sizeof(szErr), _T("Error: %s"), pszErrAsString); 157 158 #ifdef UNICODE 159 RTUtf16Free(pszErrAsString); 160 } 161 #endif 162 } 163 else 164 StringCchPrintf(szErr, sizeof(szErr), _T("0")); 165 131 166 pushstring(szErr); 132 167 } … … 152 187 } 153 188 189 #ifndef UNICODE 154 190 static void vboxChar2WCharFree(PWCHAR pwString) 155 191 { … … 158 194 } 159 195 160 static HRESULT vboxChar2WCharAlloc(const char *pszString, PWCHAR *ppwString) 161 { 162 HRESULT hr; 163 int iLen = (int)strlen(pszString) + 2; 196 static int vboxChar2WCharAlloc(const TCHAR *pszString, PWCHAR *ppwString) 197 { 198 int rc = VINF_SUCCESS; 199 200 int iLen = (int)_tcslen(pszString) + 2; 164 201 WCHAR *pwString = (WCHAR*)HeapAlloc(GetProcessHeap(), 0, iLen * sizeof(WCHAR)); 165 202 if (!pwString) 166 hr = __HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY); 203 { 204 rc = VERR_NO_MEMORY; 205 } 167 206 else 168 207 { 169 208 if (MultiByteToWideChar(CP_ACP, 0, pszString, -1, pwString, iLen) == 0) 170 209 { 171 hr = HRESULT_FROM_WIN32(GetLastError());210 rc = VERR_INVALID_PARAMETER; 172 211 HeapFree(GetProcessHeap(), 0, pwString); 173 212 } 174 213 else 175 214 { 176 hr = S_OK;177 215 *ppwString = pwString; 178 216 } 179 217 } 180 return hr; 181 } 218 return rc; 219 } 220 #endif /* !UNICODE */ 182 221 183 222 /** … … 217 256 218 257 TCHAR szFile[MAX_PATH + 1]; 219 HRESULT hr= vboxPopString(szFile, sizeof(szFile) / sizeof(TCHAR));220 if ( SUCCEEDED(hr))258 int rc = vboxPopString(szFile, sizeof(szFile) / sizeof(TCHAR)); 259 if (RT_SUCCESS(rc)) 221 260 { 222 261 HMODULE hSFC = loadSystemDll("sfc_os.dll"); /** @todo Replace this by RTLdr APIs. */ … … 230 269 g_pfnSfcFileException = (PFNSFCFILEEXCEPTION)GetProcAddress(hSFC, (LPCSTR)5); 231 270 if (g_pfnSfcFileException == NULL) 232 hr = HRESULT_FROM_WIN32(ERROR_PROC_NOT_FOUND);271 rc = VERR_SYMBOL_NOT_FOUND; 233 272 } 234 273 } 235 274 else 236 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); 237 238 if (SUCCEEDED(hr)) 239 { 275 rc = VERR_FILE_NOT_FOUND; 276 277 if (RT_SUCCESS(rc)) 278 { 279 #ifndef UNICODE 240 280 WCHAR *pwszFile; 241 hr= vboxChar2WCharAlloc(szFile, &pwszFile);242 if ( SUCCEEDED(hr))281 rc = vboxChar2WCharAlloc(szFile, &pwszFile); 282 if (RT_SUCCESS(rc)) 243 283 { 284 #else 285 TCHAR *pwszFile = szFile; 286 #endif 244 287 if (g_pfnSfcFileException(0, pwszFile, UINT32_MAX) != 0) 245 hr = HRESULT_FROM_WIN32(GetLastError()); 288 rc = VERR_ACCESS_DENIED; /** @todo Find a better rc. */ 289 #ifndef UNICODE 246 290 vboxChar2WCharFree(pwszFile); 247 291 } 292 #endif 248 293 } 249 294 … … 252 297 } 253 298 254 vboxPushR esultAsString(hr);299 vboxPushRcAsString(rc); 255 300 } 256 301 … … 273 318 274 319 TCHAR szFile[MAX_PATH + 1]; 275 HRESULT hr = vboxPopString(szFile, sizeof(szFile) / sizeof(TCHAR)); 276 if (SUCCEEDED(hr)) 277 { 278 RTLDRMOD hLdrMod; 279 int rc = RTLdrOpen(szFile, RTLDR_O_FOR_VALIDATION, RTLDRARCH_WHATEVER, &hLdrMod); 320 int rc = vboxPopString(szFile, sizeof(szFile) / sizeof(TCHAR)); 321 if (RT_SUCCESS(rc)) 322 { 323 #ifdef UNICODE 324 char *pszFileUtf8; 325 int rc = RTUtf16ToUtf8(szFile, &pszFileUtf8); 280 326 if (RT_SUCCESS(rc)) 281 327 { 282 if (RTLdrGetFormat(hLdrMod) == RTLDRFMT_PE) 328 #else 329 char *pszFileUtf8 = szFile; 330 #endif 331 RTLDRMOD hLdrMod; 332 rc = RTLdrOpen(pszFileUtf8, RTLDR_O_FOR_VALIDATION, RTLDRARCH_WHATEVER, &hLdrMod); 333 if (RT_SUCCESS(rc)) 283 334 { 284 RTLDRARCH enmLdrArch = RTLdrGetArch(hLdrMod); 285 switch (enmLdrArch) 335 if (RTLdrGetFormat(hLdrMod) == RTLDRFMT_PE) 286 336 { 287 case RTLDRARCH_X86_32: 288 pushstring("x86"); 289 break; 290 291 case RTLDRARCH_AMD64: 292 pushstring("amd64"); 293 break; 294 295 default: 296 pushstring("Error: Unknown / invalid architecture"); 297 break; 337 RTLDRARCH enmLdrArch = RTLdrGetArch(hLdrMod); 338 switch (enmLdrArch) 339 { 340 case RTLDRARCH_X86_32: 341 pushstring(_T("x86")); 342 break; 343 344 case RTLDRARCH_AMD64: 345 pushstring(_T("amd64")); 346 break; 347 348 default: 349 pushstring(_T("Error: Unknown / invalid architecture")); 350 break; 351 } 298 352 } 353 else 354 pushstring(_T("Error: Unknown / invalid PE signature")); 355 356 RTLdrClose(hLdrMod); 299 357 } 300 358 else 301 pushstring("Error: Unknown / invalid PE signature"); 302 303 RTLdrClose(hLdrMod); 304 } 305 else 306 { 307 char szMsg[64]; 308 RTStrPrintf(szMsg, sizeof(szMsg), "Error: Could not open file: %Rrc", rc); 309 310 pushstring(szMsg); 311 } 359 pushstring(_T("Error: Could not open file")); 360 #ifdef UNICODE 361 RTStrFree(pszFileUtf8); 362 } 363 #endif 312 364 } 313 365 else 314 vboxPushResultAsString(hr);366 pushstring(_T("Error: Could not retrieve file name")); 315 367 } 316 368 … … 333 385 334 386 TCHAR szFile[MAX_PATH + 1]; 335 HRESULT hr= vboxPopString(szFile, sizeof(szFile) / sizeof(TCHAR));336 if ( SUCCEEDED(hr))387 int rc = vboxPopString(szFile, sizeof(szFile) / sizeof(TCHAR)); 388 if (RT_SUCCESS(rc)) 337 389 { 338 390 DWORD dwInfoSize = GetFileVersionInfoSize(szFile, NULL /* lpdwHandle */); … … 353 405 354 406 TCHAR szQuery[MAX_PATH]; 355 #pragma warning(suppress:4995) /* warning C4995: '_sntprintf': name was marked as #pragma deprecated */ 356 _sntprintf(szQuery, sizeof(szQuery), _T("StringFileInfo\\%04X%04X\\CompanyName"), 357 wCodePage,wLanguageID); 407 StringCchPrintf(szQuery, sizeof(szQuery), _T("StringFileInfo\\%04X%04X\\CompanyName"), 408 wCodePage, wLanguageID); 358 409 359 410 LPCTSTR pcData; 360 if (VerQueryValue(pFileInfo, szQuery, (void**)&pcData, &puInfoLen))411 if (VerQueryValue(pFileInfo, szQuery, (void**)&pcData, &puInfoLen)) 361 412 { 362 413 pushstring(pcData); 363 414 } 364 415 else 365 hr = __HRESULT_FROM_WIN32(ERROR_NOT_FOUND);416 rc = VERR_NOT_FOUND; 366 417 } 367 418 else 368 hr = __HRESULT_FROM_WIN32(ERROR_NOT_FOUND);419 rc = VERR_NOT_FOUND; 369 420 } 370 421 GlobalFree(pFileInfo); 371 422 } 372 423 else 373 hr = __HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY);424 rc = VERR_NO_MEMORY; 374 425 } 375 426 else 376 hr = __HRESULT_FROM_WIN32(ERROR_NOT_FOUND);377 } 378 379 if ( FAILED(hr))380 vboxPushR esultAsString(hr);427 rc = VERR_NOT_FOUND; 428 } 429 430 if (RT_FAILURE(rc)) 431 vboxPushRcAsString(rc); 381 432 } 382 433 … … 398 449 EXDLL_INIT(); 399 450 400 char szMsg[256]; 401 char szTitle[128]; 402 HRESULT hr = vboxPopString(szMsg, sizeof(szMsg) / sizeof(char)); 451 int rc = VINF_SUCCESS; 452 453 TCHAR szMsg[256]; 454 TCHAR szTitle[128]; 455 HRESULT hr = vboxPopString(szMsg, sizeof(szMsg) / sizeof(TCHAR)); 403 456 if (SUCCEEDED(hr)) 404 hr = vboxPopString(szTitle, sizeof(szTitle) / sizeof( char));457 hr = vboxPopString(szTitle, sizeof(szTitle) / sizeof(TCHAR)); 405 458 406 459 /** @todo Do we need to restore the stack on failure? */ … … 410 463 RTR3InitDll(0); 411 464 412 uint32_t cbMsg = sizeof(VBOXTRAYIPCMSG_SHOWBALLOONMSG) 413 + (uint32_t)strlen(szMsg) + 1 /* Include terminating zero */414 + (uint32_t)strlen(szTitle) + 1; /* Ditto. */415 Assert(cbMsg);416 PVBOXTRAYIPCMSG_SHOWBALLOONMSG pIpcMsg =417 (PVBOXTRAYIPCMSG_SHOWBALLOONMSG)RTMemAlloc(cbMsg);418 if (pIpcMsg) 419 {420 /* Stuff in the strings. */421 memcpy(pIpcMsg->szMsgContent, szMsg, strlen(szMsg) + 1); 422 memcpy(pIpcMsg->szMsgTitle, szTitle, strlen(szTitle) + 1);423 424 /* Pop off the values in reverse order from the stack. */425 if (SUCCEEDED(hr))426 hr = vboxPopULong((ULONG*)&pIpcMsg->uType);427 if (SUCCEEDED(hr))428 hr = vboxPopULong((ULONG*)&pIpcMsg->uShowMS);429 430 if ( SUCCEEDED(hr))465 #ifdef UNICODE 466 char *pszMsgUtf8 = NULL; 467 char *pszTitleUtf8 = NULL; 468 rc = RTUtf16ToUtf8(szMsg, &pszMsgUtf8); 469 if (RT_SUCCESS(rc)) 470 rc = RTUtf16ToUtf8(szTitle, &pszTitleUtf8); 471 #else 472 char *pszMsgUtf8 = szMsg; 473 char *pszTitleUtf8 = szTitle; 474 #endif 475 if (RT_SUCCESS(rc)) 476 { 477 /* We use UTF-8 for the IPC data. */ 478 uint32_t cbMsg = sizeof(VBOXTRAYIPCMSG_SHOWBALLOONMSG) 479 + (uint32_t)strlen(pszMsgUtf8) + 1 /* Include terminating zero */ 480 + (uint32_t)strlen(pszTitleUtf8) + 1; /* Ditto. */ 481 Assert(cbMsg); 482 PVBOXTRAYIPCMSG_SHOWBALLOONMSG pIpcMsg = (PVBOXTRAYIPCMSG_SHOWBALLOONMSG)RTMemAlloc(cbMsg); 483 if (pIpcMsg) 431 484 { 432 RTLOCALIPCSESSION hSession = 0; 433 int rc = vboxConnectToVBoxTray(&hSession); 485 /* Stuff in the strings. */ 486 memcpy(pIpcMsg->szMsgContent, pszMsgUtf8, strlen(pszMsgUtf8) + 1); 487 memcpy(pIpcMsg->szMsgTitle, pszTitleUtf8, strlen(pszTitleUtf8) + 1); 488 489 /* Pop off the values in reverse order from the stack. */ 490 rc = vboxPopULong((ULONG *)&pIpcMsg->uType); 491 if (RT_SUCCESS(rc)) 492 rc = vboxPopULong((ULONG *)&pIpcMsg->uShowMS); 493 434 494 if (RT_SUCCESS(rc)) 435 495 { 436 VBOXTRAYIPCHEADER ipcHdr = { VBOXTRAY_IPC_HDR_MAGIC, 0 /* Header version */, 437 VBOXTRAYIPCMSGTYPE_SHOWBALLOONMSG, cbMsg }; 438 439 rc = RTLocalIpcSessionWrite(hSession, &ipcHdr, sizeof(ipcHdr)); 496 RTLOCALIPCSESSION hSession = 0; 497 rc = vboxConnectToVBoxTray(&hSession); 440 498 if (RT_SUCCESS(rc)) 441 rc = RTLocalIpcSessionWrite(hSession, pIpcMsg, cbMsg); 442 443 int rc2 = RTLocalIpcSessionClose(hSession); 444 if (RT_SUCCESS(rc)) 445 rc = rc2; 499 { 500 VBOXTRAYIPCHEADER ipcHdr = { VBOXTRAY_IPC_HDR_MAGIC, 0 /* Header version */, 501 VBOXTRAYIPCMSGTYPE_SHOWBALLOONMSG, cbMsg }; 502 503 rc = RTLocalIpcSessionWrite(hSession, &ipcHdr, sizeof(ipcHdr)); 504 if (RT_SUCCESS(rc)) 505 rc = RTLocalIpcSessionWrite(hSession, pIpcMsg, cbMsg); 506 507 int rc2 = RTLocalIpcSessionClose(hSession); 508 if (RT_SUCCESS(rc)) 509 rc = rc2; 510 } 446 511 } 447 512 448 if (RT_FAILURE(rc)) 449 hr = __HRESULT_FROM_WIN32(ERROR_BROKEN_PIPE); 513 RTMemFree(pIpcMsg); 450 514 } 451 452 RTMemFree(pIpcMsg); 453 } 454 else 455 hr = __HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY); 456 } 457 458 /* Push simple return value on stack. */ 459 SUCCEEDED(hr) ? pushstring("0") : pushstring("1"); 515 else 516 rc = VERR_NO_MEMORY; 517 } 518 } 519 520 vboxPushRcAsString(rc); 460 521 } 461 522 -
trunk/src/VBox/Additions/WINNT/Installer/InstallHelper/exdll.h
r82615 r82625 72 72 { 73 73 struct _stack_t *next; 74 chartext[1]; // this should be the length of string_size74 TCHAR text[1]; // this should be the length of string_size 75 75 } stack_t; 76 76 … … 106 106 static unsigned int g_stringsize; 107 107 static stack_t **g_stacktop; 108 static char *g_variables; 109 110 static int __stdcall popstring(char *str) UNUSED; // 0 on success, 1 on empty stack 111 static void __stdcall pushstring(const char *str) UNUSED; 112 static char * __stdcall getuservariable(const int varnum) UNUSED; 113 static void __stdcall setuservariable(const int varnum, const char *var) UNUSED; 108 static TCHAR *g_variables; 114 109 115 110 enum … … 144 139 145 140 // utility functions (not required but often useful) 146 static int __stdcall popstring(char *str)141 int popstringn(TCHAR *str, int maxlen) 147 142 { 148 143 stack_t *th; 149 if (!g_stacktop || !*g_stacktop) 150 return 1; 144 if (!g_stacktop || !*g_stacktop) return 1; 151 145 th=(*g_stacktop); 152 lstrcpyA(str,th->text);146 if (str) lstrcpyn(str,th->text,maxlen?maxlen:g_stringsize); 153 147 *g_stacktop = th->next; 154 148 GlobalFree((HGLOBAL)th); … … 156 150 } 157 151 158 static void __stdcall pushstring(const char*str)152 static void __stdcall pushstring(const TCHAR *str) 159 153 { 160 154 stack_t *th; … … 162 156 return; 163 157 th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+g_stringsize); 164 lstrcpyn A(th->text,str,g_stringsize);158 lstrcpyn(th->text,str,g_stringsize); 165 159 th->next=*g_stacktop; 166 160 *g_stacktop=th; 167 161 } 168 162 169 static char* __stdcall getuservariable(const int varnum)163 static TCHAR* __stdcall getuservariable(const int varnum) 170 164 { 171 165 if (varnum < 0 || varnum >= __INST_LAST) … … 174 168 } 175 169 176 static void __stdcall setuservariable(const int varnum, const char*var)170 static void __stdcall setuservariable(const int varnum, const TCHAR *var) 177 171 { 178 172 if (var != NULL && varnum >= 0 && varnum < __INST_LAST) 179 lstrcpy A(g_variables + varnum*g_stringsize, var);173 lstrcpy(g_variables + varnum*g_stringsize, var); 180 174 } 181 175 #endif /* !GA_INCLUDED_SRC_WINNT_Installer_InstallHelper_exdll_h */ -
trunk/src/VBox/Additions/WINNT/Installer/InstallHelper/testcase/Makefile.kmk
r82618 r82625 27 27 tstWinAdditionsInstallHelper_TEMPLATE = VBoxGuestR3Exe 28 28 tstWinAdditionsInstallHelper_SOURCES = tstWinAdditionsInstallHelper.cpp 29 tstWinAdditionsInstallHelper_DEFS = _WIN32_WINNT=0x0400 WIN32_LEAN_AND_MEAN=1 TESTCASE29 tstWinAdditionsInstallHelper_DEFS = _WIN32_WINNT=0x0400 WIN32_LEAN_AND_MEAN=1 UNICODE _UNICODE 30 30 31 31 endif # VBOX_WITH_TESTCASES -
trunk/src/VBox/Additions/WINNT/Installer/InstallHelper/testcase/tstWinAdditionsInstallHelper.cpp
r82618 r82625 21 21 *********************************************************************************************************************************/ 22 22 #include <iprt/win/windows.h> 23 24 #include <tchar.h> 25 23 26 #pragma warning(push) 24 27 #pragma warning(disable: 4995) /* warning C4995: 'lstrcpyA': name was marked as #pragma deprecated */ … … 33 36 #include <iprt/string.h> 34 37 #include <iprt/test.h> 38 #include <iprt/utf16.h> 35 39 36 40 … … 45 49 46 50 /** Symbol names to test. */ 47 #define TST_FILEGETARCHITECTURE_NAME "FileGetArchitecture" 48 #define TST_FILEGETVENDOR_NAME "FileGetVendor" 51 #define TST_FILEGETARCHITECTURE_NAME "FileGetArchitecture" 52 #define TST_FILEGETVENDOR_NAME "FileGetVendor" 53 #define TST_VBOXTRAYSHOWBALLONMSG_NAME "VBoxTrayShowBallonMsg" 49 54 50 55 … … 71 76 * @param pcszString String to push to the stack. 72 77 */ 73 static int tstStackPushString(stack_t **ppStackTop, const char *pcszString) 74 { 75 const size_t cchString = strlen(pcszString); 76 AssertReturn(cchString, NULL); 77 78 static int tstStackPushString(stack_t **ppStackTop, const TCHAR *pcszString) 79 { 78 80 int rc = VINF_SUCCESS; 79 81 80 stack_t *pStack = (stack_t *)GlobalAlloc(GPTR, sizeof(stack_t) + cchString /* Termination space is part of stack_t */); 82 /* Termination space is part of stack_t. */ 83 stack_t *pStack = (stack_t *)GlobalAlloc(GPTR, sizeof(stack_t) + g_stringsize); 81 84 if (pStack) 82 85 { 83 lstrcpyn A(pStack->text, pcszString, (int)cchString + 1);86 lstrcpyn(pStack->text, pcszString, (int)g_stringsize); 84 87 pStack->next = ppStackTop ? *ppStackTop : NULL; 85 88 … … 98 101 * @param ppStackTop Stack to pop off string from. 99 102 */ 100 static char *tstStackPopString(stack_t **ppStackTop) 101 { 102 AssertPtrReturn(ppStackTop, NULL); 103 AssertPtrReturn(*ppStackTop, NULL); 104 103 static int tstStackPopString(stack_t **ppStackTop, TCHAR *pszStr, size_t cchStr) 104 { 105 105 stack_t *pStack = *ppStackTop; 106 107 char *pszString = RTStrDup(pStack->text); 108 if (pszString) 109 { 110 *ppStackTop = pStack->next; 111 GlobalFree((HGLOBAL)pStack); 112 } 113 114 AssertPtr(pszString); 115 return pszString; 106 lstrcpyn(pszStr, pStack->text, cchStr); 107 *ppStackTop = pStack->next; 108 GlobalFree((HGLOBAL)pStack); 109 110 return VINF_SUCCESS; 116 111 } 117 112 … … 126 121 char szGuestInstallHelperDll[RTPATH_MAX]; 127 122 RTProcGetExecutablePath(szGuestInstallHelperDll, sizeof(szGuestInstallHelperDll)); 123 124 /* Set the default string size. */ 125 g_stringsize = NSIS_MAX_STRLEN; 128 126 129 127 /** @todo This ASSUMES that this testcase always is located in the separate "bin/additions" sub directory … … 136 134 RTTestIPrintf(RTTESTLVL_ALWAYS, "Using DLL: %s\n", szGuestInstallHelperDll); 137 135 136 #ifdef UNICODE 137 const bool fUnicode = true; 138 #else 139 const bool fUnicode = false; 140 #endif 141 RTTestIPrintf(RTTESTLVL_ALWAYS, "Running %s build\n", fUnicode ? "UNICODE" : "ANSI"); 142 138 143 RTLDRMOD hLdrMod; 139 144 rc = RTLdrLoad(szGuestInstallHelperDll, &hLdrMod); 140 145 if (RT_SUCCESS(rc)) 141 146 { 142 TCHAR szVars[NSIS_MAX_STRLEN] = { 0 }; 143 147 TCHAR szVars[NSIS_MAX_STRLEN * sizeof(TCHAR)] = { 0 }; 148 149 /* 150 * Tests FileGetArchitecture 151 */ 144 152 PNSIS_PLUGIN_FUNC pfnFileGetArchitecture = NULL; 145 153 rc = RTLdrGetSymbol(hLdrMod, TST_FILEGETARCHITECTURE_NAME, (void**)&pfnFileGetArchitecture); … … 147 155 { 148 156 stack_t *pStack = NULL; 149 tstStackPushString(&pStack, "c:\\windows\\system32\\kernel32.dll");157 tstStackPushString(&pStack, _T("c:\\windows\\system32\\kernel32.dll")); 150 158 151 159 pfnFileGetArchitecture(NULL /* hWnd */, NSIS_MAX_STRLEN, szVars, &pStack, NULL /* extra */); 152 160 153 char *pszStack = tstStackPopString(&pStack); 154 if (pszStack) 155 RTTestIPrintf(RTTESTLVL_ALWAYS, "Arch: %s\n", pszStack); 161 TCHAR szStack[NSIS_MAX_STRLEN]; 162 rc = tstStackPopString(&pStack, szStack, sizeof(szStack)); 163 if ( RT_SUCCESS(rc) 164 && ( !_tcscmp(szStack, _T("x86")) 165 || !_tcscmp(szStack, _T("amd64")))) 166 { 167 if (fUnicode) 168 RTTestIPrintf(RTTESTLVL_ALWAYS, "Arch: %ls\n", szStack); 169 else 170 RTTestIPrintf(RTTESTLVL_ALWAYS, "Arch: %s\n", szStack); 171 } 156 172 else 157 173 RTTestIFailed("Getting file arch failed (NSIS API changed?)\n"); 158 RTStrFree(pszStack);159 174 tstStackDestroy(pStack); 160 175 } 161 176 else 162 RTTestIFailed("Loading FileGetArchitecture failed: %Rrc", rc); 163 177 RTTestIFailed("Loading pfnFileGetArchitecture failed: %Rrc", rc); 178 179 /* 180 * Tests FileGetVendor 181 */ 164 182 PNSIS_PLUGIN_FUNC pfnFileGetVendor; 165 183 rc = RTLdrGetSymbol(hLdrMod, TST_FILEGETVENDOR_NAME, (void**)&pfnFileGetVendor); … … 167 185 { 168 186 stack_t *pStack = NULL; 169 tstStackPushString(&pStack, "c:\\windows\\system32\\kernel32.dll"); 187 tstStackPushString(&pStack, _T("c:\\windows\\system32\\kernel32.dll")); 188 170 189 pfnFileGetVendor(NULL /* hWnd */, NSIS_MAX_STRLEN, szVars, &pStack, NULL /* extra */); 171 char *pszStack = tstStackPopString(&pStack); 172 if (pszStack) 173 RTTestIPrintf(RTTESTLVL_ALWAYS, "Vendor: %s\n", pszStack); 190 191 TCHAR szStack[NSIS_MAX_STRLEN]; 192 rc = tstStackPopString(&pStack, szStack, RT_ELEMENTS(szStack)); 193 if ( RT_SUCCESS(rc) 194 && !_tcscmp(szStack, _T("Microsoft Corporation"))) 195 { 196 if (fUnicode) 197 RTTestIPrintf(RTTESTLVL_ALWAYS, "Vendor: %ls\n", szStack); 198 else 199 RTTestIPrintf(RTTESTLVL_ALWAYS, "Vendor: %s\n", szStack); 200 } 174 201 else 175 202 RTTestIFailed("Getting file vendor failed (NSIS API changed?)\n"); 176 RTStrFree(pszStack);177 203 tstStackDestroy(pStack); 178 204 } 179 205 else 180 RTTestIFailed("Loading FileGetVendor failed: %Rrc", rc); 206 RTTestIFailed("Loading pfnFileGetVendor failed: %Rrc", rc); 207 208 /* 209 * Tests VBoxTrayShowBallonMsg 210 */ 211 PNSIS_PLUGIN_FUNC pfnVBoxTrayShowBallonMsg; 212 rc = RTLdrGetSymbol(hLdrMod, TST_VBOXTRAYSHOWBALLONMSG_NAME, (void **)&pfnVBoxTrayShowBallonMsg); 213 if (RT_SUCCESS(rc)) 214 { 215 stack_t *pStack = NULL; 216 /* Push stuff in reverse order to the stack. */ 217 tstStackPushString(&pStack, _T("5000") /* Time to show in ms */); 218 tstStackPushString(&pStack, _T("1") /* Type */); 219 tstStackPushString(&pStack, _T("This is a message from tstWinAdditionsInstallHelper!")); 220 tstStackPushString(&pStack, _T("This is a title from tstWinAdditionsInstallHelper!")); 221 222 pfnVBoxTrayShowBallonMsg(NULL /* hWnd */, NSIS_MAX_STRLEN, szVars, &pStack, NULL /* extra */); 223 224 TCHAR szStack[NSIS_MAX_STRLEN]; 225 rc = tstStackPopString(&pStack, szStack, RT_ELEMENTS(szStack)); 226 if (RT_SUCCESS(rc)) 227 { 228 if (fUnicode) 229 RTTestIPrintf(RTTESTLVL_ALWAYS, "Reply: %ls\n", szStack); 230 else 231 RTTestIPrintf(RTTESTLVL_ALWAYS, "Reply: %s\n", szStack); 232 } 233 else 234 RTTestIFailed("Sending message to VBoxTray failed (NSIS API changed?)\n"); 235 tstStackDestroy(pStack); 236 } 237 else 238 RTTestIFailed("Loading pfnVBoxTrayShowBallonMsg failed: %Rrc", rc); 181 239 182 240 RTLdrClose(hLdrMod); -
trunk/src/VBox/Additions/WINNT/Installer/VBoxGuestAdditionsCommon.nsh
r82606 r82625 571 571 found: 572 572 573 ${LogVerbose} "Getting architecture of file $\"$0$\" ..." 574 573 575 VBoxGuestInstallHelper::FileGetArchitecture "$0" 576 574 577 ; Stack: <architecture> $1 $0 575 578 Pop $0 ; Get architecture string 579 580 ${LogVerbose} "Architecture is: $0" 581 576 582 Pop $1 ; Restore $1 577 583 Exch $0 ; Restore $0, push vendor on top of stack
Note:
See TracChangeset
for help on using the changeset viewer.