コード例 #1
0
ファイル: asmlink.cpp プロジェクト: ArildF/masters
HRESULT CAsmLink::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_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);
}
コード例 #2
0
ファイル: assemblymd_emit.cpp プロジェクト: 0-wiz-0/coreclr
//*******************************************************************************
// Set the specified attributes on the given ManifestResource token.
//*******************************************************************************
STDMETHODIMP RegMeta::SetManifestResourceProps(// S_OK or error.
    mdManifestResource  mr,             // [IN] ManifestResource token.
    mdToken     tkImplementation,       // [IN] mdFile or mdAssemblyRef that provides the resource.
    DWORD       dwOffset,               // [IN] Offset to the beginning of the resource within the file.
    DWORD       dwResourceFlags)        // [IN] Flags.
{
    HRESULT     hr = S_OK;

    BEGIN_ENTRYPOINT_NOTHROW;

    LOG((LOGMD, "RegMeta::SetManifestResourceProps(%#08x, %#08x, %#08x, %#08x)\n",
        mr, tkImplementation, dwOffset, 
        dwResourceFlags));
   
    _ASSERTE(TypeFromToken(tkImplementation) == mdtFile ||
              TypeFromToken(tkImplementation) == mdtAssemblyRef ||
              tkImplementation == mdTokenNil);

    START_MD_PERF();
    LOCKWRITE();
    
    IfFailGo( _SetManifestResourceProps( mr, tkImplementation, dwOffset, dwResourceFlags) );

ErrExit:
    
    STOP_MD_PERF(SetManifestResourceProps);
    END_ENTRYPOINT_NOTHROW;
    
    return hr;
} // STDMETHODIMP RegMeta::SetManifestResourceProps()
コード例 #3
0
ファイル: ceefilegenwriter.cpp プロジェクト: ArildF/masters
HRESULT CeeFileGenWriter::link()
{
    HRESULT hr = checkForErrors();
    if (! SUCCEEDED(hr))
        return hr;


    m_corHeader->Resources.VirtualAddress = VAL32(m_dwManifestRVA);
    m_corHeader->Resources.Size = VAL32(m_dwManifestSize);

    m_corHeader->StrongNameSignature.VirtualAddress = VAL32(m_dwStrongNameRVA);
    m_corHeader->StrongNameSignature.Size = VAL32(m_dwStrongNameSize);

    m_corHeader->VTableFixups.VirtualAddress = VAL32(m_dwVTableRVA);
    m_corHeader->VTableFixups.Size = VAL32(m_dwVTableSize);

    getPEWriter().setCharacteristics(
//#ifndef _WIN64
        IMAGE_FILE_32BIT_MACHINE |
//#endif
        IMAGE_FILE_EXECUTABLE_IMAGE | 
        IMAGE_FILE_LINE_NUMS_STRIPPED | 
        IMAGE_FILE_LOCAL_SYMS_STRIPPED
    );

    m_corHeader->cb = VAL32(sizeof(IMAGE_COR20_HEADER));
    m_corHeader->MajorRuntimeVersion = VAL16(COR_VERSION_MAJOR);
    m_corHeader->MinorRuntimeVersion = VAL16(COR_VERSION_MINOR);
    if (m_dllSwitch)
        getPEWriter().setCharacteristics(IMAGE_FILE_DLL);
    if (m_objSwitch)
        getPEWriter().clearCharacteristics(IMAGE_FILE_DLL | IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_LOCAL_SYMS_STRIPPED);
    m_corHeader->Flags = VAL32(m_comImageFlags);
    m_corHeader->EntryPointToken = VAL32(m_entryPoint);
    _ASSERTE(TypeFromToken(m_entryPoint) == mdtMethodDef || m_entryPoint == mdTokenNil || 
             TypeFromToken(m_entryPoint) == mdtFile);
    setDirectoryEntry(getCorHeaderSection(), IMAGE_DIRECTORY_ENTRY_COMHEADER, sizeof(IMAGE_COR20_HEADER), m_corHeaderOffset);

    if ((m_comImageFlags & COMIMAGE_FLAGS_IL_LIBRARY) == 0
        && !m_linked && !m_objSwitch)
    {
        hr = emitExeMain();
        if (FAILED(hr))
            return hr;

    }

    m_linked = true;

    IfFailRet(getPEWriter().link());

    return S_OK;
} // HRESULT CeeFileGenWriter::link()
コード例 #4
0
ファイル: asmlink.cpp プロジェクト: ArildF/masters
HRESULT CAsmLink::GetResolutionScope(mdAssembly AssemblyID, mdToken FileToken, mdToken TargetFile, mdToken* pScope)
{
    ASSERT(m_bInited && !m_bPreClosed && m_pAssem);
    ASSERT(AssemblyID == TokenFromRid(mdtAssembly, 1) || AssemblyID == AssemblyIsUBM);
    ASSERT((RidFromToken(FileToken) < m_pAssem->CountFiles() && TypeFromToken(FileToken) == mdtFile) ||
        (FileToken == AssemblyID));
    ASSERT(pScope != NULL);

    if (FileToken == TargetFile) {
        *pScope = TokenFromRid(1, mdtModule);
        return S_OK;
    }

    HRESULT hr = S_OK;
    CFile *file = NULL;
    if (FileToken == AssemblyID) {
        file = m_pAssem;
    } else {
        if (FAILED(hr = m_pAssem->GetFile(FileToken, &file)))
            return hr;
    }

    if (TypeFromToken(TargetFile) == mdtFile) {
        // make a moduleref to target file in "file"
        CFile *target;
        if (FAILED(hr = m_pAssem->GetFile(TargetFile, &target)))
            return hr;
        hr = target->MakeModuleRef(file->GetEmitScope(), pScope);
    } else if (TypeFromToken(TargetFile) == mdtModule) {
        // make a moduleref to target file in "file"
        CFile *target;
        if (FAILED(hr = m_pModules->GetFile(TargetFile, &target)))
            return hr;
        hr = target->MakeModuleRef(file->GetEmitScope(), pScope);
    } else if (TypeFromToken(TargetFile) == mdtAssembly) {
        ASSERT(TargetFile != AssemblyIsUBM);
        // make a moduleref to the manifest file in "file"
        hr = m_pAssem->MakeModuleRef(file->GetEmitScope(), pScope);
    } else if (TypeFromToken(TargetFile) == mdtAssemblyRef) {
        // make an assembly ref in "file"
        CFile *target;
        if (FAILED(hr = m_pImports->GetFile(TargetFile, &target)))
            return hr;
        if (file == m_pAssem)
            // Special Case this so we don't have to re-QI for the AssemblyEmit interface
            hr = ((CAssemblyFile*)target)->MakeAssemblyRef(m_pAssem->GetEmitter(), pScope);
        else
            hr = ((CAssemblyFile*)target)->MakeAssemblyRef(file->GetEmitScope(), pScope);
    } else
        hr = E_INVALIDARG;

    return hr;
}
コード例 #5
0
ファイル: comdynamic.cpp プロジェクト: DrewScoggins/coreclr
/*============================SetConstantValue============================
**Action: Helper to set constant value to field or parameter
**Returns:
**Arguments:
**Exceptions:
==============================================================================*/
void QCALLTYPE COMDynamicWrite::SetConstantValue(QCall::ModuleHandle pModule, UINT32 tk, DWORD valueCorType, LPVOID pValue)
{
    QCALL_CONTRACT;

    BEGIN_QCALL;

    RefClassWriter * pRCW = pModule->GetReflectionModule()->GetClassWriter(); 
    _ASSERTE(pRCW);

    HRESULT hr;

    if (TypeFromToken(tk) == mdtFieldDef)
    {
        hr = pRCW->GetEmitter()->SetFieldProps( 
            tk,                         // [IN] The FieldDef.
            ULONG_MAX,                  // [IN] Field attributes.
            valueCorType,               // [IN] Flag for the value type, selected ELEMENT_TYPE_*
            pValue,                     // [IN] Constant value.
            (ULONG) -1);                // [IN] Optional length.
    }
    else if (TypeFromToken(tk) == mdtProperty)
    {
        hr = pRCW->GetEmitter()->SetPropertyProps( 
            tk,                         // [IN] The PropertyDef.
            ULONG_MAX,                  // [IN] Property attributes.
            valueCorType,               // [IN] Flag for the value type, selected ELEMENT_TYPE_*
            pValue,                     // [IN] Constant value.
            (ULONG) -1,                 // [IN] Optional length.
            mdMethodDefNil,             // [IN] Getter method.
            mdMethodDefNil,             // [IN] Setter method.
            NULL);                      // [IN] Other methods.
    }
    else
    {
        hr = pRCW->GetEmitter()->SetParamProps( 
            tk,                   // [IN] The ParamDef.
            NULL,
            ULONG_MAX,                  // [IN] Parameter attributes.
            valueCorType,               // [IN] Flag for the value type, selected ELEMENT_TYPE_*
            pValue,                     // [IN] Constant value.
            (ULONG) -1);                // [IN] Optional length.
    }
    if (FAILED(hr)) {   
        _ASSERTE(!"Set default value is failing"); 
        COMPlusThrow(kArgumentException, W("Argument_BadConstantValue"));    
    }   

    END_QCALL;
}
コード例 #6
0
ファイル: cilVMStaticField.cpp プロジェクト: hak/criscript
/***************************************************************************
 *      get Field Value (Debugger helper)
 ***************************************************************************/
