<commit_before>// Copyright (c) 2010 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/enumerate_modules_model_win.h"

#include <Tlhelp32.h>
#include <wintrust.h>

#include "app/l10n_util.h"
#include "app/win_util.h"
#include "base/command_line.h"
#include "base/environment.h"
#include "base/file_path.h"
#include "base/file_version_info_win.h"
#include "base/metrics/histogram.h"
#include "base/scoped_handle.h"
#include "base/sha2.h"
#include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "base/version.h"
#include "base/win/registry.h"
#include "chrome/browser/net/service_providers_win.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/notification_service.h"
#include "grit/generated_resources.h"

// The period of time (in milliseconds) to wait until checking to see if any
// incompatible modules exist.
static const int kModuleCheckDelayMs = 60 * 1000;

// The path to the Shell Extension key in the Windows registry.
static const wchar_t kRegPath[] =
    L"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved";

// A sort method that sorts by ModuleType ordinal (loaded module at the top),
// then by full name (including path).
static bool ModuleSort(const ModuleEnumerator::Module& a,
                       const ModuleEnumerator::Module& b) {
  if (a.type != b.type)
    return a.type < b.type;
  if (a.location == b.location)
    return a.name < b.name;

  return a.location < b.location;
}

namespace {

// Used to protect the LoadedModuleVector which is accessed
// from both the UI thread and the FILE thread.
Lock* lock = NULL;

// A struct to help de-duping modules before adding them to the enumerated
// modules vector.
struct FindModule {
 public:
  explicit FindModule(const ModuleEnumerator::Module& x)
    : module(x) {}
  bool operator()(ModuleEnumerator::Module module_in) const {
    return (module.type == module_in.type) &&
      (module.location == module_in.location) &&
      (module.name == module_in.name);
  }

  const ModuleEnumerator::Module& module;
};

}

// The browser process module blacklist. This lists all modules that are known
// to cause compatibility issues within the browser process. When adding to this
// list, make sure that all paths are lower-case, in long pathname form, end
// with a slash and use environments variables (or just look at one of the
// comments below and keep it consistent with that). When adding an entry with
// an environment variable not currently used in the list below, make sure to
// update the list in PreparePathMappings. Filename, Description/Signer, and
// Location must be entered as hashes (see GenerateHash). Filename is mandatory.
// Entries without any Description, Signer info, or Location will never be
// marked as confirmed bad (only as suspicious).
const ModuleEnumerator::BlacklistEntry ModuleEnumerator::kModuleBlacklist[] = {

  // NOTE: Please keep this list sorted by dll name, then location.

  // foldersizecolumn.dll.
  {"5ec91bd7", "", "", "", "", NONE},

  // idmmbc.dll, "%programfiles%\\internet download manager\\", "Tonec Inc.".
  // See: http://crbug.com/26892/.
  {"b8dce5c3", "94541bf5", "d33ad640", "", "", NONE},

  // imon.dll.  See: http://crbug.com/21715.
  {"8f42f22e", "", "", "", "", NONE},

  // is3lsp.dll.  See: http://crbug.com/26892.
  {"7ffbdce9", "", "", "", "", NONE},

  // nvlsp.dll.  See: http://crbug.com/22083.
  {"37f907e2", "", "", "", "", NONE},
<commit_msg>Readd two dlls to the blacklist for demonstration purposes.<commit_after>// Copyright (c) 2010 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/enumerate_modules_model_win.h"

#include <Tlhelp32.h>
#include <wintrust.h>

#include "app/l10n_util.h"
#include "app/win_util.h"
#include "base/command_line.h"
#include "base/environment.h"
#include "base/file_path.h"
#include "base/file_version_info_win.h"
#include "base/metrics/histogram.h"
#include "base/scoped_handle.h"
#include "base/sha2.h"
#include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "base/version.h"
#include "base/win/registry.h"
#include "chrome/browser/net/service_providers_win.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/notification_service.h"
#include "grit/generated_resources.h"

// The period of time (in milliseconds) to wait until checking to see if any
// incompatible modules exist.
static const int kModuleCheckDelayMs = 60 * 1000;

// The path to the Shell Extension key in the Windows registry.
static const wchar_t kRegPath[] =
    L"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved";

// A sort method that sorts by ModuleType ordinal (loaded module at the top),
// then by full name (including path).
static bool ModuleSort(const ModuleEnumerator::Module& a,
                       const ModuleEnumerator::Module& b) {
  if (a.type != b.type)
    return a.type < b.type;
  if (a.location == b.location)
    return a.name < b.name;

  return a.location < b.location;
}

namespace {

// Used to protect the LoadedModuleVector which is accessed
// from both the UI thread and the FILE thread.
Lock* lock = NULL;

// A struct to help de-duping modules before adding them to the enumerated
// modules vector.
struct FindModule {
 public:
  explicit FindModule(const ModuleEnumerator::Module& x)
    : module(x) {}
  // Coverity issue 13896.
  bool operator()(const ModuleEnumerator::Module& module_in) const {
    return (module.type == module_in.type) &&
           (module.location == module_in.location) &&
           (module.name == module_in.name);
  }

  const ModuleEnumerator::Module& module;
};

}

// The browser process module blacklist. This lists all modules that are known
// to cause compatibility issues within the browser process. When adding to this
// list, make sure that all paths are lower-case, in long pathname form, end
// with a slash and use environments variables (or just look at one of the
// comments below and keep it consistent with that). When adding an entry with
// an environment variable not currently used in the list below, make sure to
// update the list in PreparePathMappings. Filename, Description/Signer, and
// Location must be entered as hashes (see GenerateHash). Filename is mandatory.
// Entries without any Description, Signer info, or Location will never be
// marked as confirmed bad (only as suspicious).
const ModuleEnumerator::BlacklistEntry ModuleEnumerator::kModuleBlacklist[] = {
  // Test DLLs, to demonstrate the feature. Will be removed soon.
  {     // apphelp.dll, "%systemroot%\\system32\\"
    "f5fda581", "23d01d5b", "", "", "", NONE
  }, {  // rsaenh.dll, "%systemroot%\\system32\\", "Microsoft Windows"
    "6af212cb", "23d01d5b", "7b47bf79", "", "",
        static_cast<RecommendedAction>(UPDATE | DISABLE | SEE_LINK)
  },

  // NOTE: Please keep this list sorted by dll name, then location.

  // foldersizecolumn.dll.
  {"5ec91bd7", "", "", "", "", NONE},

  // idmmbc.dll, "%programfiles%\\internet download manager\\", "Tonec Inc.".
  // See: http://crbug.com/26892/.
  {"b8dce5c3", "94541bf5", "d33ad640", "", "", NONE},

  // imon.dll.  See: http://crbug.com/21715.
  {"8f42f22e", "", "", "", "", NONE},

  // is3lsp.dll.  See: http://crbug.com/26892.
  {"7ffbdce9", "", "", "", "", NONE},

  // nvlsp.dll.  See: http://crbug.com/22083.
  {"37f907e2", "", "", "", "", NONE},

{'fraction_non_alphanumeric': 0.13422053231939163, 'fraction_numerical': 0.021039290240811154, 'mean_word_length': 3.847051597051597, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3391357', 'n_tokens_mistral': 2598, 'n_tokens_neox': 2486, 'n_words': 785}