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

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_verifier_win.h"
16 #include "chrome/browser/safe_browsing/path_sanitizer.h" 17 #include "chrome/browser/safe_browsing/path_sanitizer.h"
17 #include "chrome/common/safe_browsing/csd.pb.h" 18 #include "chrome/common/safe_browsing/csd.pb.h"
18 #include "chrome_elf/chrome_elf_constants.h" 19 #include "chrome_elf/chrome_elf_constants.h"
19 #include "net/base/winsock_init.h" 20 #include "net/base/winsock_init.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 namespace { 23 namespace {
23 24
24 const wchar_t test_dll[] = L"test_name.dll"; 25 const wchar_t test_dll[] = L"test_name.dll";
25 26
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 .Append(FILE_PATH_LITERAL("test_path.dll")) 161 .Append(FILE_PATH_LITERAL("test_path.dll"))
161 .AsUTF8Unsafe(); 162 .AsUTF8Unsafe();
162 163
163 blacklist_registry_key.WriteValue(input_path.c_str(), input_path.c_str()); 164 blacklist_registry_key.WriteValue(input_path.c_str(), input_path.c_str());
164 safe_browsing::CollectDllBlacklistData(&process_report); 165 safe_browsing::CollectDllBlacklistData(&process_report);
165 166
166 ASSERT_EQ(1, process_report.blacklisted_dll_size()); 167 ASSERT_EQ(1, process_report.blacklisted_dll_size());
167 std::string process_report_path = process_report.blacklisted_dll(0); 168 std::string process_report_path = process_report.blacklisted_dll(0);
168 EXPECT_EQ(path_expected, process_report_path); 169 EXPECT_EQ(path_expected, process_report_path);
169 } 170 }
171
172 TEST(SafeBrowsingEnvironmentDataCollectionWinTest, VerifyLoadedModules) {
173 // Load the test modules.
174 base::ScopedNativeLibrary test_dlls[safe_browsing::kTestDllsMaxCount];
175 int test_dlls_count = safe_browsing::TestDllsCount();
176 for (int i = 0; i < test_dlls_count; ++i) {
177 test_dlls[i].Reset(LoadNativeLibrary(
178 base::FilePath(safe_browsing::test_dll_names[i]), NULL));
179 }
180
181 // Edit the first byte of the function exported by the first module.
182 HMODULE module_handle = NULL;
183 EXPECT_TRUE(
184 GetModuleHandleEx(0, safe_browsing::test_dll_names[0], &module_handle));
185 uint8_t* export_addr = reinterpret_cast<uint8_t*>(
186 GetProcAddress(module_handle, safe_browsing::kTestExportName));
187 EXPECT_NE(reinterpret_cast<uint8_t*>(NULL), export_addr);
188
189 uint8_t new_val = (*export_addr) + 1;
190 SIZE_T bytes_written = 0;
191 WriteProcessMemory(GetCurrentProcess(),
192 export_addr,
193 reinterpret_cast<void*>(&new_val),
194 1,
195 &bytes_written);
196 EXPECT_EQ(1, bytes_written);
197
198 safe_browsing::ClientIncidentReport_EnvironmentData_Process process_report;
199 safe_browsing::RecordModuleVerificationData(safe_browsing::test_dll_names,
200 &process_report);
201 EXPECT_EQ(test_dlls_count, process_report.module_state_size());
202
203 // RecordModuleVerificationData should find the modified exported function
204 // in the first module, and see all others as unmodified.
205 for (int i = 0; i < process_report.module_state_size(); ++i) {
206 if (process_report.module_state(i).name() ==
207 base::WideToUTF8(std::wstring(safe_browsing::test_dll_names[0]))) {
208 EXPECT_EQ(safe_browsing::MODULE_STATE_MODIFIED,
209 process_report.module_state(i).modified_state());
210 EXPECT_EQ(1, process_report.module_state(i).modified_export_size());
211 EXPECT_EQ(std::string(safe_browsing::kTestExportName),
212 process_report.module_state(i).modified_export(0));
213
214 } else {
215 EXPECT_EQ(safe_browsing::MODULE_STATE_UNMODIFIED,
216 process_report.module_state(i).modified_state());
217 EXPECT_EQ(0, process_report.module_state(i).modified_export_size());
218 }
219 }
220 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698