CVariable& CCilVm::getStaticField( const RID rid )
{
	assert( TypeFromToken( rid ) == MDT_FIELDDEF );
	uint32_t iIndex = RidFromToken( rid );
	assert( iIndex < m_iStaticFieldTalbeSize );
	return m_pStaticFieldTable[ iIndex ];
}
コード例 #7
0
ファイル: cilVMBind.cpp プロジェクト: hak/criscript
/***************************************************************************
 *   setStaticFieldFunctionObject
 ***************************************************************************/
bool CCilVm::setStaticFieldFunctionObject( const RID rid,
        const RID ridMethod )
{
    assert( TypeFromToken( ridMethod ) == MDT_METHODDEF );

    //Create function object and store it to static field
    CVmObject newobject;
    RID ridObj = getFunctionObjectRID();

    newobject.setRID( ridObj );
    newobject.setObjectName( getMetaData().getObjectNameRID( ridObj ) );
    newobject.setPrototypeObject( &getPrototypeObject( ridObj ) );
    newobject.setConstructorProperty( ridMethod );
    newobject.setCallProperty( ridMethod );

    getObjectPool().push_back( newobject );

    CVariable var;
    var.setObjectRef( &getObjectPool().back() );

    METHOD_DEF& method = getMetaData().getMethod( ridMethod );
    int32_t iLength = method.iNumArgments;
    assert( iLength >= 0 );

    CVariable varInt( iLength, OPERAND_FLAG_DONTENUM );
    var.refObject->setProperty( STRING_INTERNAL_LENGTH,
                                varInt );

    //Store the ObjectRef to a static field
    setStaticField( rid, var );

    return true;
}
コード例 #8
0
ファイル: assemblymd_emit.cpp プロジェクト: 0-wiz-0/coreclr
//*******************************************************************************
// Helper: Set the specified attributes on the given ExportedType token.
//*******************************************************************************
HRESULT RegMeta::_SetExportedTypeProps( // S_OK or error.
    mdExportedType   ct,                // [IN] ExportedType token.
    mdToken     tkImplementation,       // [IN] mdFile or mdAssemblyRef that provides the ExportedType.
    mdTypeDef   tkTypeDef,              // [IN] TypeDef token within the file.
    DWORD       dwExportedTypeFlags)    // [IN] Flags.
{
    ExportedTypeRec  *pRecord;
    HRESULT     hr = S_OK;

    IfFailGo(m_pStgdb->m_MiniMd.GetExportedTypeRecord(RidFromToken(ct), &pRecord));

    if(! IsNilToken(tkImplementation))
        IfFailGo(m_pStgdb->m_MiniMd.PutToken(TBL_ExportedType, ExportedTypeRec::COL_Implementation,
                                        pRecord, tkImplementation));
    if (! IsNilToken(tkTypeDef))
    {
        _ASSERTE(TypeFromToken(tkTypeDef) == mdtTypeDef);
        pRecord->SetTypeDefId(tkTypeDef);
    }
    if (dwExportedTypeFlags != ULONG_MAX)
        pRecord->SetFlags(dwExportedTypeFlags);

    IfFailGo(UpdateENCLog(ct));
ErrExit:
    return hr;
}   // RegMeta::_SetExportedTypeProps
コード例 #9
0
ファイル: cilVMStaticField.cpp プロジェクト: hak/criscript
/***************************************************************************
 *      Set Field Value (Debugger helper)
 ***************************************************************************/
