| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/win/enumerate_modules_model.h" | 5 #include "chrome/browser/win/enumerate_modules_model.h" |
| 6 | 6 |
| 7 #include <softpub.h> | 7 #include <softpub.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <tlhelp32.h> | 10 #include <tlhelp32.h> |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 base::Bind(&ModuleEnumerator::ScanImplModule, base::Unretained(this), 0), | 234 base::Bind(&ModuleEnumerator::ScanImplModule, base::Unretained(this), 0), |
| 235 per_module_delay_); | 235 per_module_delay_); |
| 236 } | 236 } |
| 237 | 237 |
| 238 void ModuleEnumerator::ScanImplModule(size_t index) { | 238 void ModuleEnumerator::ScanImplModule(size_t index) { |
| 239 while (index < enumerated_modules_->size()) { | 239 while (index < enumerated_modules_->size()) { |
| 240 base::TimeTicks start_time = base::TimeTicks::Now(); | 240 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 241 Module& entry = enumerated_modules_->at(index); | 241 Module& entry = enumerated_modules_->at(index); |
| 242 PopulateModuleInformation(&entry); | 242 PopulateModuleInformation(&entry); |
| 243 NormalizeModule(&entry); | 243 NormalizeModule(&entry); |
| 244 CollapsePath(&entry); | 244 CollapseMatchingPrefixInPath(path_mapping_, &entry.location); |
| 245 base::TimeDelta elapsed = base::TimeTicks::Now() - start_time; | 245 base::TimeDelta elapsed = base::TimeTicks::Now() - start_time; |
| 246 enumeration_inspection_time_ += elapsed; | 246 enumeration_inspection_time_ += elapsed; |
| 247 enumeration_total_time_ += elapsed; | 247 enumeration_total_time_ += elapsed; |
| 248 | 248 |
| 249 // If |per_module_delay_| is non-zero, post a task to scan the next module | 249 // If |per_module_delay_| is non-zero, post a task to scan the next module |
| 250 // when the delay expires. | 250 // when the delay expires. |
| 251 if (!per_module_delay_.is_zero()) { | 251 if (!per_module_delay_.is_zero()) { |
| 252 background_task_runner_->PostDelayedTask( | 252 background_task_runner_->PostDelayedTask( |
| 253 FROM_HERE, base::Bind(&ModuleEnumerator::ScanImplModule, | 253 FROM_HERE, base::Bind(&ModuleEnumerator::ScanImplModule, |
| 254 base::Unretained(this), index + 1), | 254 base::Unretained(this), index + 1), |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 FindModule(module)); | 389 FindModule(module)); |
| 390 if (iter != enumerated_modules_->end()) { | 390 if (iter != enumerated_modules_->end()) { |
| 391 iter->duplicate_count++; | 391 iter->duplicate_count++; |
| 392 iter->type = static_cast<ModuleType>(iter->type | module.type); | 392 iter->type = static_cast<ModuleType>(iter->type | module.type); |
| 393 } else { | 393 } else { |
| 394 enumerated_modules_->push_back(module); | 394 enumerated_modules_->push_back(module); |
| 395 } | 395 } |
| 396 } | 396 } |
| 397 | 397 |
| 398 void ModuleEnumerator::PreparePathMappings() { | 398 void ModuleEnumerator::PreparePathMappings() { |
| 399 path_mapping_.clear(); | 399 path_mapping_ = GetEnvironmentVariablesMapping({ |
| 400 | 400 L"LOCALAPPDATA", L"ProgramFiles", L"ProgramData", L"USERPROFILE", |
| 401 std::unique_ptr<base::Environment> environment(base::Environment::Create()); | 401 L"SystemRoot", L"TEMP", L"TMP", L"CommonProgramFiles", |
| 402 std::vector<base::string16> env_vars; | 402 }); |
| 403 env_vars.push_back(L"LOCALAPPDATA"); | |
| 404 env_vars.push_back(L"ProgramFiles"); | |
| 405 env_vars.push_back(L"ProgramData"); | |
| 406 env_vars.push_back(L"USERPROFILE"); | |
| 407 env_vars.push_back(L"SystemRoot"); | |
| 408 env_vars.push_back(L"TEMP"); | |
| 409 env_vars.push_back(L"TMP"); | |
| 410 env_vars.push_back(L"CommonProgramFiles"); | |
| 411 for (std::vector<base::string16>::const_iterator variable = env_vars.begin(); | |
| 412 variable != env_vars.end(); ++variable) { | |
| 413 std::string path; | |
| 414 if (environment->GetVar(base::UTF16ToASCII(*variable).c_str(), &path)) { | |
| 415 path_mapping_.push_back( | |
| 416 std::make_pair(base::i18n::ToLower(base::UTF8ToUTF16(path)) + L"\\", | |
| 417 L"%" + base::i18n::ToLower(*variable) + L"%")); | |
| 418 } | |
| 419 } | |
| 420 } | |
| 421 | |
| 422 void ModuleEnumerator::CollapsePath(Module* entry) { | |
| 423 // Take the path and see if we can use any of the substitution values | |
| 424 // from the vector constructed above to replace c:\windows with, for | |
| 425 // example, %systemroot%. The most collapsed path (the one with the | |
| 426 // minimum length) wins. | |
| 427 size_t min_length = MAXINT; | |
| 428 base::string16 location = entry->location; | |
| 429 for (PathMapping::const_iterator mapping = path_mapping_.begin(); | |
| 430 mapping != path_mapping_.end(); ++mapping) { | |
| 431 const base::string16& prefix = mapping->first; | |
| 432 if (base::StartsWith(base::i18n::ToLower(location), | |
| 433 base::i18n::ToLower(prefix), | |
| 434 base::CompareCase::SENSITIVE)) { | |
| 435 base::string16 new_location = mapping->second + | |
| 436 location.substr(prefix.length() - 1); | |
| 437 size_t length = new_location.length() - mapping->second.length(); | |
| 438 if (length < min_length) { | |
| 439 entry->location = new_location; | |
| 440 min_length = length; | |
| 441 } | |
| 442 } | |
| 443 } | |
| 444 } | 403 } |
| 445 | 404 |
| 446 void ModuleEnumerator::ReportThirdPartyMetrics() { | 405 void ModuleEnumerator::ReportThirdPartyMetrics() { |
| 447 static const wchar_t kMicrosoft[] = L"Microsoft "; | 406 static const wchar_t kMicrosoft[] = L"Microsoft "; |
| 448 static const wchar_t kGoogle[] = L"Google Inc"; | 407 static const wchar_t kGoogle[] = L"Google Inc"; |
| 449 | 408 |
| 450 // Used for counting unique certificates that need to be validated. A | 409 // Used for counting unique certificates that need to be validated. A |
| 451 // catalog counts as a single certificate, as does a file with a baked in | 410 // catalog counts as a single certificate, as does a file with a baked in |
| 452 // certificate. | 411 // certificate. |
| 453 std::set<base::FilePath> unique_certificates; | 412 std::set<base::FilePath> unique_certificates; |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 | 719 |
| 761 UMA_HISTOGRAM_COUNTS_100("Conflicts.SuspectedBadModules", | 720 UMA_HISTOGRAM_COUNTS_100("Conflicts.SuspectedBadModules", |
| 762 suspected_bad_modules_detected_); | 721 suspected_bad_modules_detected_); |
| 763 UMA_HISTOGRAM_COUNTS_100("Conflicts.ConfirmedBadModules", | 722 UMA_HISTOGRAM_COUNTS_100("Conflicts.ConfirmedBadModules", |
| 764 confirmed_bad_modules_detected_); | 723 confirmed_bad_modules_detected_); |
| 765 | 724 |
| 766 // Forward the callback to any registered observers. | 725 // Forward the callback to any registered observers. |
| 767 for (Observer& observer : observers_) | 726 for (Observer& observer : observers_) |
| 768 observer.OnScanCompleted(); | 727 observer.OnScanCompleted(); |
| 769 } | 728 } |
| OLD | NEW |