HRESULT GetTokenFromPublicKey(SBuffer &publicKeyBLOB, SBuffer &publicKeyTokenBLOB) { HRESULT hr = S_OK; BINDER_LOG_ENTER(W("GetTokenFromPublicKey")); const BYTE *pByteKey = publicKeyBLOB; DWORD dwKeyLen = publicKeyBLOB.GetSize(); BYTE *pByteToken = NULL; DWORD dwTokenLen = 0; if (!StrongNameTokenFromPublicKey(const_cast<BYTE *>(pByteKey), dwKeyLen, &pByteToken, &dwTokenLen)) { BINDER_LOG(W("StrongNameTokenFromPublicKey failed!")); IF_FAIL_GO(StrongNameErrorInfo()); } else { _ASSERTE(pByteToken != NULL); publicKeyTokenBLOB.Set(pByteToken, dwTokenLen); StrongNameFreeBuffer(pByteToken); } Exit: BINDER_LOG_LEAVE_HR(W("GetTokenFromPublicKey"), hr); return hr; }
/* static */ HRESULT BindingLog::CreateInContext(ApplicationContext *pApplicationContext, AssemblyName *pAssemblyName, SString &assemblyPath, PEAssembly *pParentAssembly) { HRESULT hr = S_OK; BINDER_LOG_ENTER(L"BindingLog::CreateInContext"); BindingLog *pBindingLog = pApplicationContext->GetBindingLog(); // Invalidate existing debug log pBindingLog->SetDebugLog(NULL); IF_FAIL_GO(CDebugLog::Create(pApplicationContext, pAssemblyName, assemblyPath, &pBindingLog->m_pCDebugLog)); IF_FAIL_GO(pBindingLog->LogPreBindState(pApplicationContext, pAssemblyName, assemblyPath, pParentAssembly)); Exit: BINDER_LOG_LEAVE_HR(L"BindingLog::CreateInContext", hr); return hr; }
HRESULT FileOrDirectoryExistsLog(PathString &path) { HRESULT hr = S_FALSE; BINDER_LOG_ENTER(W("Utils::FileOrDirectoryExistsLog")); BINDER_LOG_STRING(W("path"), path); hr = FileOrDirectoryExists(path); BINDER_LOG_LEAVE_HR(W("Utils::FileOrDirectoryExistsLog"), hr); return hr; }
HRESULT BindingLog::Log(SString &info) { HRESULT hr = S_OK; BINDER_LOG_ENTER(L"BindingLog::Log"); IF_FAIL_GO(GetDebugLog()->LogMessage(0, FUSION_BIND_LOG_CATEGORY_DEFAULT, info)); Exit: BINDER_LOG_LEAVE_HR(L"BindingLog::Log", hr); return hr; }
HRESULT BindingLog::LogHR(HRESULT logHR) { HRESULT hr = S_OK; BINDER_LOG_ENTER(L"BindingLog::LogHR"); IF_FAIL_GO(GetDebugLog()->SetResultCode(0, logHR)); Exit: BINDER_LOG_LEAVE_HR(L"BindingLog::LogHR", hr); return hr; }
HRESULT BindingLog::LogResult(BindResult *pBindResult) { HRESULT hr = S_OK; BINDER_LOG_ENTER(L"BindingLog::LogResult"); PathString assemblyDisplayName; PathString format; PathString info; pBindResult->GetAssemblyName()->GetDisplayName(assemblyDisplayName, AssemblyName::INCLUDE_VERSION | AssemblyName::INCLUDE_ARCHITECTURE); IF_FAIL_GO(format.LoadResourceAndReturnHR(CCompRC::Debugging, ID_FUSLOG_ASSEMBLY_STATUS_BOUND_TO_ID)); info.Printf(format.GetUnicode(), assemblyDisplayName.GetUnicode()); IF_FAIL_GO(Log(info)); IUnknown *pIUnknownAssembly; pIUnknownAssembly = pBindResult->GetAssembly(FALSE /* fAddRef */); Assembly *pAssembly; pAssembly = static_cast<Assembly *>(static_cast<void *>(pIUnknownAssembly)); _ASSERTE(pAssembly != NULL); if (pAssembly->GetIsInGAC()) { IF_FAIL_GO(info. LoadResourceAndReturnHR(CCompRC::Debugging, ID_FUSLOG_ASSEMBLY_STATUS_BOUND_GAC)); } else if (pAssembly->GetIsByteArray()) { IF_FAIL_GO(info. LoadResourceAndReturnHR(CCompRC::Debugging, ID_FUSLOG_ASSEMBLY_STATUS_BOUND_BYTE_ARRAY)); } else { PathString assemblyPath; BinderGetImagePath(pAssembly->GetPEImage(), assemblyPath); IF_FAIL_GO(format. LoadResourceAndReturnHR(CCompRC::Debugging, ID_FUSLOG_ASSEMBLY_STATUS_BOUND_TO_LOCATION)); info.Printf(format.GetUnicode(), assemblyPath.GetUnicode()); } IF_FAIL_GO(Log(info)); Exit: BINDER_LOG_LEAVE_HR(L"BindingLog::LogResult", hr); return hr; }
void PlatformPath(SString &path) { BINDER_LOG_ENTER(W("Utils::PlatformPath")); BINDER_LOG_STRING(W("input path"), path); // Create platform representation MutateUrlToPath(path); if (NeedToRemoveDoubleAndNormalizePathSeparators(path)) RemoveDoubleAndNormalizePathSeparators(path); BINDER_LOG_STRING(W("platform path"), path); BINDER_LOG_LEAVE(W("Utils::PlatformPath")); }
HRESULT BindingLog::Flush() { HRESULT hr = S_OK; BINDER_LOG_ENTER(L"BindingLog::Flush"); hr = GetDebugLog()->Flush(0, FUSION_BIND_LOG_CATEGORY_DEFAULT); if (hr == E_ACCESSDENIED) { // We've been impersonated differently and have a old log entry BINDER_LOG(L"Impersonated: E_ACCESSDENIED"); hr = S_OK; } BINDER_LOG_LEAVE_HR(L"BindingLog::Flush", hr); return hr; }
/* static */ HRESULT BindingLog::CreateInContext(ApplicationContext *pApplicationContext, SString &assemblyPath, PEAssembly *pParentAssembly) { HRESULT hr = S_OK; BINDER_LOG_ENTER(L"BindingLog::CreateInContext (assemblyPath)"); if (IsLoggingNeeded()) { IF_FAIL_GO(CreateInContext(pApplicationContext, NULL, assemblyPath, pParentAssembly)); } Exit: BINDER_LOG_LEAVE_HR(L"BindingLog::CreateInContext (assemblyPath)", hr); return hr; }
void MutateUrlToPath(SString &urlOrPath) { BINDER_LOG_ENTER(W("Utils::MutateUrlToPath")); const SString fileUrlPrefix(SString::Literal, W("file://")); SString::Iterator i = urlOrPath.Begin(); BINDER_LOG_STRING(W("URL"), urlOrPath); if (urlOrPath.MatchCaseInsensitive(i, fileUrlPrefix)) { urlOrPath.Delete(i, fileUrlPrefix.GetCount()); i = urlOrPath.Begin() + 1; if (i[0] == W(':')) { // CLR erroneously passes in file:// prepended to file paths, // so we can't tell the difference between UNC and local file. goto Exit; } i = urlOrPath.Begin(); #if !defined(PLATFORM_UNIX) if (i[0] == W('/')) { // Disk path file:/// urlOrPath.Delete(i, 1); } else if (i[0] != W('\\')) { // UNC Path, re-insert "//" if not the wrong file://\\... urlOrPath.Insert(i, W("//")); } #else // Unix doesn't have a distinction between local and network path _ASSERTE(i[0] == W('\\') || i[0] == W('/')); #endif } Exit: while (urlOrPath.Find(i, W('/'))) { urlOrPath.Replace(i, W('\\')); } BINDER_LOG_STRING(W("Path"), urlOrPath); BINDER_LOG_LEAVE(W("Utils::MutateUrlToPath")); }
void MutatePathToUrl(SString &pathOrUrl) { BINDER_LOG_ENTER(W("Utils::MutatePathToUrl")); SString::Iterator i = pathOrUrl.Begin(); BINDER_LOG_STRING(W("Path"), pathOrUrl); #if !defined(PLATFORM_UNIX) // Network path \\server --> file://server // Disk path c:\dir --> file:///c:/dir if (i[0] == W('\\')) { const SString networkUrlPrefix(SString::Literal, W("file:")); // Network path pathOrUrl.Insert(i, networkUrlPrefix); pathOrUrl.Skip(i, networkUrlPrefix); } else { const SString diskPathUrlPrefix(SString::Literal, W("file:///")); // Disk path pathOrUrl.Insert(i, diskPathUrlPrefix); pathOrUrl.Skip(i, diskPathUrlPrefix); } #else // Unix doesn't have a distinction between a network or a local path _ASSERTE(i[0] == W('\\') || i[0] == W('/')); const SString fileUrlPrefix(SString::Literal, W("file://")); pathOrUrl.Insert(i, fileUrlPrefix); pathOrUrl.Skip(i, fileUrlPrefix); #endif while (pathOrUrl.Find(i, W('\\'))) { pathOrUrl.Replace(i, W('/')); } BINDER_LOG_STRING(W("URL"), pathOrUrl); BINDER_LOG_LEAVE(W("Utils::MutatePathToUrl")); }
HRESULT BindingLog::LogAssemblyName(LPCWSTR pwzPrefix, AssemblyName *pAssemblyName) { HRESULT hr = S_OK; BINDER_LOG_ENTER(L"BindingLog::LogAssemblyName"); PathString assemblyDisplayName; // Verify input arguments IF_FALSE_GO(pwzPrefix != NULL); IF_FALSE_GO(pAssemblyName != NULL); pAssemblyName->GetDisplayName(assemblyDisplayName, AssemblyName::INCLUDE_VERSION | AssemblyName::INCLUDE_ARCHITECTURE); IF_FAIL_GO(Log(pwzPrefix, assemblyDisplayName)); Exit: BINDER_LOG_LEAVE_HR(L"BindingLog::LogAssemblyName", hr); return hr; }
StringLexer::LEXEME_TYPE StringLexer::GetNextLexeme(SString ¤tString, BOOL fPermitUnescapedQuotes) { BOOL fIsEscaped = FALSE; WCHAR wcCurrentChar = INVALID_CHARACTER; BINDER_LOG_ENTER(L"StringLexer::GetNextLexeme"); // Remove any white spaces do { wcCurrentChar = PopCharacter(&fIsEscaped); } while (IsWhitespace(wcCurrentChar)); // Determine lexeme type LEXEME_TYPE kLexemeType = LEXEME_TYPE_INVALID; if (!fIsEscaped) { kLexemeType = GetLexemeType(wcCurrentChar); if (kLexemeType != LEXEME_TYPE_STRING) { return kLexemeType; } } // First character of string lexeme; push it back PushCharacter(wcCurrentChar, fIsEscaped); kLexemeType = ParseString(currentString, fPermitUnescapedQuotes); if (kLexemeType == LEXEME_TYPE_STRING) { BINDER_LOG_LEAVE_HR(L"StringLexer::GetNextLexeme(LEXEME_TYPE_STRING)", S_OK); } else { BINDER_LOG_LEAVE_HR(L"StringLexer::GetNextLexeme(LEXEME_TYPE_INVALID)", S_FALSE); } return kLexemeType; }
void CombinePath(SString &pathA, SString &pathB, SString &combinedPath) { BINDER_LOG_ENTER(W("Utils::CombinePath")); BINDER_LOG_STRING(W("path A"), pathA); BINDER_LOG_STRING(W("path B"), pathB); SString platformPathSeparator(SString::Literal, GetPlatformPathSeparator()); combinedPath.Set(pathA); if (!combinedPath.EndsWith(platformPathSeparator)) { combinedPath.Append(platformPathSeparator); } combinedPath.Append(pathB); BINDER_LOG_LEAVE(W("Utils::CombinePath")); }
/* static */ HRESULT BindingLog::CreateInContext(ApplicationContext *pApplicationContext, AssemblyName *pAssemblyName, PEAssembly *pParentAssembly) { HRESULT hr = S_OK; BINDER_LOG_ENTER(L"BindingLog::CreateInContext (pAssemblyName)"); if (IsLoggingNeeded()) { SmallStackSString emptyString; IF_FALSE_GO(pAssemblyName != NULL); IF_FAIL_GO(CreateInContext(pApplicationContext, pAssemblyName, emptyString, pParentAssembly)); } Exit: BINDER_LOG_LEAVE_HR(L"BindingLog::CreateInContext (pAssemblyName)", hr); return hr; }
/* static */ HRESULT Compatibility::Retarget(AssemblyName *pAssemblyName, AssemblyName **ppRetargetedAssemblyName, BOOL *pfIsRetargeted) { HRESULT hr = S_OK; BINDER_LOG_ENTER(W("Compatibility::Retarget")); IF_FALSE_GO(pAssemblyName != NULL); IF_FALSE_GO(ppRetargetedAssemblyName != NULL); BINDER_LOG_ASSEMBLY_NAME(W("source"), pAssemblyName); if (pfIsRetargeted) { *pfIsRetargeted = FALSE; } #ifdef FEATURE_CORESYSTEM // Apply retargeting only for strong-named culture neutral assemblies if (pAssemblyName->IsStronglyNamed() && pAssemblyName->GetDeNormalizedCulture().IsEmpty()) { ReleaseHolder<AssemblyName> pRetargetedAssemblyName; SString &simpleName = pAssemblyName->GetSimpleName(); AssemblyVersion *pAssemblyVersion = pAssemblyName->GetVersion(); SString publicKeyToken; TextualIdentityParser::BlobToHex(pAssemblyName->GetPublicKeyTokenBLOB(), publicKeyToken); // Perform linear search for matching assembly. Legacy Fusion also does that for (unsigned int i = 0; i < LENGTH_OF(arRetargetConfig); i++) { #ifdef FEATURE_LEGACYNETCF if (!RuntimeIsLegacyNetCF(0) && arRetargetConfig[i].fMangoOnly == TRUE) continue; #endif if (IsMatchingString(simpleName, arRetargetConfig[i].pwzSimpleName) && IsMatchingVersion(pAssemblyVersion, arRetargetConfig[i].pwzVersion) && IsMatchingString(publicKeyToken, arRetargetConfig[i].pwzPublicKeyToken)) { AssemblyVersion newAssemblyVersion; IF_FALSE_GO(newAssemblyVersion.SetVersion(arRetargetConfig[i].pwzNewVersion)); SAFE_NEW(pRetargetedAssemblyName, AssemblyName); if (arRetargetConfig[i].pwzNewSimpleName != NULL) { pRetargetedAssemblyName-> GetSimpleName().Set(arRetargetConfig[i].pwzNewSimpleName); } else { pRetargetedAssemblyName->GetSimpleName().Set(simpleName); } pRetargetedAssemblyName->SetVersion(&newAssemblyVersion); SBuffer newPublicKeyTokenBlob; SmallStackSString newPublicKeyToken(arRetargetConfig[i].pwzNewPublicKeyToken); TextualIdentityParser::HexToBlob(newPublicKeyToken, FALSE /* fValidateHex */, TRUE /* fIsToken */, newPublicKeyTokenBlob); pRetargetedAssemblyName->GetPublicKeyTokenBLOB().Set(newPublicKeyTokenBlob); BINDER_LOG_ASSEMBLY_NAME(W("retargeted"), pRetargetedAssemblyName); *ppRetargetedAssemblyName = pRetargetedAssemblyName.Extract(); if (pfIsRetargeted) { *pfIsRetargeted = TRUE; } GO_WITH_HRESULT(S_OK); } } // Create a clone without retargetable flag if (pAssemblyName->GetIsRetargetable()) { IF_FAIL_GO(pAssemblyName->Clone(&pRetargetedAssemblyName)); pRetargetedAssemblyName->SetIsRetargetable(FALSE); *ppRetargetedAssemblyName = pRetargetedAssemblyName.Extract(); } else { pAssemblyName->AddRef(); *ppRetargetedAssemblyName = pAssemblyName; } } else #endif // FEATURE_CORESYSTEM { pAssemblyName->AddRef(); *ppRetargetedAssemblyName = pAssemblyName; } Exit: BINDER_LOG_LEAVE_HR(W("Compatibility::Retarget"), hr); return hr; }
HRESULT BindingLog::LogPreBindState(ApplicationContext *pApplicationContext, AssemblyName *pAssemblyName, SString &assemblyPath, PEAssembly *pParentAssembly) { HRESULT hr = S_OK; BINDER_LOG_ENTER(L"BindingLog::LogPreBindState"); PathString format; PathString info; IF_FAIL_GO(info.LoadResourceAndReturnHR(CCompRC::Debugging, ID_FUSLOG_BINDING_PRE_BIND_STATE_BEGIN)); IF_FAIL_GO(Log(info)); if (pAssemblyName != NULL) { PathString assemblyDisplayName; pAssemblyName->GetDisplayName(assemblyDisplayName, AssemblyName::INCLUDE_VERSION | AssemblyName::INCLUDE_ARCHITECTURE | AssemblyName::INCLUDE_RETARGETABLE); IF_FAIL_GO(format.LoadResourceAndReturnHR(CCompRC::Debugging, GetPreBindStateName(pAssemblyName))); info.Printf(format.GetUnicode(), assemblyDisplayName.GetUnicode()); } else { IF_FAIL_GO(format. LoadResourceAndReturnHR(CCompRC::Debugging, ID_FUSLOG_BINDING_PRE_BIND_STATE_WHERE_REF)); info.Printf(format.GetUnicode(), assemblyPath.GetUnicode()); } IF_FAIL_GO(Log(info)); if (pParentAssembly != NULL) { PathString parentAssemblyDisplayName; IF_FAIL_GO(BinderGetDisplayName(pParentAssembly, parentAssemblyDisplayName)); IF_FAIL_GO(format.LoadResourceAndReturnHR(CCompRC::Debugging, ID_FUSLOG_BINDING_PRE_BIND_STATE_CALLER)); info.Printf(format.GetUnicode(), parentAssemblyDisplayName.GetUnicode()); } else { IF_FAIL_GO(info. LoadResourceAndReturnHR(CCompRC::Debugging, ID_FUSLOG_BINDING_PRE_BIND_STATE_CALLER_UNKNOWN)); } IF_FAIL_GO(Log(info)); IF_FAIL_GO(info.LoadResourceAndReturnHR(CCompRC::Debugging, ID_FUSLOG_BINDING_PRE_BIND_STATE_END)); IF_FAIL_GO(Log(info)); Exit: BINDER_LOG_LEAVE_HR(L"BindingLog::LogPreBindState", hr); return hr; }