| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/install_verification/win/install_verification.h" | 5 #include "chrome/browser/install_verification/win/install_verification.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <windows.h> |
| 8 | 9 |
| 9 #include <set> | 10 #include <set> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 13 #include "base/files/file_path.h" |
| 12 #include "base/metrics/sparse_histogram.h" | 14 #include "base/metrics/sparse_histogram.h" |
| 15 #include "base/process/process.h" |
| 16 #include "base/process/process_handle.h" |
| 17 #include "base/strings/string_util.h" |
| 18 #include "base/strings/sys_string_conversions.h" |
| 13 #include "chrome/browser/install_verification/win/loaded_module_verification.h" | 19 #include "chrome/browser/install_verification/win/loaded_module_verification.h" |
| 14 #include "chrome/browser/install_verification/win/module_ids.h" | 20 #include "chrome/browser/install_verification/win/module_ids.h" |
| 15 #include "chrome/browser/install_verification/win/module_info.h" | 21 #include "chrome/browser/install_verification/win/module_info.h" |
| 16 #include "chrome/browser/install_verification/win/module_verification_common.h" | 22 #include "chrome/browser/install_verification/win/module_verification_common.h" |
| 23 #include "components/variations/metrics_util.h" |
| 17 | 24 |
| 18 namespace { | 25 namespace { |
| 19 | 26 |
| 20 void ReportModuleMatch(size_t module_id) { | 27 void ReportModuleMatch(size_t module_id) { |
| 21 UMA_HISTOGRAM_SPARSE_SLOWLY("InstallVerifier.ModuleMatch", module_id); | 28 UMA_HISTOGRAM_SPARSE_SLOWLY("InstallVerifier.ModuleMatch", module_id); |
| 22 } | 29 } |
| 23 | 30 |
| 31 base::FilePath GetExeFilePathForProcess(const base::Process& process) { |
| 32 wchar_t exe_name[MAX_PATH]; |
| 33 DWORD exe_name_len = arraysize(exe_name); |
| 34 // Note: requesting the Win32 path format. |
| 35 if (::QueryFullProcessImageName(process.Handle(), 0, exe_name, |
| 36 &exe_name_len) == 0) { |
| 37 DPLOG(ERROR) << "Failed to get executable name for process"; |
| 38 return base::FilePath(); |
| 39 } |
| 40 |
| 41 // QueryFullProcessImageName's documentation does not specify behavior when |
| 42 // the buffer is too small, but we know that GetModuleFileNameEx succeeds and |
| 43 // truncates the returned name in such a case. Given that paths of arbitrary |
| 44 // length may exist, the conservative approach is to reject names when |
| 45 // the returned length is that of the buffer. |
| 46 if (exe_name_len > 0 && exe_name_len < arraysize(exe_name)) |
| 47 return base::FilePath(exe_name); |
| 48 |
| 49 return base::FilePath(); |
| 50 } |
| 51 |
| 52 void ReportParentProcessName() { |
| 53 base::ProcessId ppid = |
| 54 base::GetParentProcessId(base::GetCurrentProcessHandle()); |
| 55 |
| 56 base::Process process( |
| 57 base::Process::OpenWithAccess(ppid, PROCESS_QUERY_LIMITED_INFORMATION)); |
| 58 |
| 59 uint32_t hash = 0U; |
| 60 |
| 61 if (process.IsValid()) { |
| 62 base::FilePath path(GetExeFilePathForProcess(process)); |
| 63 |
| 64 if (!path.empty()) { |
| 65 std::string ascii_path(base::SysWideToUTF8(path.BaseName().value())); |
| 66 DCHECK(base::IsStringASCII(ascii_path)); |
| 67 hash = metrics::HashName(base::ToLowerASCII(ascii_path)); |
| 68 } |
| 69 } |
| 70 |
| 71 UMA_HISTOGRAM_SPARSE_SLOWLY("Windows.ParentProcessNameHash", hash); |
| 72 } |
| 73 |
| 24 } // namespace | 74 } // namespace |
| 25 | 75 |
| 26 void VerifyInstallation() { | 76 void VerifyInstallation() { |
| 77 ReportParentProcessName(); |
| 27 ModuleIDs module_ids; | 78 ModuleIDs module_ids; |
| 28 LoadModuleIDs(&module_ids); | 79 LoadModuleIDs(&module_ids); |
| 29 std::set<ModuleInfo> loaded_modules; | 80 std::set<ModuleInfo> loaded_modules; |
| 30 if (GetLoadedModules(&loaded_modules)) { | 81 if (GetLoadedModules(&loaded_modules)) { |
| 31 VerifyLoadedModules(loaded_modules, module_ids, &ReportModuleMatch); | 82 VerifyLoadedModules(loaded_modules, module_ids, &ReportModuleMatch); |
| 32 } | 83 } |
| 33 } | 84 } |
| OLD | NEW |