| 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 bool ExploitabilityLinux::GetObjdumpInstructionLine( |
| 392 const char *objdump_output_buffer, |
| 393 string *instruction_line) { |
| 394 // Put buffer data into stream to output line-by-line. |
| 395 std::stringstream objdump_stream; |
| 396 objdump_stream.str(string(objdump_output_buffer)); |
| 397 |
| 398 // Pipe each output line into the string until the string contains the first |
| 399 // instruction from objdump. All lines before the "<.data>:" section are |
| 400 // skipped. Loop until the line shows the first instruction or there are no |
| 401 // lines left. |
| 402 bool data_section_seen = false; |
| 403 do { |
| 404 if (!getline(objdump_stream, *instruction_line)) { |
| 405 BPLOG(INFO) << "Objdump instructions not found"; |
| 406 return false; |
| 407 } |
| 408 if (instruction_line->find("<.data>:") != string::npos) { |
| 409 data_section_seen = true; |
| 410 } |
| 411 } while (!data_section_seen || instruction_line->find("0:") == string::npos); |
| 412 // This first instruction contains the above substring. |
| 413 |
| 414 return true; |
| 415 } |
| 416 |
| 402 bool ExploitabilityLinux::TokenizeObjdumpInstruction(const string &line, | 417 bool ExploitabilityLinux::TokenizeObjdumpInstruction(const string &line, |
| 403 string *operation, | 418 string *operation, |
| 404 string *dest, | 419 string *dest, |
| 405 string *src) { | 420 string *src) { |
| 406 if (!operation || !dest || !src) { | 421 if (!operation || !dest || !src) { |
| 407 BPLOG(ERROR) << "Null parameters passed."; | 422 BPLOG(ERROR) << "Null parameters passed."; |
| 408 return false; | 423 return false; |
| 409 } | 424 } |
| 410 | 425 |
| 411 // Set all pointer values to empty strings. | 426 // 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: | 610 case MD_EXCEPTION_CODE_LIN_DUMP_REQUESTED: |
| 596 return true; | 611 return true; |
| 597 break; | 612 break; |
| 598 default: | 613 default: |
| 599 return false; | 614 return false; |
| 600 break; | 615 break; |
| 601 } | 616 } |
| 602 } | 617 } |
| 603 | 618 |
| 604 } // namespace google_breakpad | 619 } // namespace google_breakpad |
| OLD | NEW |