-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathelfbinary.h
More file actions
121 lines (94 loc) · 2.88 KB
/
elfbinary.h
File metadata and controls
121 lines (94 loc) · 2.88 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* line - Line Is Not an Emulator
* Copyright (C) 2016 GeekProjects.com
*
* This file is part of line.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __LINE_ELFBINARY_H_
#define __LINE_ELFBINARY_H_
#include "elf.h"
#include "logger.h"
#include <vector>
#include <map>
#define ALIGN(_v, _a) (((_v) + _a - 1) & ~(_a - 1))
class Line;
class ElfExec;
class ElfLibrary;
class LibraryEntry;
class LineProcess;
class ElfBinary;
struct IFuncRela
{
Elf64_Rela* rela;
Elf64_Sym* symbol;
ElfBinary* lib;
};
class ElfBinary : public Logger
{
protected:
Line* m_line;
ElfExec* m_exec;
char* m_path;
char* m_image;
Elf64_Ehdr* m_header;
char* m_shStringTable;
char* m_stringTable;
uint64_t m_end;
uint64_t m_base;
std::map<std::string, Elf64_Sym*> m_symbols;
std::vector<IFuncRela> m_ifuncRelas;
Elf64_Shdr* m_symbolSection;
int m_tlsBase;
int m_tlsSize;
std::vector<uint64_t> m_needed;
std::map<uint64_t, uint64_t> m_dyn;
Elf64_Shdr* findSection(const char* name);
bool readDynamicHeader(Elf64_Phdr* header);
bool mapStatic();
bool mapDynamic();
void relocateRela(Elf64_Rela* rela, uint64_t base, Elf64_Sym* symtab, const char* strtab);
public:
ElfBinary(Line* line);
virtual ~ElfBinary();
bool load(const char* path);
const char* getString(int name);
Elf64_Sym* findSymbol(const char* sym);
bool map();
uint64_t getEnd() { return m_end; }
void setBase(uint64_t base) { m_base = base; }
uint64_t getBase() { return m_base; }
bool loadLibraries();
ElfLibrary* loadLibrary(const char* file, bool init = false, int argc = 0, char** argv = NULL, char** env = NULL);
virtual bool relocate();
bool relocateIFuncs();
char* getPath() { return m_path; }
int getTLSSize() { return m_tlsSize; }
void setTLSBase(int tlsbase) { m_tlsBase = tlsbase; }
int getTLSBase() { return m_tlsBase; }
void initTLS(void* tls);
void setDynValue(uint64_t tag, uint64_t value) { m_dyn.insert(std::make_pair(tag, value)); }
uint64_t getDynValue(uint64_t tag)
{
std::map<uint64_t, uint64_t>::iterator it;
it = m_dyn.find(tag);
if (it != m_dyn.end())
{
return it->second;
}
return 0;
}
};
#endif