bool CCilVm::setStaticField( const RID rid, const CVariable& value )
{
	assert( TypeFromToken( rid ) == MDT_FIELDDEF );
	uint32_t iIndex = RidFromToken( rid );
	m_pStaticFieldTable[ iIndex ] = value;
	return true;
}
コード例 #10
0
ファイル: asmlink.cpp プロジェクト: ArildF/masters
// Find MSCORLIB
CAssemblyFile *CAsmLink::GetStdLib()
{
    if (m_pStdLib)
        return m_pStdLib;

    // First search imports
    DWORD i, count;
    CFile *file = NULL;
    HRESULT hr;

    for (i = 0, count = m_pImports->CountFiles(); i < count; i++) {
        hr = m_pImports->GetFile(i, &file);
        if (FAILED(hr))
            break;
        if (file && file->IsStdLib())
            return (m_pStdLib = (CAssemblyFile*)file);
    }

    CComPtr<IMetaDataAssemblyImport> pAImport;
    WCHAR szFilename[MAX_PATH + MAX_PATH];
    mdFile tkFile = mdTokenNil;

    if (FAILED(m_pDisp->GetCORSystemDirectory(szFilename, lengthof(szFilename) - 12, &count)))
        return NULL;
    wcscpy(szFilename + count - 1, L"mscorlib.dll");
    if (FAILED(ImportFile( szFilename, NULL, FALSE, &tkFile, &pAImport, NULL)) || !pAImport)
        return NULL;
    ASSERT(TypeFromToken(tkFile) == mdtAssemblyRef);
    if (FAILED(m_pImports->GetFile(RidFromToken(tkFile), &file)))
        return NULL;
    if (file && file->IsStdLib())
        return (m_pStdLib = (CAssemblyFile*)file);

    return NULL;
}
コード例 #11
0
ファイル: assemblymd_emit.cpp プロジェクト: 0-wiz-0/coreclr
//*******************************************************************************
// Set the specified attributes on the given Assembly token.
//*******************************************************************************
STDMETHODIMP RegMeta::SetAssemblyProps(       // S_OK or error.
    mdAssembly  ma,                     // [IN] Assembly token.
    const void  *pbPublicKey,           // [IN] Public key of the assembly.
    ULONG       cbPublicKey,            // [IN] Count of bytes in the public key.
    ULONG       ulHashAlgId,            // [IN] Hash Algorithm.
    LPCWSTR     szName,                 // [IN] Name of the assembly.
    const ASSEMBLYMETADATA *pMetaData,  // [IN] Assembly MetaData.
    DWORD       dwAssemblyFlags)        // [IN] Flags.
{
    HRESULT hr = S_OK;
    
    BEGIN_ENTRYPOINT_NOTHROW;
    
    _ASSERTE(TypeFromToken(ma) == mdtAssembly && RidFromToken(ma));
    
    LOG((LOGMD, "RegMeta::SetAssemblyProps(%#08x, %#08x, %#08x, %#08x %S, %#08x, %#08x)\n",
        ma, pbPublicKey, cbPublicKey, ulHashAlgId, MDSTR(szName), pMetaData, dwAssemblyFlags));
    
    START_MD_PERF();
    LOCKWRITE();
    
    IfFailGo(m_pStgdb->m_MiniMd.PreUpdate());
    
    IfFailGo(_SetAssemblyProps(ma, pbPublicKey, cbPublicKey, ulHashAlgId, szName, pMetaData, dwAssemblyFlags));
    
ErrExit:
    STOP_MD_PERF(SetAssemblyProps);
    END_ENTRYPOINT_NOTHROW;
    
    return hr;
} // STDMETHODIMP SetAssemblyProps()
コード例 #12
0
ファイル: cilVMStaticField.cpp プロジェクト: hak/criscript
/***************************************************************************
 *      Store from top of the stack to a static field
 ***************************************************************************/
