OLD | NEW |
---|---|
1 // Copyright (c) 2010, Google Inc. | 1 // Copyright (c) 2010, 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 29 matching lines...) Expand all Loading... | |
40 #ifndef _WIN32 | 40 #ifndef _WIN32 |
41 #include "processor/exploitability_linux.h" | 41 #include "processor/exploitability_linux.h" |
42 #endif // _WIN32 | 42 #endif // _WIN32 |
43 #include "processor/simple_symbol_supplier.h" | 43 #include "processor/simple_symbol_supplier.h" |
44 | 44 |
45 #ifndef _WIN32 | 45 #ifndef _WIN32 |
46 namespace google_breakpad { | 46 namespace google_breakpad { |
47 | 47 |
48 class ExploitabilityLinuxTest : public ExploitabilityLinux { | 48 class ExploitabilityLinuxTest : public ExploitabilityLinux { |
49 public: | 49 public: |
50 using ExploitabilityLinux::CalculateAddress; | |
50 using ExploitabilityLinux::DisassembleBytes; | 51 using ExploitabilityLinux::DisassembleBytes; |
52 using ExploitabilityLinux::GetObjdumpInstructionLine; | |
51 using ExploitabilityLinux::TokenizeObjdumpInstruction; | 53 using ExploitabilityLinux::TokenizeObjdumpInstruction; |
52 using ExploitabilityLinux::CalculateAddress; | |
53 }; | 54 }; |
54 | 55 |
55 class ExploitabilityLinuxTestMinidumpContext : public MinidumpContext { | 56 class ExploitabilityLinuxTestMinidumpContext : public MinidumpContext { |
56 public: | 57 public: |
57 explicit ExploitabilityLinuxTestMinidumpContext( | 58 explicit ExploitabilityLinuxTestMinidumpContext( |
58 const MDRawContextAMD64& context) : MinidumpContext(NULL) { | 59 const MDRawContextAMD64& context) : MinidumpContext(NULL) { |
59 valid_ = true; | 60 valid_ = true; |
60 SetContextAMD64(new MDRawContextAMD64(context)); | 61 SetContextAMD64(new MDRawContextAMD64(context)); |
61 SetContextFlags(MD_CONTEXT_AMD64); | 62 SetContextFlags(MD_CONTEXT_AMD64); |
62 } | 63 } |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 buffer)); | 194 buffer)); |
194 std::stringstream objdump_stream; | 195 std::stringstream objdump_stream; |
195 objdump_stream.str(string(buffer)); | 196 objdump_stream.str(string(buffer)); |
196 string line = ""; | 197 string line = ""; |
197 while (line.find("<.data>") == string::npos) | 198 while (line.find("<.data>") == string::npos) |
198 getline(objdump_stream, line); | 199 getline(objdump_stream, line); |
199 getline(objdump_stream, line); | 200 getline(objdump_stream, line); |
200 ASSERT_EQ(line, " 0:\tc7 00 05 00 00 00 \tmov DWORD PTR [rax],0x5"); | 201 ASSERT_EQ(line, " 0:\tc7 00 05 00 00 00 \tmov DWORD PTR [rax],0x5"); |
201 } | 202 } |
202 | 203 |
204 TEST(ExploitabilityLinuxUtilsTest, GetObjdumpInstructionLine) { | |
205 string disassebly = | |
206 "\n" | |
207 "/tmp/breakpad_mem_region-raw_bytes-tMmMo0: file format binary\n" | |
208 "\n" | |
209 "\n" | |
210 "Disassembly of section .data:\n" | |
211 "\n" | |
212 "0000000000000000 <.data>:\n" | |
213 " 0:\tc7 00 01 00 00 00 \tmov DWORD PTR [rax],0x1\n" | |
mmandlis
2016/02/16 19:21:16
IIUC, we are after the line starting with 0: that
ivanpe
2016/02/16 19:41:43
Done.
| |
214 " 6:\t5d \tpop rbp\n" | |
215 " 7:\tc3 \tret \n" | |
216 " 8:\t55 \tpush rbp\n" | |
217 " 9:\t48 89 e5 \tmov rbp,rsp\n" | |
218 " c:\t53 \tpush rbx\n" | |
219 " d:\t48 \trex.W\n" | |
220 " e:\t81 \t.byte 0x81\n"; | |
221 string line; | |
222 EXPECT_TRUE(ExploitabilityLinuxTest::GetObjdumpInstructionLine( | |
223 disassebly.c_str(), &line)); | |
224 EXPECT_EQ(" 0:\tc7 00 01 00 00 00 \tmov DWORD PTR [rax],0x1", line); | |
225 } | |
226 | |
203 TEST(ExploitabilityLinuxUtilsTest, TokenizeObjdumpInstructionTest) { | 227 TEST(ExploitabilityLinuxUtilsTest, TokenizeObjdumpInstructionTest) { |
204 ASSERT_FALSE(ExploitabilityLinuxTest::TokenizeObjdumpInstruction("", | 228 ASSERT_FALSE(ExploitabilityLinuxTest::TokenizeObjdumpInstruction("", |
205 NULL, | 229 NULL, |
206 NULL, | 230 NULL, |
207 NULL)); | 231 NULL)); |
208 string line = "0: c7 00 05 00 00 00 mov DWORD PTR [rax],0x5"; | 232 string line = "0: c7 00 05 00 00 00 mov DWORD PTR [rax],0x5"; |
209 string operation = ""; | 233 string operation = ""; |
210 string dest = ""; | 234 string dest = ""; |
211 string src = ""; | 235 string src = ""; |
212 ASSERT_TRUE(ExploitabilityLinuxTest::TokenizeObjdumpInstruction(line, | 236 ASSERT_TRUE(ExploitabilityLinuxTest::TokenizeObjdumpInstruction(line, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 ASSERT_FALSE(ExploitabilityLinuxTest::CalculateAddress("rdx+rax", | 276 ASSERT_FALSE(ExploitabilityLinuxTest::CalculateAddress("rdx+rax", |
253 context, | 277 context, |
254 &write_address)); | 278 &write_address)); |
255 ASSERT_FALSE(ExploitabilityLinuxTest::CalculateAddress("0x3482+0x4D2", | 279 ASSERT_FALSE(ExploitabilityLinuxTest::CalculateAddress("0x3482+0x4D2", |
256 context, | 280 context, |
257 &write_address)); | 281 &write_address)); |
258 } | 282 } |
259 #endif // _WIN32 | 283 #endif // _WIN32 |
260 | 284 |
261 } // namespace | 285 } // namespace |
OLD | NEW |