| 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/blacklist_load_analyze
r.h" | 5 #include "chrome/browser/safe_browsing/incident_reporting/blacklist_load_analyze
r.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/file_version_info.h" | 9 #include "base/file_version_info.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 16 #include "chrome/browser/install_verification/win/module_info.h" | 17 #include "chrome/browser/install_verification/win/module_info.h" |
| 17 #include "chrome/browser/install_verification/win/module_verification_common.h" | 18 #include "chrome/browser/install_verification/win/module_verification_common.h" |
| 18 #include "chrome/browser/safe_browsing/incident_reporting/blacklist_load_inciden
t.h" | 19 #include "chrome/browser/safe_browsing/incident_reporting/blacklist_load_inciden
t.h" |
| 19 #include "chrome/browser/safe_browsing/incident_reporting/incident_receiver.h" | 20 #include "chrome/browser/safe_browsing/incident_reporting/incident_receiver.h" |
| 20 #include "chrome/browser/safe_browsing/path_sanitizer.h" | 21 #include "chrome/browser/safe_browsing/path_sanitizer.h" |
| 21 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 22 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 39 base::string16 module_file_name(base::ToLowerASCII( | 40 base::string16 module_file_name(base::ToLowerASCII( |
| 40 base::FilePath(module_iter->name).BaseName().value())); | 41 base::FilePath(module_iter->name).BaseName().value())); |
| 41 if (blacklist::GetBlacklistIndex(module_file_name.c_str()) != -1) { | 42 if (blacklist::GetBlacklistIndex(module_file_name.c_str()) != -1) { |
| 42 module_names->push_back(module_iter->name); | 43 module_names->push_back(module_iter->name); |
| 43 } | 44 } |
| 44 } | 45 } |
| 45 | 46 |
| 46 return true; | 47 return true; |
| 47 } | 48 } |
| 48 | 49 |
| 49 void VerifyBlacklistLoadState(scoped_ptr<IncidentReceiver> incident_receiver) { | 50 void VerifyBlacklistLoadState( |
| 51 std::unique_ptr<IncidentReceiver> incident_receiver) { |
| 50 std::vector<base::string16> module_names; | 52 std::vector<base::string16> module_names; |
| 51 if (GetLoadedBlacklistedModules(&module_names)) { | 53 if (GetLoadedBlacklistedModules(&module_names)) { |
| 52 PathSanitizer path_sanitizer; | 54 PathSanitizer path_sanitizer; |
| 53 | 55 |
| 54 const bool blacklist_intialized = blacklist::IsBlacklistInitialized(); | 56 const bool blacklist_intialized = blacklist::IsBlacklistInitialized(); |
| 55 | 57 |
| 56 for (const auto& module_name : module_names) { | 58 for (const auto& module_name : module_names) { |
| 57 scoped_ptr<ClientIncidentReport_IncidentData_BlacklistLoadIncident> | 59 std::unique_ptr<ClientIncidentReport_IncidentData_BlacklistLoadIncident> |
| 58 blacklist_load( | 60 blacklist_load( |
| 59 new ClientIncidentReport_IncidentData_BlacklistLoadIncident()); | 61 new ClientIncidentReport_IncidentData_BlacklistLoadIncident()); |
| 60 | 62 |
| 61 const base::FilePath module_path(module_name); | 63 const base::FilePath module_path(module_name); |
| 62 | 64 |
| 63 // Sanitized path. | 65 // Sanitized path. |
| 64 base::FilePath sanitized_path(module_path); | 66 base::FilePath sanitized_path(module_path); |
| 65 path_sanitizer.StripHomeDirectory(&sanitized_path); | 67 path_sanitizer.StripHomeDirectory(&sanitized_path); |
| 66 blacklist_load->set_path(base::WideToUTF8(sanitized_path.value())); | 68 blacklist_load->set_path(base::WideToUTF8(sanitized_path.value())); |
| 67 | 69 |
| 68 // Digest. | 70 // Digest. |
| 69 scoped_refptr<BinaryFeatureExtractor> | 71 scoped_refptr<BinaryFeatureExtractor> |
| 70 binary_feature_extractor(new BinaryFeatureExtractor()); | 72 binary_feature_extractor(new BinaryFeatureExtractor()); |
| 71 base::TimeTicks start_time = base::TimeTicks::Now(); | 73 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 72 binary_feature_extractor->ExtractDigest(module_path, | 74 binary_feature_extractor->ExtractDigest(module_path, |
| 73 blacklist_load->mutable_digest()); | 75 blacklist_load->mutable_digest()); |
| 74 UMA_HISTOGRAM_TIMES("SBIRS.BLAHashTime", | 76 UMA_HISTOGRAM_TIMES("SBIRS.BLAHashTime", |
| 75 base::TimeTicks::Now() - start_time); | 77 base::TimeTicks::Now() - start_time); |
| 76 | 78 |
| 77 // Version. | 79 // Version. |
| 78 scoped_ptr<FileVersionInfo> version_info( | 80 std::unique_ptr<FileVersionInfo> version_info( |
| 79 FileVersionInfo::CreateFileVersionInfo(module_path)); | 81 FileVersionInfo::CreateFileVersionInfo(module_path)); |
| 80 if (version_info) { | 82 if (version_info) { |
| 81 std::wstring file_version = version_info->file_version(); | 83 std::wstring file_version = version_info->file_version(); |
| 82 if (!file_version.empty()) | 84 if (!file_version.empty()) |
| 83 blacklist_load->set_version(base::WideToUTF8(file_version)); | 85 blacklist_load->set_version(base::WideToUTF8(file_version)); |
| 84 } | 86 } |
| 85 | 87 |
| 86 // Initialized state. | 88 // Initialized state. |
| 87 blacklist_load->set_blacklist_initialized(blacklist_intialized); | 89 blacklist_load->set_blacklist_initialized(blacklist_intialized); |
| 88 | 90 |
| 89 // Signature. | 91 // Signature. |
| 90 start_time = base::TimeTicks::Now(); | 92 start_time = base::TimeTicks::Now(); |
| 91 binary_feature_extractor->CheckSignature( | 93 binary_feature_extractor->CheckSignature( |
| 92 module_path, blacklist_load->mutable_signature()); | 94 module_path, blacklist_load->mutable_signature()); |
| 93 UMA_HISTOGRAM_TIMES("SBIRS.BLASignatureTime", | 95 UMA_HISTOGRAM_TIMES("SBIRS.BLASignatureTime", |
| 94 base::TimeTicks::Now() - start_time); | 96 base::TimeTicks::Now() - start_time); |
| 95 | 97 |
| 96 // Image headers. | 98 // Image headers. |
| 97 if (!binary_feature_extractor->ExtractImageFeatures( | 99 if (!binary_feature_extractor->ExtractImageFeatures( |
| 98 module_path, | 100 module_path, |
| 99 BinaryFeatureExtractor::kDefaultOptions, | 101 BinaryFeatureExtractor::kDefaultOptions, |
| 100 blacklist_load->mutable_image_headers(), | 102 blacklist_load->mutable_image_headers(), |
| 101 nullptr /* signed_data */)) { | 103 nullptr /* signed_data */)) { |
| 102 blacklist_load->clear_image_headers(); | 104 blacklist_load->clear_image_headers(); |
| 103 } | 105 } |
| 104 | 106 |
| 105 // Send the report. | 107 // Send the report. |
| 106 incident_receiver->AddIncidentForProcess(make_scoped_ptr( | 108 incident_receiver->AddIncidentForProcess(base::WrapUnique( |
| 107 new BlacklistLoadIncident(std::move(blacklist_load)))); | 109 new BlacklistLoadIncident(std::move(blacklist_load)))); |
| 108 } | 110 } |
| 109 } | 111 } |
| 110 } | 112 } |
| 111 | 113 |
| 112 } // namespace safe_browsing | 114 } // namespace safe_browsing |
| OLD | NEW |