| 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 ASSERT_FALSE(ExploitabilityLinuxTest::DisassembleBytes("", NULL, 5, NULL)); | 187 ASSERT_FALSE(ExploitabilityLinuxTest::DisassembleBytes("", NULL, 5, NULL)); |
| 188 uint8_t bytes[6] = {0xc7, 0x0, 0x5, 0x0, 0x0, 0x0}; | 188 uint8_t bytes[6] = {0xc7, 0x0, 0x5, 0x0, 0x0, 0x0}; |
| 189 char buffer[1024] = {0}; | 189 char buffer[1024] = {0}; |
| 190 ASSERT_TRUE(ExploitabilityLinuxTest::DisassembleBytes("i386:x86-64", | 190 ASSERT_TRUE(ExploitabilityLinuxTest::DisassembleBytes("i386:x86-64", |
| 191 bytes, | 191 bytes, |
| 192 1024, | 192 1024, |
| 193 buffer)); | 193 buffer)); |
| 194 std::stringstream objdump_stream; | 194 std::stringstream objdump_stream; |
| 195 objdump_stream.str(string(buffer)); | 195 objdump_stream.str(string(buffer)); |
| 196 string line = ""; | 196 string line = ""; |
| 197 while ((line.find("<.data>") == string::npos) && | 197 while (line.find("<.data>") == string::npos) |
| 198 getline(objdump_stream, line)) { | 198 getline(objdump_stream, line); |
| 199 } | 199 getline(objdump_stream, line); |
| 200 ASSERT_TRUE(getline(objdump_stream, line)); | |
| 201 ASSERT_EQ(line, " 0:\tc7 00 05 00 00 00 \tmov DWORD PTR [rax],0x5"); | 200 ASSERT_EQ(line, " 0:\tc7 00 05 00 00 00 \tmov DWORD PTR [rax],0x5"); |
| 202 } | 201 } |
| 203 | 202 |
| 204 TEST(ExploitabilityLinuxUtilsTest, TokenizeObjdumpInstructionTest) { | 203 TEST(ExploitabilityLinuxUtilsTest, TokenizeObjdumpInstructionTest) { |
| 205 ASSERT_FALSE(ExploitabilityLinuxTest::TokenizeObjdumpInstruction("", | 204 ASSERT_FALSE(ExploitabilityLinuxTest::TokenizeObjdumpInstruction("", |
| 206 NULL, | 205 NULL, |
| 207 NULL, | 206 NULL, |
| 208 NULL)); | 207 NULL)); |
| 209 string line = "0: c7 00 05 00 00 00 mov DWORD PTR [rax],0x5"; | 208 string line = "0: c7 00 05 00 00 00 mov DWORD PTR [rax],0x5"; |
| 210 string operation = ""; | 209 string operation = ""; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 232 &src)); | 231 &src)); |
| 233 ASSERT_EQ(operation, "pop"); | 232 ASSERT_EQ(operation, "pop"); |
| 234 ASSERT_EQ(dest, "rdi"); | 233 ASSERT_EQ(dest, "rdi"); |
| 235 ASSERT_EQ(src, ""); | 234 ASSERT_EQ(src, ""); |
| 236 } | 235 } |
| 237 | 236 |
| 238 TEST(ExploitabilityLinuxUtilsTest, CalculateAddressTest) { | 237 TEST(ExploitabilityLinuxUtilsTest, CalculateAddressTest) { |
| 239 MDRawContextAMD64 raw_context; | 238 MDRawContextAMD64 raw_context; |
| 240 raw_context.rdx = 12345; | 239 raw_context.rdx = 12345; |
| 241 ExploitabilityLinuxTestMinidumpContext context(raw_context); | 240 ExploitabilityLinuxTestMinidumpContext context(raw_context); |
| 242 ASSERT_EQ(context.GetContextAMD64()->rdx, 12345); | 241 ASSERT_EQ(context.GetContextAMD64()->rdx, 12345U); |
| 243 ASSERT_FALSE(ExploitabilityLinuxTest::CalculateAddress("", context, NULL)); | 242 ASSERT_FALSE(ExploitabilityLinuxTest::CalculateAddress("", context, NULL)); |
| 244 uint64_t write_address = 0; | 243 uint64_t write_address = 0; |
| 245 ASSERT_TRUE(ExploitabilityLinuxTest::CalculateAddress("rdx-0x4D2", | 244 ASSERT_TRUE(ExploitabilityLinuxTest::CalculateAddress("rdx-0x4D2", |
| 246 context, | 245 context, |
| 247 &write_address)); | 246 &write_address)); |
| 248 ASSERT_EQ(write_address, 11111); | 247 ASSERT_EQ(write_address, 11111U); |
| 249 ASSERT_TRUE(ExploitabilityLinuxTest::CalculateAddress("rdx+0x4D2", | 248 ASSERT_TRUE(ExploitabilityLinuxTest::CalculateAddress("rdx+0x4D2", |
| 250 context, | 249 context, |
| 251 &write_address)); | 250 &write_address)); |
| 252 ASSERT_EQ(write_address, 13579); | 251 ASSERT_EQ(write_address, 13579U); |
| 253 ASSERT_FALSE(ExploitabilityLinuxTest::CalculateAddress("rdx+rax", | 252 ASSERT_FALSE(ExploitabilityLinuxTest::CalculateAddress("rdx+rax", |
| 254 context, | 253 context, |
| 255 &write_address)); | 254 &write_address)); |
| 256 ASSERT_FALSE(ExploitabilityLinuxTest::CalculateAddress("0x3482+0x4D2", | 255 ASSERT_FALSE(ExploitabilityLinuxTest::CalculateAddress("0x3482+0x4D2", |
| 257 context, | 256 context, |
| 258 &write_address)); | 257 &write_address)); |
| 259 } | 258 } |
| 260 #endif // _WIN32 | 259 #endif // _WIN32 |
| 261 | 260 |
| 262 } // namespace | 261 } // namespace |
| OLD | NEW |