Ejemplo n.º 1
0
        //------------------------------------------------------------
        // CAsmLink::AddImport (sscli)
        //------------------------------------------------------------
        //virtual internal HRESULT AddImport(
        //    mdAssembly AssemblyID,
        //    mdToken ImportToken,
        //    DWORD dwFlags,
        //    mdFile * pFileToken)
        //{
        //    // If we have already emitted the manifest, and then we import
        //    // a file with a CA that maps to an assembly option, we're in trouble!
        //    ASSERT(m_bInited && !m_bAssemblyEmitted && !m_bPreClosed && !m_bManifestEmitted);
        //
        //    HRESULT hr;
        //    CFile *file = NULL;
        //    if (TypeFromToken(ImportToken) == mdtModule) {
        //        ASSERT(RidFromToken(ImportToken) < m_pModules->CountFiles());
        //        hr = m_pModules->GetFile( ImportToken, &file);
        //    } else {
        //        ASSERT(TypeFromToken(ImportToken) == mdtAssemblyRef && RidFromToken(ImportToken) < m_pImports->CountFiles());
        //        hr = m_pImports->GetFile( ImportToken, &file);
        //    }
        //    if (FAILED(hr))
        //        return hr;
        //    ASSERT(file != NULL);
        //    if (FAILED(hr = m_pAssem->AddFile(file, dwFlags, pFileToken)))
        //        return hr;
        //    else if (AssemblyID == AssemblyIsUBM) {
        //        if (pFileToken)
        //            *pFileToken = ImportToken;
        //        return S_FALSE;
        //    }
        //    ASSERT(AssemblyID == TokenFromRid(mdtAssembly, 1));
        //    if (FAILED(hr = m_pModules->RemoveFile( ImportToken)))
        //        return hr;
        //    if (FAILED(hr = file->ImportFile( NULL, m_pAssem)))
        //        return hr;
        //    return file->ImportResources(m_pAssem);
        //}

        // virtual internal HRESULT  GetScope(mdAssembly AssemblyID, mdToken FileToken, DWORD dwScope, IMetaDataImport** ppImportScope);
        // virtual internal HRESULT  GetScope2(mdAssembly AssemblyID, mdToken FileToken, DWORD dwScope, IMetaDataImport2** ppImportScope);
        // virtual internal HRESULT  GetAssemblyRefHash(mdToken FileToken, const void** ppvHash, DWORD* pcbHash);
        // virtual internal HRESULT  GetPublicKeyToken(LPCWSTR pszKeyFile, LPCWSTR pszKeyContainer, void * pvPublicKeyToken, DWORD * pcbPublicKeyToken);

        //------------------------------------------------------------
        // CAsmLink.SetPEKind (1)
        //
        /// <summary>
        /// Set PE kind and machin of a given CAssemblyBuilder instance.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="peKind"></param>
        /// <param name="machine"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        virtual internal bool SetPEKind(
            CAssemblyBuilderEx builder,
            PortableExecutableKinds peKind,
            ImageFileMachine machine)
        {
            if (builder == null)
            {
                return(false);
            }
            builder.SetPEKind(peKind, machine);
            return(true);
        }
Ejemplo n.º 2
0
        //------------------------------------------------------------
        // CAsmLink::Init (sscli) (2)
        //------------------------------------------------------------
        //virtual internal HRESULT  Init(IMetaDataDispenserEx *pDispenser, IMetaDataError *pError);
        //{
        //
        //#ifdef _DEBUG
        //    DEBUG_BEGIN_IF_NZ("Break")
        //        DebugBreak();
        //    DEBUG_END_IF
        //#endif
        //    VARIANT v;
        //    HRESULT hr;
        //    ASSERT(!m_bInited && pDispenser != NULL);
        //    m_pDisp = pDispenser;
        //    m_pDisp->AddRef();
        //
        //    VariantInit(&v);
        //    if (SUCCEEDED(hr = m_pDisp->GetOption(MetaDataCheckDuplicatesFor, &v))) {
        //        V_UI4(&v) |= MDDupModuleRef | MDDupAssemblyRef | MDDupAssembly | MDDupManifestResource | MDDupExportedType;
        //        hr = m_pDisp->SetOption(MetaDataCheckDuplicatesFor, &v);
        //    }
        //
        //    if (pError != NULL) {
        //        m_pError = pError;
        //        m_pError->AddRef();
        //    } else
        //        m_pError = NULL;
        //    m_bInited = true;
        //    return hr;
        //}

        //------------------------------------------------------------
        // CAsmLink.SetAssemblyFile (1)
        //
        /// <summary>
        /// Create a CAssemblyBuilder instance.
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="flags"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        virtual internal bool SetAssemblyFile(
            string fileName,
            AssemblyFlagsEnum flags)
        {
            if (fileName == null)
            {
                fileName = "";
            }

            this.assemblyBuilderEx = new CAssemblyBuilderEx(this.controller);
            return(this.assemblyBuilderEx.Init(flags, this));
        }
