-
Notifications
You must be signed in to change notification settings - Fork 27
/
ProcessElf.h
87 lines (78 loc) · 2.43 KB
/
ProcessElf.h
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
77
78
79
80
81
82
83
84
85
86
87
/***************************************************************
* PRXTool : Utility for PSP executables.
* (c) TyRaNiD 2k5
*
* ProcessElf.h - Definition of a class to process ELF files.
***************************************************************/
#ifndef __PROCESS_ELF__
#define __PROCESS_ELF__
#include "types.h"
#include "elftypes.h"
class CProcessElf
{
protected:
/* Pointers to the original elf and a binary image of the elf */
u8 *m_pElf;
u32 m_iElfSize;
u8 *m_pElfBin;
u32 m_iBinSize;
bool m_blElfLoaded;
char m_szFilename[MAXPATH];
/* List of sections */
ElfSection *m_pElfSections;
/* Number of elf section headers */
int m_iSHCount;
/* Pointer to the program headers */
ElfProgram *m_pElfPrograms;
/* Number of elf program headers */
int m_iPHCount;
/* Pointer to the string table section */
ElfSection *m_pElfStrtab;
/* Holds the elf header information */
ElfHeader m_elfHeader;
/* List of symbols */
ElfSymbol *m_pElfSymbols;
/* Number of symbols */
int m_iSymCount;
/* The base address of the ELF */
u32 m_iBaseAddr;
const char *GetSymbolName(u32 name, u32 shndx);
void ElfLoadHeader(const Elf32_Ehdr* pHeader);
bool ElfValidateHeader();
void ElfDumpHeader();
bool BuildBinaryImage();
bool BuildFakeSections(unsigned int dwDataBase);
u8* LoadFileToMem(const char *szFilename, u32 &lSize);
bool LoadPrograms();
bool FillSection(ElfSection& elfSect, const Elf32_Shdr *pSection);
void ElfDumpSections();
bool LoadSections();
bool LoadSymbols();
void FreeMemory();
public:
/** Default constructor */
CProcessElf();
/** Virtual destructor */
virtual ~CProcessElf();
/** Load an ELF from a file */
virtual bool LoadFromFile(const char *szFilename);
/** Load a binary file */
virtual bool LoadFromBinFile(const char *szFilename, unsigned int dwDataBase);
/** Find an elf section based on its name */
ElfSection *ElfFindSection(const char* szName);
/** Find an elf section based on its address */
ElfSection *ElfFindSectionByAddr(unsigned int dwAddr);
/** Determine if a section is a data section */
bool ElfAddrIsText(unsigned int dwAddr);
/** Get the base address of the ELF */
u32 ElfGetBaseAddr();
/** Get the top address of the ELF */
u32 ElfGetTopAddr();
/** Get the size of the loaded ELF (as would be loaded in memory) */
u32 ElfGetLoadSize();
/** Get the section headers */
ElfSection* ElfGetSections(u32 &iSHCount);
/** Get the file name of the loaded elf */
const char* GetElfName();
};
#endif