root/chrome/browser/install_verification/win/module_verification_common.cc

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. CalculateModuleNameDigest
  2. GetLoadedModules
  3. ReportModuleMatches

// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/install_verification/win/module_verification_common.h"

#include "base/files/file_path.h"
#include "base/md5.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/install_verification/win/loaded_modules_snapshot.h"
#include "chrome/browser/install_verification/win/module_info.h"
#include "chrome/browser/install_verification/win/module_list.h"

std::string CalculateModuleNameDigest(const base::string16& module_name) {
  return base::MD5String(StringToLowerASCII(base::UTF16ToUTF8(
      base::FilePath(module_name).BaseName().value())));
}

bool GetLoadedModules(std::set<ModuleInfo>* loaded_modules) {
  std::vector<HMODULE> snapshot;
  if (!GetLoadedModulesSnapshot(&snapshot))
    return false;

  ModuleList::FromLoadedModuleSnapshot(snapshot)->GetModuleInfoSet(
      loaded_modules);
  return true;
}

void ReportModuleMatches(const std::vector<std::string>& module_name_digests,
                         const ModuleIDs& module_ids,
                         ModuleVerificationDelegate* delegate) {
  for (size_t i = 0; i < module_name_digests.size(); ++i) {
    ModuleIDs::const_iterator entry = module_ids.find(module_name_digests[i]);
    if (entry != module_ids.end())
      delegate(entry->second);
  }
}

/* [<][>][^][v][top][bottom][index][help] */