void CCilVm::storeStaticField( const RID rid )
{
	assert( TypeFromToken( rid ) == MDT_FIELDDEF );

	uint32_t iIndex = RidFromToken( rid );

	if( m_pStaticFieldTable[ iIndex ].getFlag() & OPERAND_FLAG_READONLY )
	{
		//Read only variable
		popEvalStack();
		return;
	}

	if( m_pStaticFieldTable[ iIndex ].getFlag() & OPERAND_FLAG_STRICT )
	{
		//Test type constraint
		storeAsRestrictedType( m_pStaticFieldTable[ iIndex ] );
		popEvalStack();
		return;
	}

	getEvalStackFirstEntry().moveTo( m_pStaticFieldTable[ iIndex ] );
	popEvalStackFast();

}
コード例 #13
0
ファイル: assemblymd_emit.cpp プロジェクト: 0-wiz-0/coreclr
//*******************************************************************************
// Set the specified attributes on the given File token.
//*******************************************************************************
STDMETHODIMP RegMeta::SetFileProps(           // S_OK or error.
    mdFile      file,                   // [IN] File token.
    const void  *pbHashValue,           // [IN] Hash Blob.
    ULONG       cbHashValue,            // [IN] Count of bytes in the Hash Blob.
    DWORD       dwFileFlags)            // [IN] Flags.
{
    HRESULT     hr = S_OK;

    BEGIN_ENTRYPOINT_NOTHROW;

    
    _ASSERTE(TypeFromToken(file) == mdtFile && RidFromToken(file));
   
    LOG((LOGMD, "RegMeta::SetFileProps(%#08x, %#08x, %#08x, %#08x)\n",
        file, pbHashValue, cbHashValue, dwFileFlags));
    START_MD_PERF();
    LOCKWRITE();
    
    IfFailGo(m_pStgdb->m_MiniMd.PreUpdate());
    
    IfFailGo( _SetFileProps(file, pbHashValue, cbHashValue, dwFileFlags) );

ErrExit:
    
    STOP_MD_PERF(SetFileProps);
    END_ENTRYPOINT_NOTHROW;
    
    return hr;
}   // RegMeta::SetFileProps
コード例 #14
0
ファイル: asmlink.cpp プロジェクト: ArildF/masters
HRESULT CAsmLink::EmitAssemblyCustomAttribute(mdAssembly AssemblyID, mdToken FileToken, mdToken tkType,
                                       void const* pCustomValue, DWORD cbCustomValue, BOOL bSecurity, BOOL bAllowMultiple)
{
    ASSERT(m_bInited && !m_bPreClosed && !m_bManifestEmitted);
    ASSERT(AssemblyID == TokenFromRid(mdtAssembly, 1) || AssemblyID == AssemblyIsUBM);
    ASSERT((RidFromToken(FileToken) < m_pAssem->CountFiles() && TypeFromToken(FileToken) == mdtFile) ||
        (FileToken == AssemblyID));

    HRESULT hr = S_OK;
    if (AssemblyID == AssemblyIsUBM) {
        CFile *file = NULL;
        if (FAILED(hr = m_pAssem->GetFile(FileToken, &file)))
            return hr;
        hr = file->AddCustomAttribute(tkType, pCustomValue, cbCustomValue, bSecurity, bAllowMultiple, NULL);
    } else if (FileToken == AssemblyID) {
        hr = m_pAssem->AddCustomAttribute(tkType, pCustomValue, cbCustomValue, bSecurity, bAllowMultiple, NULL);
    } else {
        // An assembly level custom attribute that is in the wrong scope
        CFile *file = NULL;
        if (FAILED(hr = m_pAssem->GetFile(FileToken, &file)))
            return hr;
        hr = m_pAssem->AddCustomAttribute(tkType, pCustomValue, cbCustomValue, bSecurity, bAllowMultiple, file);
    }
    return hr;
}
コード例 #15
0
BOOL    AsmMan::SetComTypeClassTok(mdToken tkClass)
{
    if((m_pCurComType)&&(TypeFromToken(tkClass)==mdtTypeDef))
    {
        m_pCurComType->tkClass = tkClass;
        return TRUE;
    }
    return FALSE;
}
コード例 #16
0
//*****************************************************************************
// Given a namespace and a class name, return the typedef
//*****************************************************************************
STDMETHODIMP RegMeta::FindTypeDefByName(// S_OK or error.
    LPCWSTR     wzTypeDef,              // [IN] Name of the Type.
    mdToken     tkEnclosingClass,       // [IN] Enclosing class.
    mdTypeDef   *ptd)                   // [OUT] Put the TypeDef token here.
{
    HRESULT     hr = S_OK;
    BEGIN_ENTRYPOINT_NOTHROW

    LOG((LOGMD, "{%08x} RegMeta::FindTypeDefByName(%S, 0x%08x, 0x%08x)\n", 
            this, MDSTR(wzTypeDef), tkEnclosingClass, ptd));
    START_MD_PERF();
    LOCKREAD();


    if (wzTypeDef == NULL)
        IfFailGo(E_INVALIDARG);
    PREFIX_ASSUME(wzTypeDef != NULL);
    LPSTR       szTypeDef;
    UTF8STR(wzTypeDef, szTypeDef);
    LPCSTR      szNamespace;
    LPCSTR      szName;

    _ASSERTE(ptd);
    _ASSERTE(TypeFromToken(tkEnclosingClass) == mdtTypeDef ||
             TypeFromToken(tkEnclosingClass) == mdtTypeRef ||
             IsNilToken(tkEnclosingClass));

    // initialize output parameter
    *ptd = mdTypeDefNil;

    ns::SplitInline(szTypeDef, szNamespace, szName);
    hr = ImportHelper::FindTypeDefByName(&(m_pStgdb->m_MiniMd), 
                                        szNamespace, 
                                        szName, 
                                        tkEnclosingClass, 
                                        ptd);
ErrExit:
    
    STOP_MD_PERF(FindTypeDefByName);
    END_ENTRYPOINT_NOTHROW;
    
    return hr;
} // STDMETHODIMP RegMeta::FindTypeDefByName()
コード例 #17
0
ファイル: ceefilegenwriter.cpp プロジェクト: ArildF/masters
HRESULT CeeFileGenWriter::checkForErrors()
{
    if (TypeFromToken(m_entryPoint) == mdtMethodDef) {
        if (m_dllSwitch) {
//          }
        } 
        return S_OK;
    }
    return S_OK;
} // HRESULT CeeFileGenWriter::checkForErrors()
コード例 #18
0
ファイル: asmlink.cpp プロジェクト: ArildF/masters
HRESULT CAsmLink::ImportTypes(mdAssembly AssemblyID, mdToken FileToken, DWORD dwScope, HALINKENUM* phEnum,
                       IMetaDataImport **ppImportScope, DWORD* pdwCountOfTypes)
{
    ASSERT(m_bInited && !m_bPreClosed);
    ASSERT(AssemblyID == TokenFromRid(mdtAssembly, 1) || AssemblyID == AssemblyIsUBM);
    ASSERT((TypeFromToken(FileToken) == mdtFile && RidFromToken(FileToken) < m_pAssem->CountFiles()) || 
        (TypeFromToken(FileToken) == mdtAssemblyRef && RidFromToken(FileToken) < m_pImports->CountFiles()) || 
        (TypeFromToken(FileToken) == mdtModule && RidFromToken(FileToken) < m_pModules->CountFiles()) ||
        FileToken == AssemblyID);
    ASSERT(dwScope == 0 || TypeFromToken(FileToken) == mdtAssemblyRef);

    // Initialize to empty values
    if (ppImportScope)
        *ppImportScope = NULL;
    if (pdwCountOfTypes)
        *pdwCountOfTypes = 0;
    *phEnum = (HALINKENUM)NULL;

    HRESULT hr = S_OK;
    TypeEnumerator *TypeEnum = new TypeEnumerator;
    if (TypeEnum == NULL)
        return E_OUTOFMEMORY;

    TypeEnum->TypeID = 0;
    if (TypeFromToken(FileToken) == mdtAssemblyRef) {
        // Import from another assembly (possibly a nested file)
        if (SUCCEEDED(hr = m_pImports->GetFile( FileToken, &TypeEnum->file)) &&
            dwScope > 0) {
            CAssemblyFile *assembly = (CAssemblyFile*)TypeEnum->file;
            TypeEnum->file = NULL;
            hr = assembly->GetFile(dwScope - 1, &TypeEnum->file);
        }
    } else if (TypeFromToken(FileToken) == mdtModule) {
        hr = m_pModules->GetFile( FileToken, &TypeEnum->file);
    } else if (TypeFromToken(FileToken) == mdtFile){
        // Import from this Assembly
        hr = m_pAssem->GetFile( FileToken, &TypeEnum->file);
    } else {
        TypeEnum->file = m_pAssem;
        hr = S_OK;
    }


    if (SUCCEEDED(hr) && SUCCEEDED(hr = TypeEnum->file->ImportFile(pdwCountOfTypes, NULL))) {
        if ((ppImportScope != NULL) && (*ppImportScope = TypeEnum->file->GetImportScope()))
            (*ppImportScope)->AddRef(); // Give a copy to them, AddRef so they can release
        if (pdwCountOfTypes)
            *pdwCountOfTypes = TypeEnum->file->CountTypes();
        *phEnum = (HALINKENUM)TypeEnum;
        if (hr == S_OK && TypeEnum->file->CountTypes() == 0)
            hr = S_FALSE;
    } else {
        delete TypeEnum;
    }
    return hr;
}
コード例 #19
0
ファイル: dasm_sz.cpp プロジェクト: ArildF/masters
unsigned SizeOfField(mdToken tk, IMDInternalImport* pImport)
{
	unsigned ret = 0xFFFFFFFF;
	if((TypeFromToken(tk) == mdtFieldDef) && RidFromToken(tk) && pImport)
	{
		PCCOR_SIGNATURE	pSig;
		ULONG		cSig;
	    pSig = pImport->GetSigOfFieldDef(tk, &cSig);
		ret = SizeOfField(&pSig,cSig,pImport);
	}
	return ret;
}
コード例 #20
0
ファイル: asmlink.cpp プロジェクト: ArildF/masters
HRESULT CAsmLink::GetAssemblyRefHash(mdToken FileToken, const void** ppvHash, DWORD* pcbHash)
{
    if (TypeFromToken(FileToken) != mdtAssemblyRef) {
        VSFAIL( "You can only get AssemblyRef hashes for assemblies!");
        return E_INVALIDARG;
    }

    HRESULT hr;
    CAssemblyFile *file = NULL;
    if (FAILED(hr = m_pImports->GetFile( FileToken, (CFile**)&file)))
        return hr;

    return file->GetHash(ppvHash, pcbHash);
}
コード例 #21
0
BOOL    AsmMan::SetComTypeImplementationTok(mdToken tk)
{
    if(m_pCurComType)
    {
        switch(TypeFromToken(tk))
        {
        case mdtAssemblyRef:
        case mdtExportedType:
        case mdtFile:
            m_pCurComType->tkImpl = tk;
            return TRUE;
        }
    }
    return FALSE;
}
コード例 #22
0
ファイル: ceegentokenmapper.cpp プロジェクト: A-And/coreclr
//*****************************************************************************
// At this point, only a select set of token values are stored for remap.
// If others should become required, this needs to get updated.
//*****************************************************************************
int CeeGenTokenMapper::IndexForType(mdToken tk)
{
#ifdef CEEGEN_TRACKED_TOKEN
#undef CEEGEN_TRACKED_TOKEN
#endif
#define CEEGEN_TRACKED_TOKEN(type) case INDEX_OF_TYPE(mdt ## type): return (tkix ## type);
    
    int iType = INDEX_OF_TYPE(TypeFromToken(tk));
    switch(iType)
    {
        CEEGEN_TRACKED_TOKENS()
    }
    
    return (-1);
}
コード例 #23
0
ファイル: info.cpp プロジェクト: ArildF/masters
//*****************************************************************************
// Retrieve a pointer to the body of a method starting at it's header.
// A method is coped by the module it lives in.  Because this function
// is designed to give a tool access to IL before it has been loaded
// by the Runtime, it uses the metadata token of the method to find
// the instance desired.  Note that this function has no effect on
// already compiled code.
//*****************************************************************************
COM_METHOD CorProfInfo::GetILFunctionBody(
	ModuleID	moduleId,
	mdMethodDef	methodId,
	LPCBYTE		*ppMethodHeader,
	ULONG		*pcbMethodSize)
{
    if (moduleId == NULL ||
        methodId == mdMethodDefNil ||
        methodId == 0 ||
        TypeFromToken(methodId) != mdtMethodDef)
        return (E_INVALIDARG);

	return g_pProfToEEInterface->GetILFunctionBody(moduleId, methodId,
				ppMethodHeader, pcbMethodSize);
}
コード例 #24
0
ファイル: cilVMStaticField.cpp プロジェクト: hak/criscript
bool CCilVm::setStaticField( const RID rid, const CVariable& value, bool bForceWriting )
{
	assert( TypeFromToken( rid ) == MDT_FIELDDEF );
	uint32_t iIndex = RidFromToken( rid );
	if( bForceWriting )
	{
		OPERAND_FLAG op = m_pStaticFieldTable[ iIndex ].getFlag();
		m_pStaticFieldTable[ iIndex ].setFlag( OPERAND_FLAG( op & ~OPERAND_FLAG_READONLY ) );
		m_pStaticFieldTable[ iIndex ] = value;
	}
	else
		m_pStaticFieldTable[ iIndex ] = value;

	return true;
}
コード例 #25
0
ファイル: info.cpp プロジェクト: ArildF/masters
//*****************************************************************************
// Replaces the method body for a function in a module.  This will replace
// the RVA of the method in the metadata to point to this new method body,
// and adjust any internal data structures as required.  This function can
// only be called on those methods which have never been compiled by a JITTER.
// Please use the GetILFunctionBodyAllocator to allocate space for the new method to
// ensure the buffer is compatible.
//*****************************************************************************
COM_METHOD CorProfInfo::SetILFunctionBody(
	ModuleID	moduleId,
	mdMethodDef	methodId,
	LPCBYTE		pbNewILMethodHeader)
{
    if (moduleId == NULL ||
        methodId == mdMethodDefNil ||
        TypeFromToken(methodId) != mdtMethodDef ||
        pbNewILMethodHeader == NULL)
    {
        return (E_INVALIDARG);
    }

	return g_pProfToEEInterface->SetILFunctionBody(moduleId, methodId,
				pbNewILMethodHeader);
}
コード例 #26
0
int GetVersionResilientTypeHashCode(IMDInternalImport *pMDImport, mdExportedType token)
{
    _ASSERTE(TypeFromToken(token) == mdtTypeDef ||
        TypeFromToken(token) == mdtTypeRef ||
        TypeFromToken(token) == mdtExportedType);
    _ASSERTE(!IsNilToken(token));

    HRESULT hr;
    LPCUTF8 szNamespace;
    LPCUTF8 szName;
    bool hasTypeToken = true;
    int hashcode = 0;

    while (hasTypeToken)
    {
        if (IsNilToken(token))
            ThrowHR(COR_E_BADIMAGEFORMAT);

        switch (TypeFromToken(token))
        {
        case mdtTypeDef:
            if (FAILED(pMDImport->GetNameOfTypeDef(token, &szName, &szNamespace)))
                ThrowHR(COR_E_BADIMAGEFORMAT);
            hr = pMDImport->GetNestedClassProps(token, &token);
            if (hr == CLDB_E_RECORD_NOTFOUND)
                hasTypeToken = false;
            else if (FAILED(hr))
                ThrowHR(COR_E_BADIMAGEFORMAT);
            break;

        case mdtTypeRef:
            if (FAILED(pMDImport->GetNameOfTypeRef(token, &szNamespace, &szName)))
                ThrowHR(COR_E_BADIMAGEFORMAT);
            if (FAILED(pMDImport->GetResolutionScopeOfTypeRef(token, &token)))
                ThrowHR(COR_E_BADIMAGEFORMAT);
            hasTypeToken = (TypeFromToken(token) == mdtTypeRef);
            break;

        case mdtExportedType:
            if (FAILED(pMDImport->GetExportedTypeProps(token, &szNamespace, &szName, &token, NULL, NULL)))
                ThrowHR(COR_E_BADIMAGEFORMAT);
            hasTypeToken = (TypeFromToken(token) == mdtExportedType);
            break;

        default:
            ThrowHR(COR_E_BADIMAGEFORMAT);
        }

        hashcode ^= ComputeNameHashCode(szNamespace, szName);
    }

    return hashcode;
}
コード例 #27
0
/***************************************************************************
 *      Load object literal onto the stack
 ***************************************************************************/
