HRESULT CeeFileGenWriter::setManifestEntry(ULONG size, ULONG offset) { if (offset) m_dwManifestRVA = offset; else { CeeSection TextSection = getTextSection(); getMethodRVA(TextSection.dataLen() - size, &m_dwManifestRVA); } m_dwManifestSize = size; return S_OK; } // HRESULT CeeFileGenWriter::setManifestEntry()
HRESULT CeeFileGenWriter::setVTableEntry(ULONG size, ULONG offset) { if (offset && size) { void * pv; CeeSection TextSection = getTextSection(); getMethodRVA(TextSection.dataLen(), &m_dwVTableRVA); if((pv = TextSection.getBlock(size))) memcpy(pv,(void *)offset,size); else return E_OUTOFMEMORY; m_dwVTableSize = size; } return S_OK; } // HRESULT CeeFileGenWriter::setVTableEntry()
HRESULT CeeFileGenWriter::MapTokens( CeeGenTokenMapper *pMapper, IMetaDataImport *pImport) { mdTypeDef td; mdMethodDef md; ULONG count; ULONG MethodRVA; ULONG codeOffset; ULONG BaseRVA; DWORD dwFlags; DWORD iFlags; HCORENUM hTypeDefs = 0, hEnum = 0; WCHAR rcwName[MAX_CLASSNAME_LENGTH]; HRESULT hr; CeeSection TextSection = getTextSection(); // Ask for the base RVA of the first method in the stream. All other // method RVA's are >= that value, and will give us the raw offset required. hr = getMethodRVA(0, &BaseRVA); _ASSERTE(SUCCEEDED(hr)); // do globals first while ((hr = pImport->EnumMethods(&hEnum, mdTokenNil, &md, 1, &count)) == S_OK) { hr = pImport->GetMethodProps(md, NULL, rcwName, lengthof(rcwName), NULL, &dwFlags, NULL, NULL, &MethodRVA, &iFlags); _ASSERTE(SUCCEEDED(hr)); if (MethodRVA == 0 || ((IsMdAbstract(dwFlags) || IsMiInternalCall(iFlags)) || (! IsMiIL(iFlags) && ! IsMiOPTIL(iFlags)))) continue; // The raw offset of the method is the RVA in the image minus // the first method in the text section. codeOffset = MethodRVA - BaseRVA; hr = MapTokensForMethod(pMapper, (BYTE *) TextSection.computePointer(codeOffset), rcwName); if (FAILED(hr)) goto ErrExit; } if (hEnum) pImport->CloseEnum(hEnum); hEnum = 0; while ((hr = pImport->EnumTypeDefs(&hTypeDefs, &td, 1, &count)) == S_OK) { while ((hr = pImport->EnumMethods(&hEnum, td, &md, 1, &count)) == S_OK) { hr = pImport->GetMethodProps(md, NULL, rcwName, lengthof(rcwName), NULL, &dwFlags, NULL, NULL, &MethodRVA, &iFlags); _ASSERTE(SUCCEEDED(hr)); if (MethodRVA == 0 || ((IsMdAbstract(dwFlags) || IsMiInternalCall(iFlags)) || (! IsMiIL(iFlags) && ! IsMiOPTIL(iFlags)))) continue; // The raw offset of the method is the RVA in the image minus // the first method in the text section. codeOffset = MethodRVA - BaseRVA; hr = MapTokensForMethod(pMapper, (BYTE *) TextSection.computePointer(codeOffset), rcwName); if (FAILED(hr)) goto ErrExit; } if (hEnum) pImport->CloseEnum(hEnum); hEnum = 0; } ErrExit: if (hTypeDefs) pImport->CloseEnum(hTypeDefs); if (hEnum) pImport->CloseEnum(hEnum); return (hr); }