Chromium Code Reviews| 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 <windows.h> | |
| 8 #include <set> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/files/file_path.h" | |
| 13 #include "base/strings/utf_string_conversions.h" | |
| 14 #include "chrome/browser/install_verification/win/module_info.h" | |
| 15 #include "chrome/browser/install_verification/win/module_verification_common.h" | |
| 16 #include "chrome/browser/net/service_providers_win.h" | |
| 17 #include "chrome/browser/safe_browsing/environment_data_collection.h" | |
| 18 #include "chrome/browser/safe_browsing/path_sanitizer.h" | |
| 7 #include "chrome/common/safe_browsing/csd.pb.h" | 19 #include "chrome/common/safe_browsing/csd.pb.h" |
| 8 | 20 |
| 9 namespace safe_browsing { | 21 namespace safe_browsing { |
| 10 | 22 |
| 23 bool CollectDlls(ClientIncidentReport_EnvironmentData_Process* process) { | |
| 24 // Retrieve the module list. | |
| 25 std::set<ModuleInfo> loaded_modules; | |
| 26 if (!GetLoadedModules(&loaded_modules)) | |
| 27 return false; | |
| 28 | |
| 29 PathSanitizer path_sanitizer; | |
| 30 | |
| 31 // Sanitize path of each module and add it to the incident report. | |
| 32 for (std::set<ModuleInfo>::const_iterator it = loaded_modules.begin(); | |
| 33 it != loaded_modules.end(); | |
| 34 ++it) { | |
| 35 base::FilePath dll_path(it->name); | |
| 36 path_sanitizer.StripHomeDirectory(&dll_path); | |
| 37 | |
| 38 AddDll(base::WideToUTF8(dll_path.value()), | |
| 39 it->base_address, | |
| 40 it->size, | |
| 41 process); | |
| 42 } | |
| 43 | |
| 44 return true; | |
| 45 } | |
| 46 | |
| 47 void VerifyLSP( | |
| 48 safe_browsing::ClientIncidentReport_EnvironmentData_Process* process) { | |
|
grt (UTC plus 2)
2014/06/10 13:47:53
"safe_browsing::" is not needed here
pmonette_google.com
2014/06/10 19:34:38
Done.
| |
| 49 WinsockLayeredServiceProviderList lsp_list; | |
| 50 GetWinsockLayeredServiceProviders(&lsp_list); | |
| 51 | |
| 52 // For each LSP, we extract and sanitize the path. | |
| 53 PathSanitizer path_sanitizer; | |
| 54 std::vector<std::wstring> lsp_paths(lsp_list.size()); | |
|
grt (UTC plus 2)
2014/06/10 13:47:53
use base::string16 rather than std::wstring
pmonette_google.com
2014/06/10 19:34:38
Done.
| |
| 55 for (unsigned int i = 0; i < lsp_list.size(); ++i) { | |
|
grt (UTC plus 2)
2014/06/10 13:47:53
unsigned int -> size_t (use size_t for the size_ty
pmonette_google.com
2014/06/10 19:34:39
Done.
| |
| 56 lsp_paths[i] = ExpandEnvironmentVariables(lsp_list[i].path); | |
| 57 path_sanitizer.StripHomeDirectory(&lsp_paths[i]); | |
| 58 } | |
| 59 | |
| 60 // Remove duplicates. | |
| 61 lsp_paths.erase(unique(lsp_paths.begin(), lsp_paths.end()), lsp_paths.end()); | |
|
grt (UTC plus 2)
2014/06/10 13:47:53
unique -> std::unique
std::unique requires that ls
pmonette_google.com
2014/06/10 19:34:38
Done. I just went for std::set.
| |
| 62 | |
| 63 // Look for a match between LSPs and loaded dlls. | |
| 64 for (unsigned int i = 0; i < lsp_paths.size(); ++i) { | |
|
grt (UTC plus 2)
2014/06/10 13:47:53
if you use a std::set for lsp_paths, you can make
grt (UTC plus 2)
2014/06/10 13:47:53
unsigned int -> size_t
pmonette_google.com
2014/06/10 19:34:39
Yes. My intent was to add a break in the if statem
| |
| 65 for (int j = 0; j < process->dlls_size(); ++j) { | |
| 66 if (base::WideToUTF8(lsp_paths[i]) == process->dlls(j).path()) | |
| 67 process->mutable_dlls(j)->add_features( | |
| 68 ClientIncidentReport_EnvironmentData_Process_DLL_Feature_LSP); | |
| 69 } | |
|
grt (UTC plus 2)
2014/06/10 13:47:53
if there is no match, that means that the LSP was
pmonette_google.com
2014/06/10 19:34:39
We talked about this. No match is an expected beha
| |
| 70 } | |
| 71 } | |
| 72 | |
| 11 void CollectPlatformProcessData( | 73 void CollectPlatformProcessData( |
| 12 ClientIncidentReport_EnvironmentData_Process* process) { | 74 ClientIncidentReport_EnvironmentData_Process* process) { |
| 13 // TODO(pmonette): collect dlls and lsps. | 75 CollectDlls(process); |
| 76 VerifyLSP(process); | |
| 77 } | |
| 78 | |
| 79 base::string16 ExpandEnvironmentVariables(const base::string16& path) { | |
| 80 wchar_t path_expanded[MAX_PATH + 1] = {0}; | |
|
grt (UTC plus 2)
2014/06/10 13:47:53
nit: {0} -> {}
pmonette_google.com
2014/06/10 19:34:38
Done.
| |
| 81 ExpandEnvironmentStrings(path.c_str(), path_expanded, MAX_PATH); | |
|
grt (UTC plus 2)
2014/06/10 13:47:53
you need to check the return value here since ther
pmonette_google.com
2014/06/10 19:34:38
Done.
WriteInto is handy!
| |
| 82 | |
| 83 return base::string16(path_expanded); | |
| 84 } | |
| 85 | |
| 86 void AddDll(const std::string& path, | |
| 87 int base_address, | |
| 88 int length, | |
| 89 ClientIncidentReport_EnvironmentData_Process* process) { | |
| 90 ClientIncidentReport_EnvironmentData_Process_DLL* dll = process->add_dlls(); | |
| 91 | |
| 92 dll->set_path(path); | |
| 93 dll->set_base_address(base_address); | |
| 94 dll->set_length(length); | |
| 14 } | 95 } |
| 15 | 96 |
| 16 } // namespace safe_browsing | 97 } // namespace safe_browsing |
| OLD | NEW |