| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/metrics/antivirus_metrics_provider_win.h" | 5 #include "chrome/browser/metrics/antivirus_metrics_provider_win.h" |
| 6 | 6 |
| 7 #include <iwscapi.h> | 7 #include <iwscapi.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <wbemidl.h> | 9 #include <wbemidl.h> |
| 10 #include <windows.h> | 10 #include <windows.h> |
| 11 #include <wscapi.h> | 11 #include <wscapi.h> |
| 12 | 12 |
| 13 #include <algorithm> |
| 13 #include <string> | 14 #include <string> |
| 14 | 15 |
| 15 #include "base/bind.h" | 16 #include "base/bind.h" |
| 16 #include "base/callback.h" | 17 #include "base/callback.h" |
| 17 #include "base/feature_list.h" | 18 #include "base/feature_list.h" |
| 18 #include "base/file_version_info_win.h" | 19 #include "base/file_version_info_win.h" |
| 19 #include "base/files/file_path.h" | 20 #include "base/files/file_path.h" |
| 20 #include "base/files/file_util.h" | 21 #include "base/files/file_util.h" |
| 21 #include "base/metrics/field_trial.h" | 22 #include "base/metrics/field_trial.h" |
| 22 #include "base/metrics/histogram_macros.h" | 23 #include "base/metrics/histogram_macros.h" |
| 23 #include "base/path_service.h" | 24 #include "base/path_service.h" |
| 25 #include "base/strings/string_split.h" |
| 24 #include "base/strings/string_util.h" | 26 #include "base/strings/string_util.h" |
| 25 #include "base/strings/sys_string_conversions.h" | 27 #include "base/strings/sys_string_conversions.h" |
| 26 #include "base/task_runner_util.h" | 28 #include "base/task_runner_util.h" |
| 27 #include "base/threading/thread_restrictions.h" | 29 #include "base/threading/thread_restrictions.h" |
| 28 #include "base/version.h" | 30 #include "base/version.h" |
| 29 #include "base/win/scoped_bstr.h" | 31 #include "base/win/scoped_bstr.h" |
| 30 #include "base/win/scoped_com_initializer.h" | 32 #include "base/win/scoped_com_initializer.h" |
| 31 #include "base/win/scoped_comptr.h" | 33 #include "base/win/scoped_comptr.h" |
| 32 #include "base/win/scoped_variant.h" | 34 #include "base/win/scoped_variant.h" |
| 33 #include "base/win/windows_version.h" | 35 #include "base/win/windows_version.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 50 uint8_t definition_state : 4; // 1 = Out of date, 0 = Up to date. | 52 uint8_t definition_state : 4; // 1 = Out of date, 0 = Up to date. |
| 51 uint8_t unknown_2 : 4; | 53 uint8_t unknown_2 : 4; |
| 52 uint8_t security_state : 4; // 0 = Inactive, 1 = Active, 2 = Snoozed. | 54 uint8_t security_state : 4; // 0 = Inactive, 1 = Active, 2 = Snoozed. |
| 53 uint8_t security_provider; // matches WSC_SECURITY_PROVIDER in wscapi.h. | 55 uint8_t security_provider; // matches WSC_SECURITY_PROVIDER in wscapi.h. |
| 54 uint8_t unknown_3; | 56 uint8_t unknown_3; |
| 55 }; | 57 }; |
| 56 #pragma pack(pop) | 58 #pragma pack(pop) |
| 57 | 59 |
| 58 static_assert(sizeof(PRODUCT_STATE) == 4, "Wrong packing!"); | 60 static_assert(sizeof(PRODUCT_STATE) == 4, "Wrong packing!"); |
| 59 | 61 |
| 62 // Filter any part of a product string that looks like it might be a version |
| 63 // number. Returns true if the part should be removed from the product name. |
| 64 bool ShouldFilterPart(const std::string& str) { |
| 65 // Special case for "360" (used by Norton), "365" (used by Kaspersky) and |
| 66 // "NOD32" (used by ESET). |
| 67 if (str == "365" || str == "360" || str == "NOD32") |
| 68 return false; |
| 69 for (const auto ch : str) { |
| 70 if (isdigit(ch)) |
| 71 return true; |
| 72 } |
| 73 return false; |
| 74 } |
| 75 |
| 60 bool ShouldReportFullNames() { | 76 bool ShouldReportFullNames() { |
| 61 // The expectation is that this will be disabled for the majority of users, | 77 // The expectation is that this will be disabled for the majority of users, |
| 62 // but this allows a small group to be enabled on other channels if there are | 78 // but this allows a small group to be enabled on other channels if there are |
| 63 // a large percentage of hashes collected on these channels that are not | 79 // a large percentage of hashes collected on these channels that are not |
| 64 // resolved to names previously collected on Canary channel. | 80 // resolved to names previously collected on Canary channel. |
| 65 bool enabled = base::FeatureList::IsEnabled( | 81 bool enabled = base::FeatureList::IsEnabled( |
| 66 AntiVirusMetricsProvider::kReportNamesFeature); | 82 AntiVirusMetricsProvider::kReportNamesFeature); |
| 67 | 83 |
| 68 if (chrome::GetChannel() == version_info::Channel::CANARY) | 84 if (chrome::GetChannel() == version_info::Channel::CANARY) |
| 69 return true; | 85 return true; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 194 |
| 179 MaybeAddUnregisteredAntiVirusProducts(&av_products); | 195 MaybeAddUnregisteredAntiVirusProducts(&av_products); |
| 180 | 196 |
| 181 UMA_HISTOGRAM_ENUMERATION("UMA.AntiVirusMetricsProvider.Result", | 197 UMA_HISTOGRAM_ENUMERATION("UMA.AntiVirusMetricsProvider.Result", |
| 182 result, | 198 result, |
| 183 RESULT_COUNT); | 199 RESULT_COUNT); |
| 184 | 200 |
| 185 return av_products; | 201 return av_products; |
| 186 } | 202 } |
| 187 | 203 |
| 204 std::string AntiVirusMetricsProvider::TrimVersionOfAvProductName( |
| 205 const std::string& av_product) { |
| 206 auto av_product_parts = base::SplitString( |
| 207 av_product, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 208 |
| 209 if (av_product_parts.size() >= 2) { |
| 210 // Skipping first element, remove any that look like version numbers. |
| 211 av_product_parts.erase( |
| 212 std::remove_if(av_product_parts.begin() + 1, av_product_parts.end(), |
| 213 ShouldFilterPart), |
| 214 av_product_parts.end()); |
| 215 } |
| 216 |
| 217 return base::JoinString(av_product_parts, " "); |
| 218 } |
| 219 |
| 188 void AntiVirusMetricsProvider::GotAntiVirusProducts( | 220 void AntiVirusMetricsProvider::GotAntiVirusProducts( |
| 189 const base::Closure& done_callback, | 221 const base::Closure& done_callback, |
| 190 const std::vector<AvProduct>& av_products) { | 222 const std::vector<AvProduct>& av_products) { |
| 191 DCHECK(thread_checker_.CalledOnValidThread()); | 223 DCHECK(thread_checker_.CalledOnValidThread()); |
| 192 av_products_ = av_products; | 224 av_products_ = av_products; |
| 193 done_callback.Run(); | 225 done_callback.Run(); |
| 194 } | 226 } |
| 195 | 227 |
| 196 // static | 228 // static |
| 197 AntiVirusMetricsProvider::ResultCode | 229 AntiVirusMetricsProvider::ResultCode |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 return RESULT_PRODUCT_STATE_INVALID; | 289 return RESULT_PRODUCT_STATE_INVALID; |
| 258 | 290 |
| 259 av_product.set_product_state( | 291 av_product.set_product_state( |
| 260 static_cast<metrics::SystemProfileProto::AntiVirusState>( | 292 static_cast<metrics::SystemProfileProto::AntiVirusState>( |
| 261 product_state)); | 293 product_state)); |
| 262 | 294 |
| 263 base::win::ScopedBstr product_name; | 295 base::win::ScopedBstr product_name; |
| 264 result = product->get_ProductName(product_name.Receive()); | 296 result = product->get_ProductName(product_name.Receive()); |
| 265 if (FAILED(result)) | 297 if (FAILED(result)) |
| 266 return RESULT_FAILED_TO_GET_PRODUCT_NAME; | 298 return RESULT_FAILED_TO_GET_PRODUCT_NAME; |
| 267 std::string name = | 299 std::string name = TrimVersionOfAvProductName( |
| 268 base::SysWideToUTF8(std::wstring(product_name, product_name.Length())); | 300 base::SysWideToUTF8(std::wstring(product_name, product_name.Length()))); |
| 269 product_name.Release(); | 301 product_name.Release(); |
| 270 if (ShouldReportFullNames()) | 302 if (ShouldReportFullNames()) |
| 271 av_product.set_product_name(name); | 303 av_product.set_product_name(name); |
| 272 av_product.set_product_name_hash(metrics::HashName(name)); | 304 av_product.set_product_name_hash(metrics::HashName(name)); |
| 273 | 305 |
| 274 base::win::ScopedBstr remediation_path; | 306 base::win::ScopedBstr remediation_path; |
| 275 result = product->get_RemediationPath(remediation_path.Receive()); | 307 result = product->get_RemediationPath(remediation_path.Receive()); |
| 276 if (FAILED(result)) | 308 if (FAILED(result)) |
| 277 return RESULT_FAILED_TO_GET_REMEDIATION_PATH; | 309 return RESULT_FAILED_TO_GET_REMEDIATION_PATH; |
| 278 std::wstring path_str(remediation_path, remediation_path.Length()); | 310 std::wstring path_str(remediation_path, remediation_path.Length()); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 } | 420 } |
| 389 | 421 |
| 390 base::win::ScopedVariant display_name; | 422 base::win::ScopedVariant display_name; |
| 391 hr = class_object->Get(L"displayName", 0, display_name.Receive(), 0, 0); | 423 hr = class_object->Get(L"displayName", 0, display_name.Receive(), 0, 0); |
| 392 | 424 |
| 393 if (FAILED(hr) || display_name.type() != VT_BSTR) | 425 if (FAILED(hr) || display_name.type() != VT_BSTR) |
| 394 return RESULT_FAILED_TO_GET_PRODUCT_NAME; | 426 return RESULT_FAILED_TO_GET_PRODUCT_NAME; |
| 395 | 427 |
| 396 // Owned by ScopedVariant. | 428 // Owned by ScopedVariant. |
| 397 BSTR temp_bstr = V_BSTR(display_name.ptr()); | 429 BSTR temp_bstr = V_BSTR(display_name.ptr()); |
| 398 std::string name(base::SysWideToUTF8( | 430 std::string name = TrimVersionOfAvProductName(base::SysWideToUTF8( |
| 399 std::wstring(temp_bstr, ::SysStringLen(temp_bstr)))); | 431 std::wstring(temp_bstr, ::SysStringLen(temp_bstr)))); |
| 400 | 432 |
| 401 if (ShouldReportFullNames()) | 433 if (ShouldReportFullNames()) |
| 402 av_product.set_product_name(name); | 434 av_product.set_product_name(name); |
| 403 av_product.set_product_name_hash(metrics::HashName(name)); | 435 av_product.set_product_name_hash(metrics::HashName(name)); |
| 404 | 436 |
| 405 base::win::ScopedVariant exe_path; | 437 base::win::ScopedVariant exe_path; |
| 406 hr = class_object->Get(L"pathToSignedProductExe", 0, exe_path.Receive(), 0, | 438 hr = class_object->Get(L"pathToSignedProductExe", 0, exe_path.Receive(), 0, |
| 407 0); | 439 0); |
| 408 | 440 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 std::string product_name("Trusteer Endpoint Protection"); | 498 std::string product_name("Trusteer Endpoint Protection"); |
| 467 if (ShouldReportFullNames()) { | 499 if (ShouldReportFullNames()) { |
| 468 av_product.set_product_name(product_name); | 500 av_product.set_product_name(product_name); |
| 469 av_product.set_product_version(product_version); | 501 av_product.set_product_version(product_version); |
| 470 } | 502 } |
| 471 av_product.set_product_name_hash(metrics::HashName(product_name)); | 503 av_product.set_product_name_hash(metrics::HashName(product_name)); |
| 472 av_product.set_product_version_hash(metrics::HashName(product_version)); | 504 av_product.set_product_version_hash(metrics::HashName(product_version)); |
| 473 | 505 |
| 474 products->push_back(av_product); | 506 products->push_back(av_product); |
| 475 } | 507 } |
| OLD | NEW |