| 1 | // Licensed to the .NET Foundation under one or more agreements. |
|---|---|
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | // =========================================================================== |
| 5 | // File: CEELOAD.H |
| 6 | // |
| 7 | |
| 8 | // CEELOAD.H defines the class use to represent the PE file |
| 9 | // =========================================================================== |
| 10 | #ifndef CEELoad_H |
| 11 | #define CEELoad_H |
| 12 | |
| 13 | class PELoader; |
| 14 | |
| 15 | // |
| 16 | // Used to cache information about sections we're interested in (descr, callsig, il) |
| 17 | // |
| 18 | class SectionInfo |
| 19 | { |
| 20 | public: |
| 21 | BYTE * m_pSection; // pointer to the beginning of the section |
| 22 | DWORD m_dwSectionOffset; // RVA |
| 23 | DWORD m_dwSectionSize; |
| 24 | |
| 25 | // init this class's member variables from the provided directory |
| 26 | void Init(PELoader *pPELoader, IMAGE_DATA_DIRECTORY *dir); |
| 27 | |
| 28 | // returns whether this RVA is inside the section |
| 29 | BOOL InSection(DWORD dwRVA) |
| 30 | { |
| 31 | return (dwRVA >= m_dwSectionOffset) && (dwRVA < m_dwSectionOffset + m_dwSectionSize); |
| 32 | } |
| 33 | }; |
| 34 | |
| 35 | class PELoader { |
| 36 | protected: |
| 37 | |
| 38 | HMODULE m_hMod; |
| 39 | HANDLE m_hFile; |
| 40 | HANDLE m_hMapFile; |
| 41 | BOOL m_bIsPE32; |
| 42 | size_t m_FileSize; |
| 43 | size_t m_FileSizeAligned; |
| 44 | |
| 45 | union |
| 46 | { |
| 47 | PIMAGE_NT_HEADERS64 m_pNT64; |
| 48 | PIMAGE_NT_HEADERS32 m_pNT32; |
| 49 | }; |
| 50 | |
| 51 | public: |
| 52 | SectionInfo m_DescrSection; |
| 53 | SectionInfo m_CallSigSection; |
| 54 | SectionInfo m_ILSection; |
| 55 | |
| 56 | PELoader(); |
| 57 | ~PELoader(); |
| 58 | BOOL open(const char* moduleNameIn); |
| 59 | BOOL open(const WCHAR* moduleNameIn); |
| 60 | BOOL open(HMODULE hMod); |
| 61 | BOOL getCOMHeader(IMAGE_COR20_HEADER **ppCorHeader); |
| 62 | BOOL getVAforRVA(DWORD rva,void **ppCorHeader); |
| 63 | void close(); |
| 64 | void dump(); |
| 65 | inline BOOL IsPE32() { return m_bIsPE32; }; |
| 66 | inline PIMAGE_NT_HEADERS32 ntHeaders32() { return m_pNT32; }; |
| 67 | inline PIMAGE_NT_HEADERS64 ntHeaders64() { return m_pNT64; }; |
| 68 | inline PIMAGE_DOS_HEADER dosHeader() { return (PIMAGE_DOS_HEADER)m_hMod; }; |
| 69 | inline PIMAGE_FILE_HEADER coffHeader() { return &(m_pNT32->FileHeader); }; |
| 70 | inline DWORD Signature() { return m_pNT32->Signature; }; |
| 71 | inline BYTE* base() { return (BYTE*) m_hMod; }; |
| 72 | inline HMODULE getHModule() { return m_hMod; }; |
| 73 | inline HANDLE getHFile() { return m_hFile; } ; |
| 74 | }; |
| 75 | |
| 76 | #endif // CEELoad_H |
| 77 |