Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/conflicts/module_info_util_win.h" | 5 #include "chrome/browser/conflicts/module_info_util_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include <tlhelp32.h> | 9 #include <tlhelp32.h> |
| 10 #include <wincrypt.h> | 10 #include <wincrypt.h> |
| 11 #include <wintrust.h> | 11 #include <wintrust.h> |
| 12 | 12 |
| 13 // This must be after wincrypt and wintrust. | 13 // This must be after wincrypt and wintrust. |
| 14 #include <mscat.h> | 14 #include <mscat.h> |
| 15 | 15 |
| 16 #include <limits> | |
| 16 #include <memory> | 17 #include <memory> |
| 17 #include <vector> | 18 #include <string> |
| 18 | 19 |
| 20 #include "base/environment.h" | |
| 21 #include "base/i18n/case_conversion.h" | |
| 19 #include "base/scoped_generic.h" | 22 #include "base/scoped_generic.h" |
| 23 #include "base/strings/string_util.h" | |
| 24 #include "base/strings/utf_string_conversions.h" | |
| 20 #include "base/win/scoped_handle.h" | 25 #include "base/win/scoped_handle.h" |
| 21 | 26 |
| 22 namespace { | 27 namespace { |
| 23 | 28 |
| 24 // Helper for scoped tracking an HCERTSTORE. | 29 // Helper for scoped tracking an HCERTSTORE. |
| 25 struct ScopedHCERTSTORETraits { | 30 struct ScopedHCERTSTORETraits { |
| 26 static HCERTSTORE InvalidValue() { return nullptr; } | 31 static HCERTSTORE InvalidValue() { return nullptr; } |
| 27 static void Free(HCERTSTORE store) { ::CertCloseStore(store, 0); } | 32 static void Free(HCERTSTORE store) { ::CertCloseStore(store, 0); } |
| 28 }; | 33 }; |
| 29 using ScopedHCERTSTORE = | 34 using ScopedHCERTSTORE = |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 return; | 236 return; |
| 232 | 237 |
| 233 base::string16 subject = GetSubjectNameInFile(filename); | 238 base::string16 subject = GetSubjectNameInFile(filename); |
| 234 if (subject.empty()) | 239 if (subject.empty()) |
| 235 return; | 240 return; |
| 236 | 241 |
| 237 certificate_info->type = CertificateType::CERTIFICATE_IN_FILE; | 242 certificate_info->type = CertificateType::CERTIFICATE_IN_FILE; |
| 238 certificate_info->path = filename; | 243 certificate_info->path = filename; |
| 239 certificate_info->subject = subject; | 244 certificate_info->subject = subject; |
| 240 } | 245 } |
| 246 | |
| 247 StringMapping GetEnvironmentVariablesMapping( | |
| 248 const std::vector<base::string16>& environment_variables) { | |
| 249 std::unique_ptr<base::Environment> environment(base::Environment::Create()); | |
| 250 | |
| 251 StringMapping string_mapping; | |
| 252 for (const base::string16& variable : environment_variables) { | |
| 253 std::string value; | |
| 254 if (environment->GetVar(base::UTF16ToASCII(variable).c_str(), &value)) { | |
| 255 string_mapping.push_back( | |
| 256 std::make_pair(base::i18n::ToLower(base::UTF8ToUTF16(value)), | |
| 257 L"%" + base::i18n::ToLower(variable) + L"%")); | |
| 258 } | |
| 259 } | |
| 260 | |
| 261 return string_mapping; | |
| 262 } | |
| 263 | |
| 264 void CollapseMatchingPrefixInString(const StringMapping& prefix_mapping, | |
| 265 base::string16* string) { | |
| 266 size_t min_length = std::numeric_limits<size_t>::max(); | |
| 267 const base::string16& lower_string = base::i18n::ToLower(*string); | |
| 268 for (const auto& mapping : prefix_mapping) { | |
| 269 const base::string16& prefix = base::i18n::ToLower(mapping.first); | |
|
chrisha
2017/02/28 18:51:28
Could we just document that we expect StringMappin
Patrick Monette
2017/02/28 23:37:38
Indeed. Done.
| |
| 270 if (base::StartsWith(lower_string, prefix, base::CompareCase::SENSITIVE)) { | |
|
chrisha
2017/02/28 18:51:29
Do we have expectations that the paths in |prefix_
Patrick Monette
2017/02/28 23:37:38
I don't think this function needs to expect paths
| |
| 271 base::string16 collapsed_string = lower_string; | |
| 272 base::ReplaceFirstSubstringAfterOffset(&collapsed_string, 0, prefix, | |
| 273 mapping.second); | |
| 274 size_t length = collapsed_string.length() - mapping.second.length(); | |
| 275 if (length < min_length) { | |
|
chrisha
2017/02/28 18:51:28
We're only doing the collapsing if it's shorter? W
Patrick Monette
2017/02/28 23:37:38
Chatted offline. Ignored.
| |
| 276 *string = collapsed_string; | |
| 277 min_length = length; | |
| 278 } | |
| 279 } | |
| 280 } | |
| 281 } | |
| OLD | NEW |