void CSystemObject::LoadobjectLiteral( CCilVm* const pVm,
										   const int32_t iNumArguments, 
										   CVariable* pArguments )
{
	assert( pVm != NULL );
	assert( iNumArguments >= 2 );
	assert( iNumArguments % 2 == 1 );

	//Skip this pointer
	pArguments++;
	int32_t i = iNumArguments;
	i--;
	CMetaData& Metadata = pVm->getMetaData();

	//Create object object
	CVmObject newobject;
	RID ridObject = pVm->getObjectRID();
	newobject.setRID( ridObject );
	newobject.setObjectName( pVm->getMetaData().getObjectNameRID( ridObject ) );
	newobject.setPrototypeObject( &pVm->getPrototypeObject( ridObject ) );

	pVm->getObjectPool().push_back( newobject );

	CVariable var;
	var.setObjectRef( &pVm->getObjectPool().back() );

	for( ; i > 0; i -= 2 )
	{
		//Argument: 1) value of the property
		//			2) string RID of the property

		RID ridString = pArguments->iValue;
		assert( TypeFromToken( ridString ) == MDT_STRING );
		pArguments++;

		wstring& str = Metadata.getStringConstant( ridString );
		var.refObject->setProperty( str, *pArguments );
		pArguments++;
	}

	//Push the ObjectRef to a eval stack
	pVm->pushEvalStackVariable( var );
	return;
}
コード例 #28
0
ファイル: assembly.hpp プロジェクト: ArildF/masters
    void PostTypeLoadException(IMDInternalImport *pInternalImport, 
                               mdToken token,
                               UINT resIDWhy, 
                               OBJECTREF *pThrowable)
    {
        LPCUTF8     szClassName = "<unknown>";
        LPCUTF8     szNameSpace = NULL;

        switch (TypeFromToken(token)) {
        case mdtTypeRef:
            pInternalImport->GetNameOfTypeRef(token, &szNameSpace, &szClassName);
            break;
        case mdtTypeDef:
            pInternalImport->GetNameOfTypeDef(token, &szClassName, &szNameSpace);
        // Leave default as "<unknown>"
        }

        PostTypeLoadException(szNameSpace, szClassName, NULL,
                              resIDWhy, pThrowable);
    }
