OLD | NEW |
---|---|
1 // Copyright (c) 2013 Google Inc. | 1 // Copyright (c) 2013 Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 return false; | 224 return false; |
225 } | 225 } |
226 | 226 |
227 // Convert bytes into objdump output. | 227 // Convert bytes into objdump output. |
228 char objdump_output_buffer[MAX_OBJDUMP_BUFFER_LEN] = {0}; | 228 char objdump_output_buffer[MAX_OBJDUMP_BUFFER_LEN] = {0}; |
229 DisassembleBytes(architecture, | 229 DisassembleBytes(architecture, |
230 raw_memory + offset, | 230 raw_memory + offset, |
231 MAX_OBJDUMP_BUFFER_LEN, | 231 MAX_OBJDUMP_BUFFER_LEN, |
232 objdump_output_buffer); | 232 objdump_output_buffer); |
233 | 233 |
234 // Put buffer data into stream to output line-by-line. | |
235 std::stringstream objdump_stream; | |
236 objdump_stream.str(string(objdump_output_buffer)); | |
237 string line; | 234 string line; |
238 | 235 if (!GetObjdumpInstructionLine(objdump_output_buffer, &line)) { |
239 // Pipe each output line into the string until the string contains | 236 return false; |
240 // the first instruction from objdump. | 237 } |
241 // Loop until the line shows the first instruction or there are no lines left. | |
242 do { | |
243 if (!getline(objdump_stream, line)) { | |
244 BPLOG(INFO) << "Objdump instructions not found"; | |
245 return false; | |
246 } | |
247 } while (line.find("0:") == string::npos); | |
248 // This first instruction contains the above substring. | |
249 | 238 |
250 // Convert objdump instruction line into the operation and operands. | 239 // Convert objdump instruction line into the operation and operands. |
251 string instruction = ""; | 240 string instruction = ""; |
252 string dest = ""; | 241 string dest = ""; |
253 string src = ""; | 242 string src = ""; |
254 TokenizeObjdumpInstruction(line, &instruction, &dest, &src); | 243 TokenizeObjdumpInstruction(line, &instruction, &dest, &src); |
255 | 244 |
256 // Check if the operation is a write to memory. First, the instruction | 245 // Check if the operation is a write to memory. First, the instruction |
257 // must one that can write to memory. Second, the write destination | 246 // must one that can write to memory. Second, the write destination |
258 // must be a spot in memory rather than a register. Since there are no | 247 // must be a spot in memory rather than a register. Since there are no |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 } | 381 } |
393 | 382 |
394 // Add or subtract constant from write address (if applicable). | 383 // Add or subtract constant from write address (if applicable). |
395 *write_address = | 384 *write_address = |
396 positive_add_constant ? | 385 positive_add_constant ? |
397 *write_address + add_constant : *write_address - add_constant; | 386 *write_address + add_constant : *write_address - add_constant; |
398 | 387 |
399 return true; | 388 return true; |
400 } | 389 } |
401 | 390 |
391 // static | |
392 bool ExploitabilityLinux::GetObjdumpInstructionLine( | |
393 const char *objdump_output_buffer, | |
394 string *instruction_line) { | |
395 // Put buffer data into stream to output line-by-line. | |
396 std::stringstream objdump_stream; | |
397 objdump_stream.str(string(objdump_output_buffer)); | |
398 | |
399 // Pipe each output line into the string until the string contains the first | |
400 // instruction from objdump. All lines before the "<.data>:" section are | |
401 // skipped. Loop until the line shows the first instruction or there are no | |
402 // lines left. | |
403 bool data_section_seen = false; | |
404 do { | |
405 if (!getline(objdump_stream, *instruction_line)) { | |
Mark Mentovai
2016/02/17 02:24:18
std::getline
ivanpe
2016/02/17 06:27:41
I'll handle this in a new CL.
| |
406 BPLOG(INFO) << "Objdump instructions not found"; | |
407 return false; | |
408 } | |
409 if (instruction_line->find("<.data>:") != string::npos) { | |
410 data_section_seen = true; | |
411 } | |
Mark Mentovai
2016/02/17 02:24:18
At some point after seeing <.data>:, if you enter
ivanpe
2016/02/17 06:27:41
Here, we are parsing the output of objdump. objdu
| |
412 } while (!data_section_seen || instruction_line->find("0:") == string::npos); | |
413 // This first instruction contains the above substring. | |
414 | |
415 return true; | |
416 } | |
417 | |
402 bool ExploitabilityLinux::TokenizeObjdumpInstruction(const string &line, | 418 bool ExploitabilityLinux::TokenizeObjdumpInstruction(const string &line, |
403 string *operation, | 419 string *operation, |
404 string *dest, | 420 string *dest, |
405 string *src) { | 421 string *src) { |
406 if (!operation || !dest || !src) { | 422 if (!operation || !dest || !src) { |
407 BPLOG(ERROR) << "Null parameters passed."; | 423 BPLOG(ERROR) << "Null parameters passed."; |
408 return false; | 424 return false; |
409 } | 425 } |
410 | 426 |
411 // Set all pointer values to empty strings. | 427 // Set all pointer values to empty strings. |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
595 case MD_EXCEPTION_CODE_LIN_DUMP_REQUESTED: | 611 case MD_EXCEPTION_CODE_LIN_DUMP_REQUESTED: |
596 return true; | 612 return true; |
597 break; | 613 break; |
598 default: | 614 default: |
599 return false; | 615 return false; |
600 break; | 616 break; |
601 } | 617 } |
602 } | 618 } |
603 | 619 |
604 } // namespace google_breakpad | 620 } // namespace google_breakpad |
OLD | NEW |