Chromium Code Reviews| Index: src/processor/exploitability_linux.h | 
| =================================================================== | 
| --- src/processor/exploitability_linux.h (revision 1471) | 
| +++ src/processor/exploitability_linux.h (working copy) | 
| @@ -37,11 +37,26 @@ | 
| #ifndef GOOGLE_BREAKPAD_PROCESSOR_EXPLOITABILITY_LINUX_H_ | 
| #define GOOGLE_BREAKPAD_PROCESSOR_EXPLOITABILITY_LINUX_H_ | 
| +#include <elf.h> | 
| +#include <string.h> | 
| + | 
| +#include "common/scoped_ptr.h" | 
| #include "google_breakpad/common/breakpad_types.h" | 
| #include "google_breakpad/processor/exploitability.h" | 
| namespace google_breakpad { | 
| +enum LinuxArchitectureType { | 
| + // A 32-bit Linux architecture. | 
| + LINUX_32_BIT, | 
| + | 
| + // A 64-bit Linux architecture. | 
| + LINUX_64_BIT, | 
| + | 
| + // Some other architecture that is not Linux. | 
| + UNSUPPORTED_ARCHITECTURE | 
| +}; | 
| + | 
| class ExploitabilityLinux : public Exploitability { | 
| public: | 
| ExploitabilityLinux(Minidump *dump, | 
| @@ -57,6 +72,47 @@ | 
| // This method checks the exception that triggered the creation of the | 
| // minidump and reports whether the exception suggests no exploitability. | 
| bool BenignCrashTrigger(const MDRawExceptionStream *raw_exception_stream); | 
| + | 
| + // Checks if the minidump architecture is 32-bit or 64-bit. | 
| + LinuxArchitectureType ArchitectureType(); | 
| + | 
| + // Loads ELF header data of the module present in the given memory | 
| + // region into the scoped pointer. | 
| + // This method takes a scoped pointer in which the ELF header data is | 
| + // loaded, the memory region containing the ELF header, and the base | 
| + // address of the ELF header. | 
| + template<typename T> | 
| + void LoadElfHeader(scoped_ptr<T>& header, | 
| 
 
ivanpe
2015/07/16 00:45:23
Please, move the out parameter to the end.  Also t
 
liuandrew
2015/07/16 17:07:02
Done.
 
 | 
| + MinidumpMemoryRegion *memory, | 
| + uint64_t base_address) { | 
| + for (size_t i = 0; i < sizeof(T); i++) { | 
| + uint8_t my_byte = 0; | 
| + memory->GetMemoryAtAddress(base_address + i, &my_byte); | 
| + memcpy(((char *) header.get()) + i, &my_byte, sizeof(uint8_t)); | 
| + } | 
| + } | 
| + | 
| + // Loads the Program Header Table of the module present in the given | 
| + // memory region into the scoped array. | 
| + // This method takes a scoped array in which the header table data is | 
| + // loaded, the memory region containing the table, the base address of | 
| + // the program header table, and the number of entries in the table. | 
| + template<typename T> | 
| + void LoadElfHeaderTable(scoped_array<T>& table, | 
| + MinidumpMemoryRegion *memory, | 
| + uint64_t base_address, | 
| + uint16_t e_phnum) { | 
| 
 
ivanpe
2015/07/16 00:45:23
Please, update the function signature as follows:
 
liuandrew
2015/07/16 17:07:02
Done.
 
 | 
| + uint64_t offset = 0; | 
| + for (size_t i = 0; i < e_phnum; i++) { | 
| + for (size_t j = 0; j < sizeof(T); j++) { | 
| + uint8_t my_byte = 0; | 
| + memory->GetMemoryAtAddress(base_address + offset, &my_byte); | 
| + memcpy(((char *) table.get()) + offset, &my_byte, sizeof(uint8_t)); | 
| + offset++; | 
| 
 
ivanpe
2015/07/16 00:45:23
This is a bit scary.  I'm concerned about padding
 
liuandrew
2015/07/16 17:07:02
Done.
Good point. It never occurred to me since i
 
 | 
| + } | 
| + } | 
| + } | 
| + | 
| }; | 
| } // namespace google_breakpad |