Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Side by Side Diff: chrome/browser/conflicts/module_info_util_win.cc

Issue 2720513005: Add InspectModule() that returns a populated ModuleInspectionResult struct (Closed)
Patch Set: Comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 value = base::TrimString(value, "\\", base::TRIM_TRAILING).as_string();
256 string_mapping.push_back(
257 std::make_pair(base::i18n::ToLower(base::UTF8ToUTF16(value)),
258 L"%" + base::i18n::ToLower(variable) + L"%"));
259 }
260 }
261
262 return string_mapping;
263 }
264
265 void CollapseMatchingPrefixInString(const StringMapping& prefix_mapping,
266 base::string16* string) {
267 const base::string16 string_copy = *string;
268 DCHECK_EQ(base::i18n::ToLower(string_copy), string_copy);
269
270 size_t min_length = std::numeric_limits<size_t>::max();
271 for (const auto& mapping : prefix_mapping) {
272 DCHECK_EQ(base::i18n::ToLower(mapping.first), mapping.first);
273 if (base::StartsWith(string_copy, mapping.first,
274 base::CompareCase::SENSITIVE)) {
275 base::string16 collapsed_string = string_copy;
276 base::ReplaceFirstSubstringAfterOffset(&collapsed_string, 0,
277 mapping.first, mapping.second);
278 size_t length = collapsed_string.length() - mapping.second.length();
chrisha 2017/03/01 15:45:42 Shouldn't we have logic to ensure the next charact
Patrick Monette 2017/03/02 20:27:07 Done.
279 if (length < min_length) {
280 *string = collapsed_string;
281 min_length = length;
282 }
283 }
284 }
285 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698