-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElfParser.h
More file actions
61 lines (50 loc) · 1.52 KB
/
ElfParser.h
File metadata and controls
61 lines (50 loc) · 1.52 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
#pragma once
#include <ElfHeader.h>
#include <InstructionFabric.h>
#include <ProgrammHeader.h>
#include <SectionHeader.h>
#include <SymTabEntry.h>
#include <SymTabInfoEnum.h>
#include <fstream>
#include <sstream>
#include <vector>
class ElfParser {
static constexpr uint8_t SYM_TAB = 2;
static constexpr uint8_t STR_TAB = 3;
public:
explicit ElfParser(std::ifstream& f);
~ElfParser();
void parse();
void printDotText(std::ostream& out);
void printSymtab(std::ostream& out) const;
private:
std::ifstream& file;
ElfHeader elfHeader;
ProgrammHeader* programHeaders;
int bufferOffset; // offset of address in buff relative to file
SectionHeader* sectionHeaders;
// SYM_TAB
uint32_t symTabAddress;
uint32_t symTabEntrySize;
uint32_t symTabEntriesCount;
SymTabEntry* symTableEntries;
// STR_TAB
uint32_t strTabAddress;
uint32_t strTabSize;
void fillStrTab(const char* buff);
char* strTab;
// SH_STR_TAB
uint32_t shStrTabAddress;
uint32_t shStrTabSize;
void fillShStrTab(const char* buff);
char* shStrTab;
std::string getStringFromStrTab(uint32_t offset) const;
std::string getStringFromShStrTab(uint32_t offset) const;
// .text
uint32_t textAddress;
uint32_t textVirtualAddress;
uint32_t textSize;
std::vector<Instruction*> instructions;
std::unordered_map<uint32_t, std::string> labels;
// std::unordered_map<uint32_t, int> addressLabels;
};