コード例 #29
0
ファイル: asmlink.cpp プロジェクト: ArildF/masters
HRESULT CAsmLink::EmbedResource(mdAssembly AssemblyID, mdToken FileToken, LPCWSTR pszResourceName, DWORD dwOffset, DWORD dwFlags)
{
    ASSERT(m_bInited && !m_bPreClosed);
    ASSERT(AssemblyID == TokenFromRid(mdtAssembly, 1) || AssemblyID == AssemblyIsUBM);
    ASSERT((RidFromToken(FileToken) < m_pAssem->CountFiles() && TypeFromToken(FileToken) == mdtFile) ||
        (FileToken == AssemblyID));

    HRESULT hr = S_OK;
    CFile *file = NULL;
    if (AssemblyID == AssemblyIsUBM) {
        if (SUCCEEDED(hr = m_pAssem->GetFile(FileToken, &file)))
            hr = file->AddResource(mdTokenNil, pszResourceName, dwOffset, dwFlags);
    } else if (FileToken == AssemblyID) {
        hr = m_pAssem->AddResource(mdTokenNil, pszResourceName, dwOffset, dwFlags);
    } else {
        if (SUCCEEDED(hr = m_pAssem->GetFile(FileToken, &file)))
            hr = m_pAssem->AddResource(file->GetFileToken(), pszResourceName, dwOffset, dwFlags);
    }
    return hr;
}
コード例 #30
0
ファイル: custattr_import.cpp プロジェクト: Afshintm/coreclr
//*****************************************************************************
// Get information about a CustomAttribute.   
//*****************************************************************************
STDMETHODIMP RegMeta::GetCustomAttributeProps(
    mdCustomAttribute   cv,                 // The attribute token
    mdToken     *ptkObj,                // [OUT, OPTIONAL] Put object token here.
    mdToken     *ptkType,               // [OUT, OPTIONAL] Put TypeDef/TypeRef token here.
    void const  **ppBlob,               // [OUT, OPTIONAL] Put pointer to data here.
    ULONG       *pcbSize)               // [OUT, OPTIONAL] Put size of data here.
{
    HRESULT     hr = S_OK;              // A result.

    BEGIN_ENTRYPOINT_NOTHROW;

    CMiniMdRW   *pMiniMd;

    START_MD_PERF();
    LOCKREAD();

    _ASSERTE(TypeFromToken(cv) == mdtCustomAttribute);

    pMiniMd = &(m_pStgdb->m_MiniMd);
    CustomAttributeRec  *pCustomAttributeRec;   // The custom value record.

    IfFailGo(pMiniMd->GetCustomAttributeRecord(RidFromToken(cv), &pCustomAttributeRec));

    if (ptkObj)
        *ptkObj = pMiniMd->getParentOfCustomAttribute(pCustomAttributeRec);

    if (ptkType)
        *ptkType = pMiniMd->getTypeOfCustomAttribute(pCustomAttributeRec);

    if (ppBlob != NULL)
    {
        IfFailGo(pMiniMd->getValueOfCustomAttribute(pCustomAttributeRec, (const BYTE **)ppBlob, pcbSize));
    }

ErrExit:
    
    STOP_MD_PERF(GetCustomAttributeProps);
    END_ENTRYPOINT_NOTHROW;
    
    return hr;
} // RegMeta::GetCustomAttributeProps