OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/safe_browsing/incident_reporting/module_integrity_verif
ier_win.h" | 5 #include "chrome/browser/safe_browsing/incident_reporting/module_integrity_verif
ier_win.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 | 243 |
244 uint8_t* mem_code_addr = NULL; | 244 uint8_t* mem_code_addr = NULL; |
245 uint8_t* disk_code_addr = NULL; | 245 uint8_t* disk_code_addr = NULL; |
246 uint32_t code_size = 0; | 246 uint32_t code_size = 0; |
247 ASSERT_TRUE(GetCodeAddrsAndSize(*mem_peimage_ptr_, | 247 ASSERT_TRUE(GetCodeAddrsAndSize(*mem_peimage_ptr_, |
248 *disk_peimage_ptr_, | 248 *disk_peimage_ptr_, |
249 &mem_code_addr, | 249 &mem_code_addr, |
250 &disk_code_addr, | 250 &disk_code_addr, |
251 &code_size)); | 251 &code_size)); |
252 | 252 |
253 const size_t kModificationSize = 256; | 253 const int kModificationSize = 256; |
254 // Write the modification at the end so it's not overlapping relocations | 254 // Write the modification at the end so it's not overlapping relocations |
255 const size_t modification_offset = code_size - kModificationSize; | 255 const size_t modification_offset = code_size - kModificationSize; |
256 ScopedModuleModifier<kModificationSize> mod( | 256 ScopedModuleModifier<kModificationSize> mod( |
257 mem_code_addr + modification_offset); | 257 mem_code_addr + modification_offset); |
258 | 258 |
259 state.Clear(); | 259 state.Clear(); |
260 num_bytes_different = 0; | 260 num_bytes_different = 0; |
261 ASSERT_TRUE(VerifyModule(kTestDllNames[0], &state, &num_bytes_different)); | 261 ASSERT_TRUE(VerifyModule(kTestDllNames[0], &state, &num_bytes_different)); |
262 ASSERT_TRUE(state.has_name()); | 262 ASSERT_TRUE(state.has_name()); |
263 ASSERT_EQ(base::WideToUTF8(kTestDllNames[0]), state.name()); | 263 ASSERT_EQ(base::WideToUTF8(kTestDllNames[0]), state.name()); |
(...skipping 28 matching lines...) Expand all Loading... |
292 uint8_t* mem_code_addr = NULL; | 292 uint8_t* mem_code_addr = NULL; |
293 uint8_t* disk_code_addr = NULL; | 293 uint8_t* disk_code_addr = NULL; |
294 uint32_t code_size = 0; | 294 uint32_t code_size = 0; |
295 ASSERT_TRUE(GetCodeAddrsAndSize(*mem_peimage_ptr_, | 295 ASSERT_TRUE(GetCodeAddrsAndSize(*mem_peimage_ptr_, |
296 *disk_peimage_ptr_, | 296 *disk_peimage_ptr_, |
297 &mem_code_addr, | 297 &mem_code_addr, |
298 &disk_code_addr, | 298 &disk_code_addr, |
299 &code_size)); | 299 &code_size)); |
300 | 300 |
301 // Modify the first hunk of the code, which contains many relocs. | 301 // Modify the first hunk of the code, which contains many relocs. |
302 const size_t kModificationSize = 256; | 302 const int kModificationSize = 256; |
303 ScopedModuleModifier<kModificationSize> mod(mem_code_addr); | 303 ScopedModuleModifier<kModificationSize> mod(mem_code_addr); |
304 | 304 |
305 state.Clear(); | 305 state.Clear(); |
306 num_bytes_different = 0; | 306 num_bytes_different = 0; |
307 ASSERT_TRUE(VerifyModule(kTestDllNames[0], &state, &num_bytes_different)); | 307 ASSERT_TRUE(VerifyModule(kTestDllNames[0], &state, &num_bytes_different)); |
308 ASSERT_TRUE(state.has_name()); | 308 ASSERT_TRUE(state.has_name()); |
309 ASSERT_EQ(base::WideToUTF8(kTestDllNames[0]), state.name()); | 309 ASSERT_EQ(base::WideToUTF8(kTestDllNames[0]), state.name()); |
310 ASSERT_TRUE(state.has_modified_state()); | 310 ASSERT_TRUE(state.has_modified_state()); |
311 ASSERT_EQ(ModuleState::MODULE_STATE_MODIFIED, state.modified_state()); | 311 ASSERT_EQ(ModuleState::MODULE_STATE_MODIFIED, state.modified_state()); |
312 ASSERT_EQ(kModificationSize, num_bytes_different); | 312 ASSERT_EQ(kModificationSize, num_bytes_different); |
313 | 313 |
314 // Modifications across the relocs should have been coalesced into one. | 314 // Modifications across the relocs should have been coalesced into one. |
315 ASSERT_EQ(1, state.modification_size()); | 315 ASSERT_EQ(1, state.modification_size()); |
316 ASSERT_EQ(kModificationSize, state.modification(0).byte_count()); | 316 ASSERT_EQ(kModificationSize, state.modification(0).byte_count()); |
317 ASSERT_EQ(kModificationSize, state.modification(0).modified_bytes().size()); | 317 ASSERT_EQ(static_cast<size_t>(kModificationSize), |
| 318 state.modification(0).modified_bytes().size()); |
318 EXPECT_EQ(std::string(mem_code_addr, mem_code_addr + kModificationSize), | 319 EXPECT_EQ(std::string(mem_code_addr, mem_code_addr + kModificationSize), |
319 state.modification(0).modified_bytes()); | 320 state.modification(0).modified_bytes()); |
320 } | 321 } |
321 | 322 |
322 TEST_F(SafeBrowsingModuleVerifierWinTest, VerifyModuleExportModified) { | 323 TEST_F(SafeBrowsingModuleVerifierWinTest, VerifyModuleExportModified) { |
323 ModuleState state; | 324 ModuleState state; |
324 int num_bytes_different = 0; | 325 int num_bytes_different = 0; |
325 // Confirm the module is identical in memory as on disk before we begin. | 326 // Confirm the module is identical in memory as on disk before we begin. |
326 SetUpTestDllAndPEImages(); | 327 SetUpTestDllAndPEImages(); |
327 ASSERT_TRUE(VerifyModule(kTestDllNames[0], &state, &num_bytes_different)); | 328 ASSERT_TRUE(VerifyModule(kTestDllNames[0], &state, &num_bytes_different)); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 | 388 |
388 // One of the two exports now has two modifications. | 389 // One of the two exports now has two modifications. |
389 BuildModificationMap(state, &modification_map); | 390 BuildModificationMap(state, &modification_map); |
390 ASSERT_EQ(2U, modification_map.size()); | 391 ASSERT_EQ(2U, modification_map.size()); |
391 ASSERT_EQ(3U, (modification_map.begin()->second.size() + | 392 ASSERT_EQ(3U, (modification_map.begin()->second.size() + |
392 (++modification_map.begin())->second.size())); | 393 (++modification_map.begin())->second.size())); |
393 } | 394 } |
394 #endif // ADDRESS_SANITIZER | 395 #endif // ADDRESS_SANITIZER |
395 | 396 |
396 } // namespace safe_browsing | 397 } // namespace safe_browsing |
OLD | NEW |