Ejemplo n.º 3
0
        //------------------------------------------------------------
        // CAsmLink::ImportFileEx2 (sscli)
        //------------------------------------------------------------
        //virtual internal HRESULT  ImportFileEx2(
        //    LPCWSTR pszFilename,
        //    LPCWSTR pszTargetName,
        //    IMetaDataAssemblyImport *pAssemblyScopeIn,
        //    BOOL fSmartImport,
        //    DWORD dwOpenFlags,
        //    mdToken *pFileToken,
        //    IMetaDataAssemblyImport **ppAssemblyScope,
        //    DWORD *pdwCountOfScopes)
        //{
        //    ASSERT(m_bInited);
        //    LPWSTR newTarget = NULL;
        //    bool bNewTarget = false;
        //    bool fIsInMemory = (pAssemblyScopeIn != NULL);
        //
        //    IMetaDataAssemblyImport *pAImport = NULL;
        //    IMetaDataImport *pImport = NULL;
        //    mdAssembly tkAssembly;
        //
        //    //--------------------------------------------------
        //    // Check if pszFilename is valid.
        //    // If pszTargetName is NULL, assign pszFilename to it.
        //    //--------------------------------------------------
        //    if (pszFilename == NULL)
        //        return E_INVALIDARG;
        //    if (wcslen(pszFilename) > MAX_PATH)
        //        return FileNameTooLong(pszFilename);
        //    if (pszTargetName && wcslen(pszTargetName) > MAX_PATH)
        //        return FileNameTooLong(pszTargetName); // File name too long
        //
        //    if (pszTargetName == NULL)
        //        newTarget = VSAllocStr(pszFilename);
        //    else
        //        newTarget = VSAllocStr(pszTargetName);
        //    if (newTarget == NULL)
        //        return E_OUTOFMEMORY;
        //
        //    if (_wcsicmp(newTarget, pszFilename) == 0) {
        //    } else {
        //        bNewTarget = true;
        //    }
        //
        //    //--------------------------------------------------
        //    // If pAssemblyScopeIn is valid, use it.
        //    //--------------------------------------------------
        //    if ((pAImport = pAssemblyScopeIn) != NULL)
        //    {
        //        //EDMAURER If bNewTarget is true and the source file is not an assembly, then pAImport
        //        //must be an object from which one can QI for IID_IMetaDataEmit. And it may not be
        //        //depending on the openflags used when it was created.
        //        //Becomes an issue with UpdateModuleName () below.
        //        pAImport->AddRef();
        //    }
        //    //--------------------------------------------------
        //    // If pAssemblyScopeIn is null, search the RegMeta instance by pszFilename,
        //    // if not found, create a RegMeta instace, and use it as pAImport.
        //    //--------------------------------------------------
        //    else
        //    {
        //        if (bNewTarget && IsOfReadOnly (dwOpenFlags)) {
        //            //EDMAURER would like to also check for !IsAssembly (pszFilename) in this IF.
        //            //Massage OpenFlags such that ofReadOnly is not used. Fall back on ofRead
        //            //which was used before the introduction of ofReadOnly. That permits QI for IMetadataEmit.
        //            //This is done to satisfy the UpdateModuleName () call below.
        //            dwOpenFlags &= ~ofReadOnly;
        //            dwOpenFlags |= ofRead;
        //        }
        //
        //        // Search or create the RegMeta instance.
        //        // The metadata section is opened in the RegMeta instance.
        //        HRESULT hr = m_pDisp->OpenScope(pszFilename, dwOpenFlags, IID_IMetaDataAssemblyImport, (IUnknown**)&pAImport);
        //        if (FAILED(hr)) {
        //            *pFileToken = 0;
        //            if (ppAssemblyScope) *ppAssemblyScope = NULL;
        //            if (pdwCountOfScopes) *pdwCountOfScopes = 0;
        //            delete [] newTarget;
        //            return hr;
        //        }
        //    }
        //
        //    HRESULT hr;
        //    if (FAILED(hr = pAImport->QueryInterface( IID_IMetaDataImport, (void**)&pImport))) {
        //        *pFileToken = 0;
        //        if (ppAssemblyScope) *ppAssemblyScope = NULL;
        //        if (pdwCountOfScopes) *pdwCountOfScopes = 0;
        //        delete [] newTarget;
        //        return hr;
        //    }
        //
        //    //--------------------------------------------------
        //    // this file is not an assembly (does not have a manifest).
        //    //--------------------------------------------------
        //    if (FAILED(hr = pAImport->GetAssemblyFromScope( &tkAssembly))) {
        //
        //        hr = S_FALSE;
        //        // This is NOT an assembly
        //        if (ppAssemblyScope) *ppAssemblyScope = NULL;
        //        if (pdwCountOfScopes) *pdwCountOfScopes = 1;
        //        *pFileToken = mdTokenNil;
        //        CFile* file = new CFile();
        //        if (file == NULL) {
        //            hr = E_OUTOFMEMORY;
        //        } else if (SUCCEEDED(hr = file->Init(newTarget, pImport, m_pError, this))) {
        //            if (bNewTarget) {
        //                if (SUCCEEDED(hr = file->SetSource(pszFilename)))
        //                    hr = file->UpdateModuleName();
        //            }
        //        } else {
        //            delete file;
        //            file = NULL;
        //        }
        //        pAImport->Release();
        //        pImport->Release();
        //
        //        if (SUCCEEDED(hr) && SUCCEEDED(hr = m_pModules->AddFile( file, 0, pFileToken))) {
        //            if (fSmartImport)
        //                hr = file->ImportFile( NULL, NULL);
        //            *pFileToken = TokenFromRid(RidFromToken(*pFileToken), mdtModule);
        //        } else if (file != NULL) {
        //            delete file;
        //            file = NULL;
        //        }
        //        if (ppAssemblyScope) *ppAssemblyScope = NULL;
        //        if (SUCCEEDED(hr) && pdwCountOfScopes) *pdwCountOfScopes = 1;
        //        delete [] newTarget;
        //        return hr == S_OK ? S_FALSE : hr;
        //    }
        //    //--------------------------------------------------
        //    // this file is an assembly (has a manifest).
        //    //--------------------------------------------------
        //    else {
        //        // It is an Assembly
        //        CAssembly* assembly = new CAssembly();
        //        if (assembly == NULL) {
        //            hr = E_OUTOFMEMORY;
        //        } else if (SUCCEEDED(hr = assembly->Init( pszFilename, pAImport, pImport, m_pError, this))){
        //            if (ppAssemblyScope)
        //                *ppAssemblyScope = pAImport;
        //            else
        //                pAImport->Release();
        //            if (m_bDontDoHashes)
        //                assembly->DontDoHash();
        //            if (fIsInMemory)
        //                assembly->SetInMemory();
        //            // Get the informations of assembly, custum attributes, types.
        //            hr = assembly->ImportAssembly(pdwCountOfScopes, fSmartImport, dwOpenFlags, m_pDisp);
        //        } else {
        //            delete assembly;
        //            assembly = NULL;
        //        }
        //        pImport->Release();
        //
        //        if (SUCCEEDED(hr) && bNewTarget)
        //            hr = assembly->ReportError( ERR_CantRenameAssembly, mdTokenNil, NULL, pszFilename);
        //
        //        if (SUCCEEDED(hr) && m_pAssem != NULL)
        //            hr = m_pAssem->ComparePEKind( assembly, false);
        //
        //        delete [] newTarget;
        //        if (FAILED(hr)) {
        //            delete assembly;
        //            assembly = NULL;
        //            return hr;
        //        }
        //
        //        if (FAILED(hr = m_pImports->AddFile( assembly, 0, pFileToken)))
        //            delete assembly;
        //        return SUCCEEDED(hr) ? S_OK : hr;
        //    }
        //}

        //------------------------------------------------------------
        // CAsmLink.AddFile
        //------------------------------------------------------------
        virtual internal bool AddFile(
            OUTFILESYM outfileSym)
        {
            DebugUtil.Assert(this.inited && !this.assemblyEmitted && !this.preClosed);

            if (outfileSym.AssemblyBuilderEx != null)
            {
                this.assemblyBuilderEx = outfileSym.AssemblyBuilderEx;
                return(true);
            }
            this.assemblyBuilderEx = null;
            return(false);
        }
