示例#1
0
    /* 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;
    }
示例#2
0
文件: utils.cpp 项目: A-And/coreclr
    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;
    }
示例#3
0
    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;
    }
示例#4
0
    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;
    }
示例#5
0
    /* 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;
    }                               
示例#6
0
    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;
    }
示例#7
0
    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;
    }
示例#8
0
    /* 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;
    }                               
示例#9
0
    /* 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;
    }
示例#10
0
    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;
    }