-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElfParser.h
More file actions
103 lines (85 loc) · 2.87 KB
/
ElfParser.h
File metadata and controls
103 lines (85 loc) · 2.87 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef ELFPARSER_H
#define ELFPARSER_H
class ElfParser
{
public:
struct tsELFHeaderInfo
{
bool bValid;
bool b32bit;
bool b64bit;
bool bLittleEndian;
bool bBigEndian;
unsigned char ucELFVersion;
unsigned char ucOSABI;
unsigned char ucABIVersion;
unsigned short sType;
unsigned short sInstructionSetID;
unsigned int unELFVersion;
unsigned long long ullProgramEntryPos;
unsigned long long ullProgramHeaderOffset;
unsigned long long ullSectionHeaderOffset;
unsigned int unFlags;
unsigned short usELFHeaderSize;
unsigned short usProgramHeaderEntrySize;
unsigned short usProgramHeaderNumberOfEntries;
unsigned short usSectionHeaderEntrySize;
unsigned short usSectionHeaderNumberOfEntries;
unsigned short usStringTableSectionIndex;
};
struct tsSectionHeaderInfo
{
unsigned int unSectionID;
unsigned int unSectionNameIndex;
unsigned int unSectionType;
unsigned long long ullSectionFlags;
unsigned long long ullSectionAddress;
unsigned long long ullSectionOffset;
unsigned long long ullSectionSize;
unsigned int unSectionHeaderIndex;
unsigned int unSectionInfo;
unsigned long long ullSectionAddressAllignment;
unsigned long long ullSectionEntrySize;
char* cpSectionName;
};
struct tsSymbolInfo
{
unsigned int unSymbolID;
unsigned int unSymbolNameIndex;
unsigned long long ullSymbolValue;
unsigned long long ullSymbolSize;
unsigned char ucSymbolInfo;
unsigned char ucSymbolOther;
unsigned short usBoundSectionHeaderIndex;
char* cpSymbolName;
};
ElfParser(char* cpFileName);
ElfParser(unsigned char* ucpBuffer, unsigned int unBufferLength);
~ElfParser();
static bool ParseHeader(char* cpFileName, tsELFHeaderInfo* stpHeaderInfo);
static bool ParseHeader(unsigned char* ucpBuffer, int nBufferLength, tsELFHeaderInfo* stpHeaderInfo);
static void PrintHeaderInfo(tsELFHeaderInfo stHeaderInfo);
static void ParseSection(unsigned char* ucpBuffer, unsigned int unSectionStartIndex, bool bIs32bit, bool bIsLittleEndian, tsSectionHeaderInfo* stResults,
unsigned int unStringTableIndex = -1);
static void PrintSectionHeaderInfo(tsSectionHeaderInfo stStructHeader);
static void ParseSymbolInfo(unsigned char* ucpBuffer, unsigned int unSymbolStartIndex, bool bIs32bit, bool bIsLittleEndian, tsSymbolInfo* stResults,
unsigned int unStringTableIndex = -1);
static void PrintSymbolInfo(tsSymbolInfo stSymbolInfo);
//static int getStringTableSectionID(tsSectionHeaderInfo* stpSectionHeaderArray);
bool ParseHeader();
void PrintHeaderInfo();
void ParseAllSections();
void PrintAllSectionHeaderInfo();
void ParseAllSymbols();
void PrintAllSymbolInfo();
unsigned int unSymbolSectionID;
unsigned int unSymbolCount;
unsigned int unStrtabSectionID;
tsELFHeaderInfo stELFHeaderInfo;
tsSectionHeaderInfo* stpSectionHeaderInfo;
tsSymbolInfo* stpSymbolInfo;
private:
unsigned char* ucpFileBuffer;
unsigned int unFileSize;
};
#endif