summaryrefslogtreecommitdiff
path: root/src/ildasm/ceeload.h
blob: 7231a89ef727633c5b18d6a41b6882ccef3af0d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// ===========================================================================
// File: CEELOAD.H
// 

// CEELOAD.H defines the class use to represent the PE file
// ===========================================================================
#ifndef CEELoad_H 
#define CEELoad_H

class PELoader;

//
// Used to cache information about sections we're interested in (descr, callsig, il)
//
class SectionInfo
{
public:
    BYTE *  m_pSection;         // pointer to the beginning of the section
    DWORD   m_dwSectionOffset;  // RVA
    DWORD   m_dwSectionSize;    

    // init this class's member variables from the provided directory
    void Init(PELoader *pPELoader, IMAGE_DATA_DIRECTORY *dir);

    // returns whether this RVA is inside the section
    BOOL InSection(DWORD dwRVA)
    {
        return (dwRVA >= m_dwSectionOffset) && (dwRVA < m_dwSectionOffset + m_dwSectionSize);
    }
};

class PELoader {
  protected:

    HMODULE m_hMod;
    HANDLE m_hFile;
    HANDLE m_hMapFile;
    BOOL   m_bIsPE32;
    size_t m_FileSize;
    size_t m_FileSizeAligned;

    union
    {
        PIMAGE_NT_HEADERS64	m_pNT64;	
        PIMAGE_NT_HEADERS32 m_pNT32;
    };

  public:
    SectionInfo m_DescrSection;
    SectionInfo m_CallSigSection;
    SectionInfo m_ILSection;

    PELoader();
    ~PELoader();
    BOOL open(const char* moduleNameIn);
    BOOL open(const WCHAR* moduleNameIn);
    BOOL open(HMODULE hMod);
    BOOL getCOMHeader(IMAGE_COR20_HEADER **ppCorHeader);
    BOOL getVAforRVA(DWORD rva,void **ppCorHeader);
    void close();
    void dump();
    inline BOOL IsPE32() { return m_bIsPE32; };
    inline PIMAGE_NT_HEADERS32 ntHeaders32() { return m_pNT32; };
    inline PIMAGE_NT_HEADERS64 ntHeaders64() { return m_pNT64; };
    inline PIMAGE_DOS_HEADER dosHeader() { return (PIMAGE_DOS_HEADER)m_hMod; };
    inline PIMAGE_FILE_HEADER coffHeader() { return &(m_pNT32->FileHeader); };
    inline DWORD Signature() { return m_pNT32->Signature; };
    inline BYTE*  base() { return (BYTE*) m_hMod; };
    inline HMODULE getHModule() { return  m_hMod; };
    inline HANDLE getHFile()	{ return  m_hFile; } ;
};

#endif // CEELoad_H