Ejemplo n.º 4
0
        //------------------------------------------------------------
        // CAsmLink.
        //------------------------------------------------------------
        // virtual internal HRESULT  SetAssemblyFile2(
        //    LPCWSTR pszFilename,
        //    IMetaDataEmit2 *pEmitter,
        //    AssemblyFlags afFlags,
        //    mdAssembly *pAssemblyID);

        //------------------------------------------------------------
        // CAsmLink.CreateTempAssemblyBuilder
        //
        /// <summary></summary>
        //------------------------------------------------------------
        private void CreateTempAssemblyBuilder()
        {
            Exception excp = null;

            this.tempAssemblyBuilder = new CAssemblyBuilderEx(this.controller);
            this.tempAssemblyBuilder.Init(AssemblyFlagsEnum.None, this);
            this.tempAssemblyBuilder.DefineAssembly(
                tempAssemblyBuilderName,
                null,
                AssemblyBuilderAccess.RunAndSave,
                this.controller.OptionManager,
                null,
                null,
                null,
                null,
                out excp);
        }
Ejemplo n.º 5
0
        //------------------------------------------------------------
        // CAsmLink::PreCloseAssembly (sscli)
        //------------------------------------------------------------
        //HRESULT CAsmLink::PreCloseAssembly(mdAssembly AssemblyID)
        //{
        //    ASSERT(m_bInited && !m_bPreClosed);
        //    ASSERT(AssemblyID == TokenFromRid(mdtAssembly, 1));
        //
        //    HRESULT hr = S_OK;
        //    if (!m_bAssemblyEmitted)
        //    {
        //        hr = EmitAssembly(AssemblyID);
        //    }
        //
        //    m_bPreClosed = true;
        //    m_pAssem->PreClose();
        //    return hr;
        //}

        //------------------------------------------------------------
        // CAsmLink.CloseAssembly
        //
        /// <summary>
        /// <para>Clear this.assemblyBuilderEx.</para>
        /// </summary>
        /// <param name="assemblyId"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        virtual internal bool CloseAssembly(uint assemblyId)
        {
            DebugUtil.Assert(this.inited && (this.preClosed || (assemblyId == AssemblyUtil.AssemblyIsUBM)));

            this.preClosed       = false;
            this.manifestEmitted = false;
            this.assemblyEmitted = false;
            bool br = false;

            if (assemblyId == AssemblyUtil.AssemblyIsUBM)
            {
                return(true);
            }
            else
            {
                // Sign the assembly
                br = this.assemblyBuilderEx.SignAssembly();
            }

            this.assemblyBuilderEx = null;
            return(br);
        }
