//***************************************************************************** // Pull the PEKind and Machine out of PE headers -- if we have PE headers. //***************************************************************************** HRESULT CLiteWeightStgdbRW::GetPEKind( // S_OK or error. MAPPINGTYPE mtMapping, // The type of mapping the image has DWORD *pdwPEKind, // [OUT] The kind of PE (0 - not a PE) DWORD *pdwMachine) // [OUT] Machine as defined in NT header { HRESULT hr = NOERROR; DWORD dwKind=0; // Working copy of pe kind. DWORD dwMachine=0; // Working copy of machine. #ifndef DACCESS_COMPILE // Do we already have cached information? if (m_dwPEKind != (DWORD)(-1)) { dwKind = m_dwPEKind; dwMachine = m_dwMachine; } else if (m_pImage) { NewHolder<PEDecoder> pe; EX_TRY { // We need to use different PEDecoder constructors based on the type of data we give it. // We use the one with a 'bool' as the second argument when dealing with a mapped file, // and we use the one that takes a COUNT_T as the second argument when dealing with a // flat file. if (mtMapping == MTYPE_IMAGE) pe = new (nothrow) PEDecoder(m_pImage, false); else pe = new (nothrow) PEDecoder(m_pImage, (COUNT_T)(m_dwImageSize)); } EX_CATCH { hr = COR_E_BADIMAGEFORMAT; } EX_END_CATCH(SwallowAllExceptions) IfFailRet(hr); IfNullRet(pe); if (pe->HasContents() && pe->HasNTHeaders()) { pe->GetPEKindAndMachine(&dwKind,&dwMachine); // Cache entries. m_dwPEKind = dwKind; m_dwMachine = dwMachine; } else // if (pe.HasContents()... hr = COR_E_BADIMAGEFORMAT; } // if (m_pImage) else