aboutsummaryrefslogtreecommitdiff
path: root/src/processor/exploitability_linux.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/processor/exploitability_linux.cc')
-rw-r--r--src/processor/exploitability_linux.cc44
1 files changed, 30 insertions, 14 deletions
diff --git a/src/processor/exploitability_linux.cc b/src/processor/exploitability_linux.cc
index a196da79..c520059c 100644
--- a/src/processor/exploitability_linux.cc
+++ b/src/processor/exploitability_linux.cc
@@ -231,21 +231,10 @@ bool ExploitabilityLinux::EndedOnIllegalWrite(uint64_t instruction_ptr) {
MAX_OBJDUMP_BUFFER_LEN,
objdump_output_buffer);
- // Put buffer data into stream to output line-by-line.
- std::stringstream objdump_stream;
- objdump_stream.str(string(objdump_output_buffer));
string line;
-
- // Pipe each output line into the string until the string contains
- // the first instruction from objdump.
- // Loop until the line shows the first instruction or there are no lines left.
- do {
- if (!getline(objdump_stream, line)) {
- BPLOG(INFO) << "Objdump instructions not found";
- return false;
- }
- } while (line.find("0:") == string::npos);
- // This first instruction contains the above substring.
+ if (!GetObjdumpInstructionLine(objdump_output_buffer, &line)) {
+ return false;
+ }
// Convert objdump instruction line into the operation and operands.
string instruction = "";
@@ -399,6 +388,33 @@ bool ExploitabilityLinux::CalculateAddress(const string &address_expression,
return true;
}
+// static
+bool ExploitabilityLinux::GetObjdumpInstructionLine(
+ const char *objdump_output_buffer,
+ string *instruction_line) {
+ // Put buffer data into stream to output line-by-line.
+ std::stringstream objdump_stream;
+ objdump_stream.str(string(objdump_output_buffer));
+
+ // Pipe each output line into the string until the string contains the first
+ // instruction from objdump. All lines before the "<.data>:" section are
+ // skipped. Loop until the line shows the first instruction or there are no
+ // lines left.
+ bool data_section_seen = false;
+ do {
+ if (!getline(objdump_stream, *instruction_line)) {
+ BPLOG(INFO) << "Objdump instructions not found";
+ return false;
+ }
+ if (instruction_line->find("<.data>:") != string::npos) {
+ data_section_seen = true;
+ }
+ } while (!data_section_seen || instruction_line->find("0:") == string::npos);
+ // This first instruction contains the above substring.
+
+ return true;
+}
+
bool ExploitabilityLinux::TokenizeObjdumpInstruction(const string &line,
string *operation,
string *dest,