| 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 <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
| 7 #include <algorithm> | 10 #include <algorithm> |
| 8 #include <functional> | 11 #include <functional> |
| 9 #include <map> | 12 #include <map> |
| 10 #include <vector> | 13 #include <vector> |
| 11 | 14 |
| 12 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 13 #include "base/files/memory_mapped_file.h" | 16 #include "base/files/memory_mapped_file.h" |
| 17 #include "base/macros.h" |
| 14 #include "base/native_library.h" | 18 #include "base/native_library.h" |
| 15 #include "base/scoped_native_library.h" | 19 #include "base/scoped_native_library.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/win/pe_image.h" | 21 #include "base/win/pe_image.h" |
| 18 #include "chrome/browser/safe_browsing/incident_reporting/module_integrity_unitt
est_util_win.h" | 22 #include "chrome/browser/safe_browsing/incident_reporting/module_integrity_unitt
est_util_win.h" |
| 19 #include "chrome/common/safe_browsing/csd.pb.h" | 23 #include "chrome/common/safe_browsing/csd.pb.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 25 |
| 22 namespace safe_browsing { | 26 namespace safe_browsing { |
| 23 | 27 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 GetMemModuleHandle(&module_handle); | 108 GetMemModuleHandle(&module_handle); |
| 105 | 109 |
| 106 WCHAR module_path[MAX_PATH] = {}; | 110 WCHAR module_path[MAX_PATH] = {}; |
| 107 DWORD length = | 111 DWORD length = |
| 108 GetModuleFileName(module_handle, module_path, arraysize(module_path)); | 112 GetModuleFileName(module_handle, module_path, arraysize(module_path)); |
| 109 ASSERT_NE(arraysize(module_path), length); | 113 ASSERT_NE(arraysize(module_path), length); |
| 110 ASSERT_TRUE(disk_dll_handle_.Initialize(base::FilePath(module_path))); | 114 ASSERT_TRUE(disk_dll_handle_.Initialize(base::FilePath(module_path))); |
| 111 } | 115 } |
| 112 | 116 |
| 113 void GetDiskModuleHandle(HMODULE* disk_handle) { | 117 void GetDiskModuleHandle(HMODULE* disk_handle) { |
| 114 *disk_handle = | 118 *disk_handle = reinterpret_cast<HMODULE>( |
| 115 reinterpret_cast<HMODULE>(const_cast<uint8*>(disk_dll_handle_.data())); | 119 const_cast<uint8_t*>(disk_dll_handle_.data())); |
| 116 } | 120 } |
| 117 | 121 |
| 118 // Returns the address of the named function exported by the test dll. | 122 // Returns the address of the named function exported by the test dll. |
| 119 uint8_t* GetAddressOfExport(const char* export_name) { | 123 uint8_t* GetAddressOfExport(const char* export_name) { |
| 120 HMODULE mem_handle; | 124 HMODULE mem_handle; |
| 121 GetMemModuleHandle(&mem_handle); | 125 GetMemModuleHandle(&mem_handle); |
| 122 uint8_t* export_addr = | 126 uint8_t* export_addr = |
| 123 reinterpret_cast<uint8_t*>(GetProcAddress(mem_handle, export_name)); | 127 reinterpret_cast<uint8_t*>(GetProcAddress(mem_handle, export_name)); |
| 124 EXPECT_NE(nullptr, export_addr); | 128 EXPECT_NE(nullptr, export_addr); |
| 125 return export_addr; | 129 return export_addr; |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 | 392 |
| 389 // One of the two exports now has two modifications. | 393 // One of the two exports now has two modifications. |
| 390 BuildModificationMap(state, &modification_map); | 394 BuildModificationMap(state, &modification_map); |
| 391 ASSERT_EQ(2U, modification_map.size()); | 395 ASSERT_EQ(2U, modification_map.size()); |
| 392 ASSERT_EQ(3U, (modification_map.begin()->second.size() + | 396 ASSERT_EQ(3U, (modification_map.begin()->second.size() + |
| 393 (++modification_map.begin())->second.size())); | 397 (++modification_map.begin())->second.size())); |
| 394 } | 398 } |
| 395 #endif // ADDRESS_SANITIZER | 399 #endif // ADDRESS_SANITIZER |
| 396 | 400 |
| 397 } // namespace safe_browsing | 401 } // namespace safe_browsing |
| OLD | NEW |