Ejemplo n.º 6
0
        //------------------------------------------------------------
        // CAsmLink::SetAssemblyFile (sscli)
        //
        // #define TokenFromRid(rid,tktype) ((rid) | (tktype)) : src\inc\corhdr.h(1411)
        //------------------------------------------------------------
        //virtual internal HRESULT SetAssemblyFile(
        //    LPCWSTR pszFilename,
        //    IMetaDataEmit *pEmitter,
        //    AssemblyFlags afFlags,
        //    mdAssembly *pAssemblyID)
        //{
        //    ASSERT(m_bInited && !m_bAssemblyEmitted && !m_bPreClosed && !m_pAssem);
        //    ASSERT(pEmitter != NULL && pAssemblyID != NULL);
        //    HRESULT hr = E_FAIL;
        //
        //    // NULL filename means 'InMemory' assembly, but we need a filename so convert it to the
        //    // empty string.
        //    if (pszFilename == NULL) {
        //        ASSERT(afFlags & afInMemory);
        //        pszFilename = L"";
        //    }
        //
        //    if (FAILED(hr = SetNonAssemblyFlags(afFlags)))
        //        return hr;
        //
        //    if (wcslen(pszFilename) > MAX_PATH)
        //        return FileNameTooLong(pszFilename); // File name too long
        //
        //    CComPtr<IMetaDataAssemblyEmit> pAEmitter;
        //    hr = pEmitter->QueryInterface(IID_IMetaDataAssemblyEmit, (void**)&pAEmitter);
        //    if (SUCCEEDED(hr)) {
        //        m_pAssem = new CAssembly();
        //        if (m_pAssem == NULL) {
        //            hr = E_OUTOFMEMORY;
        //        } else if (SUCCEEDED(hr = m_pAssem->Init(pszFilename, afFlags, pAEmitter, pEmitter, m_pError, this))) {
        //            *pAssemblyID = TokenFromRid(mdtAssembly, 1);
        //        }
        //    }
        //
        //    return hr;
        //}

        //------------------------------------------------------------
        // CAsmLink.SetAssemblyFile (2)
        //
        /// <summary></summary>
        /// <param name="builder"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        virtual internal bool SetAssemblyFile(CAssemblyBuilderEx builder)
        {
            this.assemblyBuilderEx = builder;
            return(this.assemblyBuilderEx != null);
        }