This repository has been archived by the owner on Jan 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
objdumpparser.cpp
59 lines (50 loc) · 1.77 KB
/
objdumpparser.cpp
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
#include "objdumpparser.h"
ObjdumpParser::ObjdumpParser(const char* objdumpFile) {
this->objdumpFile = objdumpFile;
}
enum ObjdumpParseState {
searchPLT, searchPLTAddress
};
void ObjdumpParser::parseObjdump(std::vector<ADDRINT> &pltFunctions) {
std::ifstream csFile(this->objdumpFile);
std::string line;
std::string pltSection = "Disassembly of section .plt:";
std::string nextSection = "Disassembly of section";
std::string malloc = "malloc";
std::string cppNew = "Znwm";
ObjdumpParseState curState = searchPLT;
while (std::getline(csFile, line)) {
if (curState == searchPLT) {
if (!line.compare(0, pltSection.size(), pltSection)) {
std::cout << "parseObjdump: found plt section: " << line
<< std::endl;
curState = searchPLTAddress;
}
} else if (curState == searchPLTAddress) {
if (!line.compare(0, nextSection.size(), nextSection)) {
std::cout << "parseObjdump: found end of plt section: " << line
<< std::endl;
return;
// We need to skip the malloc entry, as this is an allowed plt call
} else if (line.find("@") != string::npos
&& line.find(malloc) == string::npos
&& line.find("@") != string::npos
&& line.find(cppNew) == string::npos) {
std::cout << "parseObjdump: found address: " << line
<< std::endl;
std::size_t found = line.find(" ");
std::size_t start = 0;
std::string address = line.substr(start, found);
std::cout << "\t: extracted address: " << address << std::endl;
unsigned long addressLong = strtol(address.c_str(), NULL, 16)
- 0x400000;
std::cout << "\t: converted address: " << std::hex
<< addressLong << std::endl;
pltFunctions.push_back(addressLong);
} else {
std::cout << "parseObjdump: skipping line: " << line
<< std::endl;
}
}
}
}