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/environment_data_collection_win.h" | 5 #include "chrome/browser/safe_browsing/environment_data_collection_win.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 TEST(SafeBrowsingEnvironmentDataCollectionWinTest, VerifyLoadedModules) { | 173 TEST(SafeBrowsingEnvironmentDataCollectionWinTest, VerifyLoadedModules) { |
174 // Load the test modules. | 174 // Load the test modules. |
175 std::vector<base::ScopedNativeLibrary> test_dlls( | 175 std::vector<base::ScopedNativeLibrary> test_dlls( |
176 safe_browsing::kTestDllNamesCount); | 176 safe_browsing::kTestDllNamesCount); |
177 for (size_t i = 0; i < safe_browsing::kTestDllNamesCount; ++i) { | 177 for (size_t i = 0; i < safe_browsing::kTestDllNamesCount; ++i) { |
178 test_dlls[i].Reset(LoadNativeLibrary( | 178 test_dlls[i].Reset(LoadNativeLibrary( |
179 base::FilePath(safe_browsing::kTestDllNames[i]), NULL)); | 179 base::FilePath(safe_browsing::kTestDllNames[i]), NULL)); |
180 } | 180 } |
181 | 181 |
182 // Edit the first byte of the function exported by the first module. | 182 // Edit the first byte of the function exported by the first module. |
183 HMODULE module_handle = NULL; | 183 HMODULE module_handle = GetModuleHandle(safe_browsing::kTestDllNames[0]); |
robertshield
2014/08/15 01:16:34
Nice find! Instead of this, please use GetModuleHa
| |
184 EXPECT_TRUE( | 184 EXPECT_NE(reinterpret_cast<HANDLE>(NULL), module_handle); |
185 GetModuleHandleEx(0, safe_browsing::kTestDllNames[0], &module_handle)); | |
186 uint8_t* export_addr = reinterpret_cast<uint8_t*>( | 185 uint8_t* export_addr = reinterpret_cast<uint8_t*>( |
187 GetProcAddress(module_handle, safe_browsing::kTestExportName)); | 186 GetProcAddress(module_handle, safe_browsing::kTestExportName)); |
188 EXPECT_NE(reinterpret_cast<uint8_t*>(NULL), export_addr); | 187 EXPECT_NE(reinterpret_cast<uint8_t*>(NULL), export_addr); |
189 | 188 |
190 uint8_t new_val = (*export_addr) + 1; | 189 uint8_t new_val = (*export_addr) + 1; |
191 SIZE_T bytes_written = 0; | 190 SIZE_T bytes_written = 0; |
192 WriteProcessMemory(GetCurrentProcess(), | 191 WriteProcessMemory(GetCurrentProcess(), |
193 export_addr, | 192 export_addr, |
194 reinterpret_cast<void*>(&new_val), | 193 reinterpret_cast<void*>(&new_val), |
195 1, | 194 1, |
(...skipping 14 matching lines...) Expand all Loading... | |
210 EXPECT_EQ(base::WideToUTF8(std::wstring(safe_browsing::kTestDllNames[0])), | 209 EXPECT_EQ(base::WideToUTF8(std::wstring(safe_browsing::kTestDllNames[0])), |
211 process_report.module_state(0).name()); | 210 process_report.module_state(0).name()); |
212 EXPECT_EQ( | 211 EXPECT_EQ( |
213 safe_browsing::ClientIncidentReport_EnvironmentData_Process_ModuleState:: | 212 safe_browsing::ClientIncidentReport_EnvironmentData_Process_ModuleState:: |
214 MODULE_STATE_MODIFIED, | 213 MODULE_STATE_MODIFIED, |
215 process_report.module_state(0).modified_state()); | 214 process_report.module_state(0).modified_state()); |
216 EXPECT_EQ(1, process_report.module_state(0).modified_export_size()); | 215 EXPECT_EQ(1, process_report.module_state(0).modified_export_size()); |
217 EXPECT_EQ(std::string(safe_browsing::kTestExportName), | 216 EXPECT_EQ(std::string(safe_browsing::kTestExportName), |
218 process_report.module_state(0).modified_export(0)); | 217 process_report.module_state(0).modified_export(0)); |
219 } | 218 } |
OLD | NEW |