Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: chrome/browser/safe_browsing/environment_data_collection_win_unittest.cc

Issue 440753002: The incident reporting service now calls VerifyModule. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/scoped_native_library.h" 12 #include "base/scoped_native_library.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/test/test_reg_util_win.h" 14 #include "base/test/test_reg_util_win.h"
15 #include "base/win/registry.h" 15 #include "base/win/registry.h"
16 #include "chrome/browser/safe_browsing/module_integrity_unittest_util_win.h"
17 #include "chrome/browser/safe_browsing/module_integrity_verifier_win.h"
16 #include "chrome/browser/safe_browsing/path_sanitizer.h" 18 #include "chrome/browser/safe_browsing/path_sanitizer.h"
17 #include "chrome/common/safe_browsing/csd.pb.h" 19 #include "chrome/common/safe_browsing/csd.pb.h"
18 #include "chrome_elf/chrome_elf_constants.h" 20 #include "chrome_elf/chrome_elf_constants.h"
19 #include "net/base/winsock_init.h" 21 #include "net/base/winsock_init.h"
20 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
21 23
22 namespace { 24 namespace {
23 25
24 const wchar_t test_dll[] = L"test_name.dll"; 26 const wchar_t test_dll[] = L"test_name.dll";
25 27
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 .Append(FILE_PATH_LITERAL("test_path.dll")) 162 .Append(FILE_PATH_LITERAL("test_path.dll"))
161 .AsUTF8Unsafe(); 163 .AsUTF8Unsafe();
162 164
163 blacklist_registry_key.WriteValue(input_path.c_str(), input_path.c_str()); 165 blacklist_registry_key.WriteValue(input_path.c_str(), input_path.c_str());
164 safe_browsing::CollectDllBlacklistData(&process_report); 166 safe_browsing::CollectDllBlacklistData(&process_report);
165 167
166 ASSERT_EQ(1, process_report.blacklisted_dll_size()); 168 ASSERT_EQ(1, process_report.blacklisted_dll_size());
167 std::string process_report_path = process_report.blacklisted_dll(0); 169 std::string process_report_path = process_report.blacklisted_dll(0);
168 EXPECT_EQ(path_expected, process_report_path); 170 EXPECT_EQ(path_expected, process_report_path);
169 } 171 }
172
173 TEST(SafeBrowsingEnvironmentDataCollectionWinTest, VerifyLoadedModules) {
174 // Load the test modules.
175 std::vector<base::ScopedNativeLibrary> test_dlls(
176 safe_browsing::kTestDllNamesCount);
177 for (size_t i = 0; i < safe_browsing::kTestDllNamesCount; ++i) {
178 test_dlls[i].Reset(LoadNativeLibrary(
179 base::FilePath(safe_browsing::kTestDllNames[i]), NULL));
180 }
181
182 // Edit the first byte of the function exported by the first module.
183 HMODULE module_handle = NULL;
184 EXPECT_TRUE(
185 GetModuleHandleEx(0, safe_browsing::kTestDllNames[0], &module_handle));
186 uint8_t* export_addr = reinterpret_cast<uint8_t*>(
187 GetProcAddress(module_handle, safe_browsing::kTestExportName));
188 EXPECT_NE(reinterpret_cast<uint8_t*>(NULL), export_addr);
189
190 uint8_t new_val = (*export_addr) + 1;
191 SIZE_T bytes_written = 0;
192 WriteProcessMemory(GetCurrentProcess(),
193 export_addr,
194 reinterpret_cast<void*>(&new_val),
195 1,
196 &bytes_written);
197 EXPECT_EQ(1, bytes_written);
198
199 safe_browsing::ClientIncidentReport_EnvironmentData_Process process_report;
200 safe_browsing::CollectModuleVerificationData(
201 safe_browsing::kTestDllNames,
202 safe_browsing::kTestDllNamesCount,
203 &process_report);
204
205 // CollectModuleVerificationData should return the single modified module and
206 // its modified export. The other module, being unmodified, is omitted from
207 // the returned list of modules.
208 EXPECT_EQ(1, process_report.module_state_size());
209
210 EXPECT_EQ(base::WideToUTF8(std::wstring(safe_browsing::kTestDllNames[0])),
211 process_report.module_state(0).name());
212 EXPECT_EQ(
213 safe_browsing::ClientIncidentReport_EnvironmentData_Process_ModuleState::
214 MODULE_STATE_MODIFIED,
215 process_report.module_state(0).modified_state());
216 EXPECT_EQ(1, process_report.module_state(0).modified_export_size());
217 EXPECT_EQ(std::string(safe_browsing::kTestExportName),
218 process_report.module_state(0).modified_export(0));
219 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698