From 2d650398a9afa1fc3c168aed736daa13901809a8 Mon Sep 17 00:00:00 2001 From: "brettw@chromium.org" Date: Sun, 17 Oct 2010 04:41:54 +0000 Subject: Move pe_image and registry from base to base/win and use the namespace. It removes windows_message_list which isn't used. This keeps a stub for registry in the old location until we can update that. TEST=it compiles BUG=none Review URL: http://codereview.chromium.org/3836005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62888 0039d316-1c4b-4281-b951-d872f2087c98 --- app/win/iat_patch_function.cc | 5 +- app/win/iat_patch_function.h | 1 - base/base.gyp | 9 +- base/base.gypi | 8 +- base/file_util_win.cc | 4 +- base/pe_image.cc | 564 -------------------- base/pe_image.h | 258 ---------- base/pe_image_unittest.cc | 213 -------- base/registry.cc | 381 -------------- base/registry.h | 166 +----- base/registry_unittest.cc | 59 --- base/win/pe_image.cc | 570 +++++++++++++++++++++ base/win/pe_image.h | 264 ++++++++++ base/win/pe_image_unittest.cc | 219 ++++++++ base/win/registry.cc | 387 ++++++++++++++ base/win/registry.h | 171 +++++++ base/win/registry_unittest.cc | 65 +++ base/win_util.cc | 8 +- base/windows_message_list.h | 249 --------- chrome/app/breakpad_win.cc | 8 +- .../autofill/autofill_ie_toolbar_import_win.cc | 10 +- .../autofill_ie_toolbar_import_win_unittest.cc | 4 +- chrome/browser/background_mode_manager.cc | 10 +- chrome/browser/download/download_util.cc | 5 +- chrome/browser/extensions/extension_rlz_apitest.cc | 7 +- .../external_registry_extension_provider_win.cc | 12 +- chrome/browser/first_run/first_run_win.cc | 4 +- chrome/browser/history/history_publisher_win.cc | 4 +- .../browser/importer/firefox_importer_utils_win.cc | 12 +- chrome/browser/importer/ie_importer.cc | 7 +- chrome/browser/platform_util_win.cc | 4 +- chrome/browser/plugin_service.h | 6 +- .../policy/configuration_policy_provider_win.cc | 52 +- .../policy/configuration_policy_provider_win.h | 6 +- .../configuration_policy_provider_win_unittest.cc | 4 +- chrome/browser/rlz/rlz_unittest.cc | 5 +- chrome/browser/shell_integration_win.cc | 9 +- chrome/browser/views/external_protocol_dialog.cc | 4 +- chrome/browser/views/shell_dialogs_win.cc | 8 +- chrome/common/chrome_plugin_lib.cc | 4 +- chrome/installer/setup/install.cc | 11 +- chrome/installer/setup/uninstall.cc | 4 +- chrome/installer/util/browser_distribution.cc | 4 +- chrome/installer/util/browser_distribution.h | 6 +- chrome/installer/util/compat_checks.cc | 4 +- chrome/installer/util/create_reg_key_work_item.cc | 4 +- .../util/create_reg_key_work_item_unittest.cc | 41 +- .../installer/util/delete_after_reboot_helper.cc | 10 +- .../util/delete_after_reboot_helper_unittest.cc | 9 +- .../installer/util/delete_reg_value_work_item.cc | 4 +- .../util/delete_reg_value_work_item_unittest.cc | 43 +- .../installer/util/google_chrome_distribution.cc | 8 +- chrome/installer/util/google_chrome_distribution.h | 2 +- .../util/google_chrome_distribution_dummy.cc | 3 +- chrome/installer/util/google_update_settings.cc | 4 +- .../util/google_update_settings_unittest.cc | 4 +- chrome/installer/util/install_util.cc | 4 +- chrome/installer/util/install_util.h | 8 +- chrome/installer/util/set_reg_value_work_item.cc | 6 +- .../util/set_reg_value_work_item_unittest.cc | 48 +- chrome/installer/util/shell_util.cc | 7 +- chrome/installer/util/work_item_list_unittest.cc | 72 +-- .../mini_installer_test/chrome_mini_installer.cc | 4 +- chrome/test/plugin/plugin_test.cpp | 4 +- chrome_frame/chrome_tab.cc | 4 +- chrome_frame/crash_reporting/crash_metrics.cc | 6 +- chrome_frame/policy_settings.cc | 4 +- chrome_frame/test/chrome_frame_test_utils.cc | 7 +- chrome_frame/test/perf/chrome_frame_perftest.cc | 7 +- chrome_frame/test/policy_settings_unittest.cc | 4 +- chrome_frame/test/util_unittests.cc | 4 +- chrome_frame/utils.cc | 12 +- net/base/platform_mime_util_win.cc | 10 +- net/base/ssl_config_service_win.cc | 3 +- net/proxy/proxy_config_service_win.cc | 4 +- sandbox/src/eat_resolver.cc | 4 +- sandbox/src/interception.cc | 4 +- sandbox/src/policy_broker.cc | 4 +- sandbox/src/resolver.cc | 4 +- sandbox/src/sandbox_nt_util.cc | 4 +- sandbox/src/service_resolver.cc | 4 +- sandbox/src/sidestep_resolver.cc | 4 +- sandbox/src/target_process.cc | 4 +- webkit/glue/plugins/plugin_list_win.cc | 16 +- webkit/glue/plugins/webplugin_delegate_impl_win.cc | 4 +- 85 files changed, 2064 insertions(+), 2153 deletions(-) delete mode 100644 base/pe_image.cc delete mode 100644 base/pe_image.h delete mode 100644 base/pe_image_unittest.cc delete mode 100644 base/registry.cc delete mode 100644 base/registry_unittest.cc create mode 100644 base/win/pe_image.cc create mode 100644 base/win/pe_image.h create mode 100644 base/win/pe_image_unittest.cc create mode 100644 base/win/registry.cc create mode 100644 base/win/registry.h create mode 100644 base/win/registry_unittest.cc delete mode 100644 base/windows_message_list.h diff --git a/app/win/iat_patch_function.cc b/app/win/iat_patch_function.cc index 3f90d81..a78a357 100644 --- a/app/win/iat_patch_function.cc +++ b/app/win/iat_patch_function.cc @@ -5,6 +5,7 @@ #include "app/win/iat_patch_function.h" #include "base/logging.h" +#include "base/win/pe_image.h" namespace app { namespace win { @@ -79,7 +80,7 @@ DWORD ModifyCode(void* old_code, void* new_code, int length) { return error; } -bool InterceptEnumCallback(const PEImage &image, const char* module, +bool InterceptEnumCallback(const base::win::PEImage& image, const char* module, DWORD ordinal, const char* name, DWORD hint, IMAGE_THUNK_DATA* iat, void* cookie) { InterceptFunctionInformation* intercept_information = @@ -147,7 +148,7 @@ DWORD InterceptImportedFunction(HMODULE module_handle, return ERROR_INVALID_PARAMETER; } - PEImage target_image(module_handle); + base::win::PEImage target_image(module_handle); if (!target_image.VerifyMagic()) { NOTREACHED(); return ERROR_INVALID_PARAMETER; diff --git a/app/win/iat_patch_function.h b/app/win/iat_patch_function.h index 37961dd..4a2aa0c 100644 --- a/app/win/iat_patch_function.h +++ b/app/win/iat_patch_function.h @@ -9,7 +9,6 @@ #include #include "base/basictypes.h" -#include "base/pe_image.h" namespace app { namespace win { diff --git a/base/base.gyp b/base/base.gyp index e432815..5145404 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -113,7 +113,6 @@ 'object_watcher_unittest.cc', 'observer_list_unittest.cc', 'path_service_unittest.cc', - 'pe_image_unittest.cc', 'pickle_unittest.cc', 'platform_file_unittest.cc', 'platform_thread_unittest.cc', @@ -123,7 +122,6 @@ 'process_util_unittest_mac.mm', 'rand_util_unittest.cc', 'ref_counted_unittest.cc', - 'registry_unittest.cc', 'scoped_native_library_unittest.cc', 'scoped_ptr_unittest.cc', 'scoped_temp_dir_unittest.cc', @@ -165,6 +163,8 @@ 'watchdog_unittest.cc', 'weak_ptr_unittest.cc', 'win_util_unittest.cc', + 'win/pe_image_unittest.cc', + 'win/registry_unittest.cc', 'win/scoped_bstr_unittest.cc', 'win/scoped_comptr_unittest.cc', 'win/scoped_variant_unittest.cc', @@ -221,11 +221,6 @@ 'event_trace_controller_win_unittest.cc', 'event_trace_provider_win_unittest.cc', 'object_watcher_unittest.cc', - 'pe_image_unittest.cc', - 'registry_unittest.cc', - 'scoped_bstr_win_unittest.cc', - 'scoped_comptr_win_unittest.cc', - 'scoped_variant_win_unittest.cc', 'system_monitor_unittest.cc', 'time_win_unittest.cc', 'trace_event_win_unittest.cc', diff --git a/base/base.gypi b/base/base.gypi index b608e82..b449a89 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -156,8 +156,6 @@ 'observer_list_threadsafe.h', 'path_service.cc', 'path_service.h', - 'pe_image.cc', - 'pe_image.h', 'pickle.cc', 'pickle.h', 'platform_file.h', @@ -189,8 +187,6 @@ 'ref_counted.h', 'ref_counted_memory.cc', 'ref_counted_memory.h', - 'registry.cc', - 'registry.h', 'resource_util.cc', 'resource_util.h', 'safe_strerror_posix.cc', @@ -295,6 +291,10 @@ 'watchdog.h', 'weak_ptr.cc', 'weak_ptr.h', + 'win/pe_image.cc', + 'win/pe_image.h', + 'win/registry.cc', + 'win/registry.h', 'win/scoped_bstr.cc', 'win/scoped_bstr.h', 'win/scoped_comptr.h', diff --git a/base/file_util_win.cc b/base/file_util_win.cc index 213833b..d9f8404 100644 --- a/base/file_util_win.cc +++ b/base/file_util_win.cc @@ -15,7 +15,7 @@ #include "base/file_path.h" #include "base/logging.h" #include "base/metrics/histogram.h" -#include "base/pe_image.h" +#include "base/win/pe_image.h" #include "base/win/scoped_handle.h" #include "base/string_number_conversions.h" #include "base/string_util.h" @@ -1051,7 +1051,7 @@ bool PreReadImage(const wchar_t* file_path, size_t size_to_read, if (!dll_module) return false; - PEImage pe_image(dll_module); + base::win::PEImage pe_image(dll_module); PIMAGE_NT_HEADERS nt_headers = pe_image.GetNTHeaders(); size_t actual_size_to_read = size_to_read ? size_to_read : nt_headers->OptionalHeader.SizeOfImage; diff --git a/base/pe_image.cc b/base/pe_image.cc deleted file mode 100644 index 36eb0e4..0000000 --- a/base/pe_image.cc +++ /dev/null @@ -1,564 +0,0 @@ -// Copyright (c) 2006-2008 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. - -// This file implements PEImage, a generic class to manipulate PE files. -// This file was adapted from GreenBorder's Code. - -#include "base/pe_image.h" - -#if defined(_WIN64) && !defined(NACL_WIN64) -// TODO(rvargas): Bug 27218. Make sure this is ok. -#error This code is not tested on x64. Please make sure all the base unit tests\ - pass before doing any real work. The current unit tests don't test the\ - differences between 32- and 64-bits implementations. Bugs may slip through.\ - You need to improve the coverage before continuing. -#endif - -// Structure to perform imports enumerations. -struct EnumAllImportsStorage { - PEImage::EnumImportsFunction callback; - PVOID cookie; -}; - -namespace { - - // Compare two strings byte by byte on an unsigned basis. - // if s1 == s2, return 0 - // if s1 < s2, return negative - // if s1 > s2, return positive - // Exception if inputs are invalid. - int StrCmpByByte(LPCSTR s1, LPCSTR s2) { - while (*s1 != '\0' && *s1 == *s2) { - ++s1; - ++s2; - } - - return (*reinterpret_cast(s1) - - *reinterpret_cast(s2)); - } - -} // namespace - -// Callback used to enumerate imports. See EnumImportChunksFunction. -bool ProcessImportChunk(const PEImage &image, LPCSTR module, - PIMAGE_THUNK_DATA name_table, - PIMAGE_THUNK_DATA iat, PVOID cookie) { - EnumAllImportsStorage &storage = *reinterpret_cast( - cookie); - - return image.EnumOneImportChunk(storage.callback, module, name_table, iat, - storage.cookie); -} - -// Callback used to enumerate delay imports. See EnumDelayImportChunksFunction. -bool ProcessDelayImportChunk(const PEImage &image, - PImgDelayDescr delay_descriptor, - LPCSTR module, PIMAGE_THUNK_DATA name_table, - PIMAGE_THUNK_DATA iat, PIMAGE_THUNK_DATA bound_iat, - PIMAGE_THUNK_DATA unload_iat, PVOID cookie) { - EnumAllImportsStorage &storage = *reinterpret_cast( - cookie); - - return image.EnumOneDelayImportChunk(storage.callback, delay_descriptor, - module, name_table, iat, bound_iat, - unload_iat, storage.cookie); -} - -void PEImage::set_module(HMODULE module) { - module_ = module; -} - -PIMAGE_DOS_HEADER PEImage::GetDosHeader() const { - return reinterpret_cast(module_); -} - -PIMAGE_NT_HEADERS PEImage::GetNTHeaders() const { - PIMAGE_DOS_HEADER dos_header = GetDosHeader(); - - return reinterpret_cast( - reinterpret_cast(dos_header) + dos_header->e_lfanew); -} - -PIMAGE_SECTION_HEADER PEImage::GetSectionHeader(UINT section) const { - PIMAGE_NT_HEADERS nt_headers = GetNTHeaders(); - PIMAGE_SECTION_HEADER first_section = IMAGE_FIRST_SECTION(nt_headers); - - if (section < nt_headers->FileHeader.NumberOfSections) - return first_section + section; - else - return NULL; -} - -WORD PEImage::GetNumSections() const { - return GetNTHeaders()->FileHeader.NumberOfSections; -} - -DWORD PEImage::GetImageDirectoryEntrySize(UINT directory) const { - PIMAGE_NT_HEADERS nt_headers = GetNTHeaders(); - - return nt_headers->OptionalHeader.DataDirectory[directory].Size; -} - -PVOID PEImage::GetImageDirectoryEntryAddr(UINT directory) const { - PIMAGE_NT_HEADERS nt_headers = GetNTHeaders(); - - return RVAToAddr( - nt_headers->OptionalHeader.DataDirectory[directory].VirtualAddress); -} - -PIMAGE_SECTION_HEADER PEImage::GetImageSectionFromAddr(PVOID address) const { - PBYTE target = reinterpret_cast(address); - PIMAGE_SECTION_HEADER section; - - for (UINT i = 0; NULL != (section = GetSectionHeader(i)); i++) { - // Don't use the virtual RVAToAddr. - PBYTE start = reinterpret_cast( - PEImage::RVAToAddr(section->VirtualAddress)); - - DWORD size = section->Misc.VirtualSize; - - if ((start <= target) && (start + size > target)) - return section; - } - - return NULL; -} - -PIMAGE_SECTION_HEADER PEImage::GetImageSectionHeaderByName( - LPCSTR section_name) const { - if (NULL == section_name) - return NULL; - - PIMAGE_SECTION_HEADER ret = NULL; - int num_sections = GetNumSections(); - - for (int i = 0; i < num_sections; i++) { - PIMAGE_SECTION_HEADER section = GetSectionHeader(i); - if (0 == _strnicmp(reinterpret_cast(section->Name), section_name, - sizeof(section->Name))) { - ret = section; - break; - } - } - - return ret; -} - -PDWORD PEImage::GetExportEntry(LPCSTR name) const { - PIMAGE_EXPORT_DIRECTORY exports = GetExportDirectory(); - - if (NULL == exports) - return NULL; - - WORD ordinal = 0; - if (!GetProcOrdinal(name, &ordinal)) - return NULL; - - PDWORD functions = reinterpret_cast( - RVAToAddr(exports->AddressOfFunctions)); - - return functions + ordinal - exports->Base; -} - -FARPROC PEImage::GetProcAddress(LPCSTR function_name) const { - PDWORD export_entry = GetExportEntry(function_name); - if (NULL == export_entry) - return NULL; - - PBYTE function = reinterpret_cast(RVAToAddr(*export_entry)); - - PBYTE exports = reinterpret_cast( - GetImageDirectoryEntryAddr(IMAGE_DIRECTORY_ENTRY_EXPORT)); - DWORD size = GetImageDirectoryEntrySize(IMAGE_DIRECTORY_ENTRY_EXPORT); - - // Check for forwarded exports as a special case. - if (exports <= function && exports + size > function) -#pragma warning(push) -#pragma warning(disable: 4312) - // This cast generates a warning because it is 32 bit specific. - return reinterpret_cast(0xFFFFFFFF); -#pragma warning(pop) - - return reinterpret_cast(function); -} - -bool PEImage::GetProcOrdinal(LPCSTR function_name, WORD *ordinal) const { - if (NULL == ordinal) - return false; - - PIMAGE_EXPORT_DIRECTORY exports = GetExportDirectory(); - - if (NULL == exports) - return false; - - if (IsOrdinal(function_name)) { - *ordinal = ToOrdinal(function_name); - } else { - PDWORD names = reinterpret_cast(RVAToAddr(exports->AddressOfNames)); - PDWORD lower = names; - PDWORD upper = names + exports->NumberOfNames; - int cmp = -1; - - // Binary Search for the name. - while (lower != upper) { - PDWORD middle = lower + (upper - lower) / 2; - LPCSTR name = reinterpret_cast(RVAToAddr(*middle)); - - // This may be called by sandbox before MSVCRT dll loads, so can't use - // CRT function here. - cmp = StrCmpByByte(function_name, name); - - if (cmp == 0) { - lower = middle; - break; - } - - if (cmp > 0) - lower = middle + 1; - else - upper = middle; - } - - if (cmp != 0) - return false; - - - PWORD ordinals = reinterpret_cast( - RVAToAddr(exports->AddressOfNameOrdinals)); - - *ordinal = ordinals[lower - names] + static_cast(exports->Base); - } - - return true; -} - -bool PEImage::EnumSections(EnumSectionsFunction callback, PVOID cookie) const { - PIMAGE_NT_HEADERS nt_headers = GetNTHeaders(); - UINT num_sections = nt_headers->FileHeader.NumberOfSections; - PIMAGE_SECTION_HEADER section = GetSectionHeader(0); - - for (UINT i = 0; i < num_sections; i++, section++) { - PVOID section_start = RVAToAddr(section->VirtualAddress); - DWORD size = section->Misc.VirtualSize; - - if (!callback(*this, section, section_start, size, cookie)) - return false; - } - - return true; -} - -bool PEImage::EnumExports(EnumExportsFunction callback, PVOID cookie) const { - PVOID directory = GetImageDirectoryEntryAddr(IMAGE_DIRECTORY_ENTRY_EXPORT); - DWORD size = GetImageDirectoryEntrySize(IMAGE_DIRECTORY_ENTRY_EXPORT); - - // Check if there are any exports at all. - if (NULL == directory || 0 == size) - return true; - - PIMAGE_EXPORT_DIRECTORY exports = reinterpret_cast( - directory); - UINT ordinal_base = exports->Base; - UINT num_funcs = exports->NumberOfFunctions; - UINT num_names = exports->NumberOfNames; - PDWORD functions = reinterpret_cast(RVAToAddr( - exports->AddressOfFunctions)); - PDWORD names = reinterpret_cast(RVAToAddr(exports->AddressOfNames)); - PWORD ordinals = reinterpret_cast(RVAToAddr( - exports->AddressOfNameOrdinals)); - - for (UINT count = 0; count < num_funcs; count++) { - PVOID func = RVAToAddr(functions[count]); - if (NULL == func) - continue; - - // Check for a name. - LPCSTR name = NULL; - UINT hint; - for (hint = 0; hint < num_names; hint++) { - if (ordinals[hint] == count) { - name = reinterpret_cast(RVAToAddr(names[hint])); - break; - } - } - - if (name == NULL) - hint = 0; - - // Check for forwarded exports. - LPCSTR forward = NULL; - if (reinterpret_cast(func) >= reinterpret_cast(directory) && - reinterpret_cast(func) <= reinterpret_cast(directory) + - size) { - forward = reinterpret_cast(func); - func = 0; - } - - if (!callback(*this, ordinal_base + count, hint, name, func, forward, - cookie)) - return false; - } - - return true; -} - -bool PEImage::EnumRelocs(EnumRelocsFunction callback, PVOID cookie) const { - PVOID directory = GetImageDirectoryEntryAddr(IMAGE_DIRECTORY_ENTRY_BASERELOC); - DWORD size = GetImageDirectoryEntrySize(IMAGE_DIRECTORY_ENTRY_BASERELOC); - PIMAGE_BASE_RELOCATION base = reinterpret_cast( - directory); - - if (directory == NULL || size < sizeof(IMAGE_BASE_RELOCATION)) - return true; - - while (base->SizeOfBlock) { - PWORD reloc = reinterpret_cast(base + 1); - UINT num_relocs = (base->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION)) / - sizeof(WORD); - - for (UINT i = 0; i < num_relocs; i++, reloc++) { - WORD type = *reloc >> 12; - PVOID address = RVAToAddr(base->VirtualAddress + (*reloc & 0x0FFF)); - - if (!callback(*this, type, address, cookie)) - return false; - } - - base = reinterpret_cast( - reinterpret_cast(base) + base->SizeOfBlock); - } - - return true; -} - -bool PEImage::EnumImportChunks(EnumImportChunksFunction callback, - PVOID cookie) const { - DWORD size = GetImageDirectoryEntrySize(IMAGE_DIRECTORY_ENTRY_IMPORT); - PIMAGE_IMPORT_DESCRIPTOR import = GetFirstImportChunk(); - - if (import == NULL || size < sizeof(IMAGE_IMPORT_DESCRIPTOR)) - return true; - - for (; import->FirstThunk; import++) { - LPCSTR module_name = reinterpret_cast(RVAToAddr(import->Name)); - PIMAGE_THUNK_DATA name_table = reinterpret_cast( - RVAToAddr(import->OriginalFirstThunk)); - PIMAGE_THUNK_DATA iat = reinterpret_cast( - RVAToAddr(import->FirstThunk)); - - if (!callback(*this, module_name, name_table, iat, cookie)) - return false; - } - - return true; -} - -bool PEImage::EnumOneImportChunk(EnumImportsFunction callback, - LPCSTR module_name, - PIMAGE_THUNK_DATA name_table, - PIMAGE_THUNK_DATA iat, PVOID cookie) const { - if (NULL == name_table) - return false; - - for (; name_table && name_table->u1.Ordinal; name_table++, iat++) { - LPCSTR name = NULL; - WORD ordinal = 0; - WORD hint = 0; - - if (IMAGE_SNAP_BY_ORDINAL(name_table->u1.Ordinal)) { - ordinal = static_cast(IMAGE_ORDINAL32(name_table->u1.Ordinal)); - } else { - PIMAGE_IMPORT_BY_NAME import = reinterpret_cast( - RVAToAddr(name_table->u1.ForwarderString)); - - hint = import->Hint; - name = reinterpret_cast(&import->Name); - } - - if (!callback(*this, module_name, ordinal, name, hint, iat, cookie)) - return false; - } - - return true; -} - -bool PEImage::EnumAllImports(EnumImportsFunction callback, PVOID cookie) const { - EnumAllImportsStorage temp = { callback, cookie }; - return EnumImportChunks(ProcessImportChunk, &temp); -} - -bool PEImage::EnumDelayImportChunks(EnumDelayImportChunksFunction callback, - PVOID cookie) const { - PVOID directory = GetImageDirectoryEntryAddr( - IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT); - DWORD size = GetImageDirectoryEntrySize(IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT); - PImgDelayDescr delay_descriptor = reinterpret_cast(directory); - - if (directory == NULL || size == 0) - return true; - - for (; delay_descriptor->rvaHmod; delay_descriptor++) { - PIMAGE_THUNK_DATA name_table; - PIMAGE_THUNK_DATA iat; - PIMAGE_THUNK_DATA bound_iat; // address of the optional bound IAT - PIMAGE_THUNK_DATA unload_iat; // address of optional copy of original IAT - LPCSTR module_name; - - // check if VC7-style imports, using RVAs instead of - // VC6-style addresses. - bool rvas = (delay_descriptor->grAttrs & dlattrRva) != 0; - - if (rvas) { - module_name = reinterpret_cast( - RVAToAddr(delay_descriptor->rvaDLLName)); - name_table = reinterpret_cast( - RVAToAddr(delay_descriptor->rvaINT)); - iat = reinterpret_cast( - RVAToAddr(delay_descriptor->rvaIAT)); - bound_iat = reinterpret_cast( - RVAToAddr(delay_descriptor->rvaBoundIAT)); - unload_iat = reinterpret_cast( - RVAToAddr(delay_descriptor->rvaUnloadIAT)); - } else { -#pragma warning(push) -#pragma warning(disable: 4312) - // These casts generate warnings because they are 32 bit specific. - module_name = reinterpret_cast(delay_descriptor->rvaDLLName); - name_table = reinterpret_cast( - delay_descriptor->rvaINT); - iat = reinterpret_cast(delay_descriptor->rvaIAT); - bound_iat = reinterpret_cast( - delay_descriptor->rvaBoundIAT); - unload_iat = reinterpret_cast( - delay_descriptor->rvaUnloadIAT); -#pragma warning(pop) - } - - if (!callback(*this, delay_descriptor, module_name, name_table, iat, - bound_iat, unload_iat, cookie)) - return false; - } - - return true; -} - -bool PEImage::EnumOneDelayImportChunk(EnumImportsFunction callback, - PImgDelayDescr delay_descriptor, - LPCSTR module_name, - PIMAGE_THUNK_DATA name_table, - PIMAGE_THUNK_DATA iat, - PIMAGE_THUNK_DATA bound_iat, - PIMAGE_THUNK_DATA unload_iat, - PVOID cookie) const { - UNREFERENCED_PARAMETER(bound_iat); - UNREFERENCED_PARAMETER(unload_iat); - - for (; name_table->u1.Ordinal; name_table++, iat++) { - LPCSTR name = NULL; - WORD ordinal = 0; - WORD hint = 0; - - if (IMAGE_SNAP_BY_ORDINAL(name_table->u1.Ordinal)) { - ordinal = static_cast(IMAGE_ORDINAL32(name_table->u1.Ordinal)); - } else { - PIMAGE_IMPORT_BY_NAME import; - bool rvas = (delay_descriptor->grAttrs & dlattrRva) != 0; - - if (rvas) { - import = reinterpret_cast( - RVAToAddr(name_table->u1.ForwarderString)); - } else { -#pragma warning(push) -#pragma warning(disable: 4312) - // This cast generates a warning because it is 32 bit specific. - import = reinterpret_cast( - name_table->u1.ForwarderString); -#pragma warning(pop) - } - - hint = import->Hint; - name = reinterpret_cast(&import->Name); - } - - if (!callback(*this, module_name, ordinal, name, hint, iat, cookie)) - return false; - } - - return true; -} - -bool PEImage::EnumAllDelayImports(EnumImportsFunction callback, - PVOID cookie) const { - EnumAllImportsStorage temp = { callback, cookie }; - return EnumDelayImportChunks(ProcessDelayImportChunk, &temp); -} - -bool PEImage::VerifyMagic() const { - PIMAGE_DOS_HEADER dos_header = GetDosHeader(); - - if (dos_header->e_magic != IMAGE_DOS_SIGNATURE) - return false; - - PIMAGE_NT_HEADERS nt_headers = GetNTHeaders(); - - if (nt_headers->Signature != IMAGE_NT_SIGNATURE) - return false; - - if (nt_headers->FileHeader.SizeOfOptionalHeader != - sizeof(IMAGE_OPTIONAL_HEADER)) - return false; - - if (nt_headers->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR_MAGIC) - return false; - - return true; -} - -bool PEImage::ImageRVAToOnDiskOffset(DWORD rva, DWORD *on_disk_offset) const { - LPVOID address = RVAToAddr(rva); - return ImageAddrToOnDiskOffset(address, on_disk_offset); -} - -bool PEImage::ImageAddrToOnDiskOffset(LPVOID address, - DWORD *on_disk_offset) const { - if (NULL == address) - return false; - - // Get the section that this address belongs to. - PIMAGE_SECTION_HEADER section_header = GetImageSectionFromAddr(address); - if (NULL == section_header) - return false; - -#pragma warning(push) -#pragma warning(disable: 4311) - // These casts generate warnings because they are 32 bit specific. - // Don't follow the virtual RVAToAddr, use the one on the base. - DWORD offset_within_section = reinterpret_cast(address) - - reinterpret_cast(PEImage::RVAToAddr( - section_header->VirtualAddress)); -#pragma warning(pop) - - *on_disk_offset = section_header->PointerToRawData + offset_within_section; - return true; -} - -PVOID PEImage::RVAToAddr(DWORD rva) const { - if (rva == 0) - return NULL; - - return reinterpret_cast(module_) + rva; -} - -PVOID PEImageAsData::RVAToAddr(DWORD rva) const { - if (rva == 0) - return NULL; - - PVOID in_memory = PEImage::RVAToAddr(rva); - DWORD dummy; - - if (!ImageAddrToOnDiskOffset(in_memory, &dummy)) - return NULL; - - return in_memory; -} diff --git a/base/pe_image.h b/base/pe_image.h deleted file mode 100644 index 968d056..0000000 --- a/base/pe_image.h +++ /dev/null @@ -1,258 +0,0 @@ -// Copyright (c) 2006-2008 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. - -// This file was adapted from GreenBorder's Code. -// To understand what this class is about (for other than well known functions -// as GetProcAddress), a good starting point is "An In-Depth Look into the -// Win32 Portable Executable File Format" by Matt Pietrek: -// http://msdn.microsoft.com/msdnmag/issues/02/02/PE/default.aspx - -#ifndef BASE_PE_IMAGE_H_ -#define BASE_PE_IMAGE_H_ -#pragma once - -#include -#include - -// This class is a wrapper for the Portable Executable File Format (PE). -// It's main purpose is to provide an easy way to work with imports and exports -// from a file, mapped in memory as image. -class PEImage { - public: - // Callback to enumerate sections. - // cookie is the value passed to the enumerate method. - // Returns true to continue the enumeration. - typedef bool (*EnumSectionsFunction)(const PEImage &image, - PIMAGE_SECTION_HEADER header, - PVOID section_start, DWORD section_size, - PVOID cookie); - - // Callback to enumerate exports. - // function is the actual address of the symbol. If forward is not null, it - // contains the dll and symbol to forward this export to. cookie is the value - // passed to the enumerate method. - // Returns true to continue the enumeration. - typedef bool (*EnumExportsFunction)(const PEImage &image, DWORD ordinal, - DWORD hint, LPCSTR name, PVOID function, - LPCSTR forward, PVOID cookie); - - // Callback to enumerate import blocks. - // name_table and iat point to the imports name table and address table for - // this block. cookie is the value passed to the enumerate method. - // Returns true to continue the enumeration. - typedef bool (*EnumImportChunksFunction)(const PEImage &image, LPCSTR module, - PIMAGE_THUNK_DATA name_table, - PIMAGE_THUNK_DATA iat, PVOID cookie); - - // Callback to enumerate imports. - // module is the dll that exports this symbol. cookie is the value passed to - // the enumerate method. - // Returns true to continue the enumeration. - typedef bool (*EnumImportsFunction)(const PEImage &image, LPCSTR module, - DWORD ordinal, LPCSTR name, DWORD hint, - PIMAGE_THUNK_DATA iat, PVOID cookie); - - // Callback to enumerate dalayed import blocks. - // module is the dll that exports this block of symbols. cookie is the value - // passed to the enumerate method. - // Returns true to continue the enumeration. - typedef bool (*EnumDelayImportChunksFunction)(const PEImage &image, - PImgDelayDescr delay_descriptor, - LPCSTR module, - PIMAGE_THUNK_DATA name_table, - PIMAGE_THUNK_DATA iat, - PIMAGE_THUNK_DATA bound_iat, - PIMAGE_THUNK_DATA unload_iat, - PVOID cookie); - - // Callback to enumerate relocations. - // cookie is the value passed to the enumerate method. - // Returns true to continue the enumeration. - typedef bool (*EnumRelocsFunction)(const PEImage &image, WORD type, - PVOID address, PVOID cookie); - - explicit PEImage(HMODULE module) : module_(module) {} - explicit PEImage(const void* module) { - module_ = reinterpret_cast(const_cast(module)); - } - - // Gets the HMODULE for this object. - HMODULE module() const; - - // Sets this object's HMODULE. - void set_module(HMODULE module); - - // Checks if this symbol is actually an ordinal. - static bool IsOrdinal(LPCSTR name); - - // Converts a named symbol to the corresponding ordinal. - static WORD ToOrdinal(LPCSTR name); - - // Returns the DOS_HEADER for this PE. - PIMAGE_DOS_HEADER GetDosHeader() const; - - // Returns the NT_HEADER for this PE. - PIMAGE_NT_HEADERS GetNTHeaders() const; - - // Returns number of sections of this PE. - WORD GetNumSections() const; - - // Returns the header for a given section. - // returns NULL if there is no such section. - PIMAGE_SECTION_HEADER GetSectionHeader(UINT section) const; - - // Returns the size of a given directory entry. - DWORD GetImageDirectoryEntrySize(UINT directory) const; - - // Returns the address of a given directory entry. - PVOID GetImageDirectoryEntryAddr(UINT directory) const; - - // Returns the section header for a given address. - // Use: s = image.GetImageSectionFromAddr(a); - // Post: 's' is the section header of the section that contains 'a' - // or NULL if there is no such section. - PIMAGE_SECTION_HEADER GetImageSectionFromAddr(PVOID address) const; - - // Returns the section header for a given section. - PIMAGE_SECTION_HEADER GetImageSectionHeaderByName(LPCSTR section_name) const; - - // Returns the first block of imports. - PIMAGE_IMPORT_DESCRIPTOR GetFirstImportChunk() const; - - // Returns the exports directory. - PIMAGE_EXPORT_DIRECTORY GetExportDirectory() const; - - // Returns a given export entry. - // Use: e = image.GetExportEntry(f); - // Pre: 'f' is either a zero terminated string or ordinal - // Post: 'e' is a pointer to the export directory entry - // that contains 'f's export RVA, or NULL if 'f' - // is not exported from this image - PDWORD GetExportEntry(LPCSTR name) const; - - // Returns the address for a given exported symbol. - // Use: p = image.GetProcAddress(f); - // Pre: 'f' is either a zero terminated string or ordinal. - // Post: if 'f' is a non-forwarded export from image, 'p' is - // the exported function. If 'f' is a forwarded export - // then p is the special value 0xFFFFFFFF. In this case - // RVAToAddr(*GetExportEntry) can be used to resolve - // the string that describes the forward. - FARPROC GetProcAddress(LPCSTR function_name) const; - - // Retrieves the ordinal for a given exported symbol. - // Returns true if the symbol was found. - bool GetProcOrdinal(LPCSTR function_name, WORD *ordinal) const; - - // Enumerates PE sections. - // cookie is a generic cookie to pass to the callback. - // Returns true on success. - bool EnumSections(EnumSectionsFunction callback, PVOID cookie) const; - - // Enumerates PE exports. - // cookie is a generic cookie to pass to the callback. - // Returns true on success. - bool EnumExports(EnumExportsFunction callback, PVOID cookie) const; - - // Enumerates PE imports. - // cookie is a generic cookie to pass to the callback. - // Returns true on success. - bool EnumAllImports(EnumImportsFunction callback, PVOID cookie) const; - - // Enumerates PE import blocks. - // cookie is a generic cookie to pass to the callback. - // Returns true on success. - bool EnumImportChunks(EnumImportChunksFunction callback, PVOID cookie) const; - - // Enumerates the imports from a single PE import block. - // cookie is a generic cookie to pass to the callback. - // Returns true on success. - bool EnumOneImportChunk(EnumImportsFunction callback, LPCSTR module_name, - PIMAGE_THUNK_DATA name_table, PIMAGE_THUNK_DATA iat, - PVOID cookie) const; - - - // Enumerates PE delay imports. - // cookie is a generic cookie to pass to the callback. - // Returns true on success. - bool EnumAllDelayImports(EnumImportsFunction callback, PVOID cookie) const; - - // Enumerates PE delay import blocks. - // cookie is a generic cookie to pass to the callback. - // Returns true on success. - bool EnumDelayImportChunks(EnumDelayImportChunksFunction callback, - PVOID cookie) const; - - // Enumerates imports from a single PE delay import block. - // cookie is a generic cookie to pass to the callback. - // Returns true on success. - bool EnumOneDelayImportChunk(EnumImportsFunction callback, - PImgDelayDescr delay_descriptor, - LPCSTR module_name, - PIMAGE_THUNK_DATA name_table, - PIMAGE_THUNK_DATA iat, - PIMAGE_THUNK_DATA bound_iat, - PIMAGE_THUNK_DATA unload_iat, - PVOID cookie) const; - - // Enumerates PE relocation entries. - // cookie is a generic cookie to pass to the callback. - // Returns true on success. - bool EnumRelocs(EnumRelocsFunction callback, PVOID cookie) const; - - // Verifies the magic values on the PE file. - // Returns true if all values are correct. - bool VerifyMagic() const; - - // Converts an rva value to the appropriate address. - virtual PVOID RVAToAddr(DWORD rva) const; - - // Converts an rva value to an offset on disk. - // Returns true on success. - bool ImageRVAToOnDiskOffset(DWORD rva, DWORD *on_disk_offset) const; - - // Converts an address to an offset on disk. - // Returns true on success. - bool ImageAddrToOnDiskOffset(LPVOID address, DWORD *on_disk_offset) const; - - private: - HMODULE module_; -}; - -// This class is an extension to the PEImage class that allows working with PE -// files mapped as data instead of as image file. -class PEImageAsData : public PEImage { - public: - explicit PEImageAsData(HMODULE hModule) : PEImage(hModule) {} - - virtual PVOID RVAToAddr(DWORD rva) const; -}; - -inline bool PEImage::IsOrdinal(LPCSTR name) { -#pragma warning(push) -#pragma warning(disable: 4311) - // This cast generates a warning because it is 32 bit specific. - return reinterpret_cast(name) <= 0xFFFF; -#pragma warning(pop) -} - -inline WORD PEImage::ToOrdinal(LPCSTR name) { - return reinterpret_cast(name); -} - -inline HMODULE PEImage::module() const { - return module_; -} - -inline PIMAGE_IMPORT_DESCRIPTOR PEImage::GetFirstImportChunk() const { - return reinterpret_cast( - GetImageDirectoryEntryAddr(IMAGE_DIRECTORY_ENTRY_IMPORT)); -} - -inline PIMAGE_EXPORT_DIRECTORY PEImage::GetExportDirectory() const { - return reinterpret_cast( - GetImageDirectoryEntryAddr(IMAGE_DIRECTORY_ENTRY_EXPORT)); -} - -#endif // BASE_PE_IMAGE_H_ diff --git a/base/pe_image_unittest.cc b/base/pe_image_unittest.cc deleted file mode 100644 index 6d8875e..0000000 --- a/base/pe_image_unittest.cc +++ /dev/null @@ -1,213 +0,0 @@ -// 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. - -// This file contains unit tests for PEImage. - -#include "testing/gtest/include/gtest/gtest.h" -#include "base/pe_image.h" -#include "base/win/windows_version.h" - -// Just counts the number of invocations. -bool ExportsCallback(const PEImage &image, - DWORD ordinal, - DWORD hint, - LPCSTR name, - PVOID function, - LPCSTR forward, - PVOID cookie) { - int* count = reinterpret_cast(cookie); - (*count)++; - return true; -} - -// Just counts the number of invocations. -bool ImportsCallback(const PEImage &image, - LPCSTR module, - DWORD ordinal, - LPCSTR name, - DWORD hint, - PIMAGE_THUNK_DATA iat, - PVOID cookie) { - int* count = reinterpret_cast(cookie); - (*count)++; - return true; -} - -// Just counts the number of invocations. -bool SectionsCallback(const PEImage &image, - PIMAGE_SECTION_HEADER header, - PVOID section_start, - DWORD section_size, - PVOID cookie) { - int* count = reinterpret_cast(cookie); - (*count)++; - return true; -} - -// Just counts the number of invocations. -bool RelocsCallback(const PEImage &image, - WORD type, - PVOID address, - PVOID cookie) { - int* count = reinterpret_cast(cookie); - (*count)++; - return true; -} - -// Just counts the number of invocations. -bool ImportChunksCallback(const PEImage &image, - LPCSTR module, - PIMAGE_THUNK_DATA name_table, - PIMAGE_THUNK_DATA iat, - PVOID cookie) { - int* count = reinterpret_cast(cookie); - (*count)++; - return true; -} - -// Just counts the number of invocations. -bool DelayImportChunksCallback(const PEImage &image, - PImgDelayDescr delay_descriptor, - LPCSTR module, - PIMAGE_THUNK_DATA name_table, - PIMAGE_THUNK_DATA iat, - PIMAGE_THUNK_DATA bound_iat, - PIMAGE_THUNK_DATA unload_iat, - PVOID cookie) { - int* count = reinterpret_cast(cookie); - (*count)++; - return true; -} - -// We'll be using some known values for the tests. -enum Value { - sections = 0, - imports_dlls, - delay_dlls, - exports, - imports, - delay_imports, - relocs -}; - -// Retrieves the expected value from advapi32.dll based on the OS. -int GetExpectedValue(Value value, DWORD os) { - const int xp_delay_dlls = 2; - const int xp_exports = 675; - const int xp_imports = 422; - const int xp_delay_imports = 8; - const int xp_relocs = 9180; - const int vista_delay_dlls = 4; - const int vista_exports = 799; - const int vista_imports = 476; - const int vista_delay_imports = 24; - const int vista_relocs = 10188; - const int w2k_delay_dlls = 0; - const int w2k_exports = 566; - const int w2k_imports = 357; - const int w2k_delay_imports = 0; - const int w2k_relocs = 7388; - const int win7_delay_dlls = 7; - const int win7_exports = 806; - const int win7_imports = 568; - const int win7_delay_imports = 71; - const int win7_relocs = 7812; - - // Contains the expected value, for each enumerated property (Value), and the - // OS version: [Value][os_version] - const int expected[][4] = { - {4, 4, 4, 4}, - {3, 3, 3, 13}, - {w2k_delay_dlls, xp_delay_dlls, vista_delay_dlls, win7_delay_dlls}, - {w2k_exports, xp_exports, vista_exports, win7_exports}, - {w2k_imports, xp_imports, vista_imports, win7_imports}, - {w2k_delay_imports, xp_delay_imports, - vista_delay_imports, win7_delay_imports}, - {w2k_relocs, xp_relocs, vista_relocs, win7_relocs} - }; - - if (value > relocs) - return 0; - if (50 == os) - os = 0; // 5.0 - else if (51 == os || 52 == os) - os = 1; - else if (os == 60) - os = 2; // 6.x - else if (os >= 61) - os = 3; - else - return 0; - - return expected[value][os]; -} - -// Tests that we are able to enumerate stuff from a PE file, and that -// the actual number of items found is within the expected range. -TEST(PEImageTest, EnumeratesPE) { - // Windows Server 2003 is not supported as a test environment for this test. - if (base::win::GetVersion() == base::win::VERSION_SERVER_2003) - return; - HMODULE module = LoadLibrary(L"advapi32.dll"); - ASSERT_TRUE(NULL != module); - - PEImage pe(module); - int count = 0; - EXPECT_TRUE(pe.VerifyMagic()); - - DWORD os = pe.GetNTHeaders()->OptionalHeader.MajorOperatingSystemVersion; - os = os * 10 + pe.GetNTHeaders()->OptionalHeader.MinorOperatingSystemVersion; - - pe.EnumSections(SectionsCallback, &count); - EXPECT_EQ(GetExpectedValue(sections, os), count); - - count = 0; - pe.EnumImportChunks(ImportChunksCallback, &count); - EXPECT_EQ(GetExpectedValue(imports_dlls, os), count); - - count = 0; - pe.EnumDelayImportChunks(DelayImportChunksCallback, &count); - EXPECT_EQ(GetExpectedValue(delay_dlls, os), count); - - count = 0; - pe.EnumExports(ExportsCallback, &count); - EXPECT_GT(count, GetExpectedValue(exports, os) - 20); - EXPECT_LT(count, GetExpectedValue(exports, os) + 100); - - count = 0; - pe.EnumAllImports(ImportsCallback, &count); - EXPECT_GT(count, GetExpectedValue(imports, os) - 20); - EXPECT_LT(count, GetExpectedValue(imports, os) + 100); - - count = 0; - pe.EnumAllDelayImports(ImportsCallback, &count); - EXPECT_GT(count, GetExpectedValue(delay_imports, os) - 2); - EXPECT_LT(count, GetExpectedValue(delay_imports, os) + 8); - - count = 0; - pe.EnumRelocs(RelocsCallback, &count); - EXPECT_GT(count, GetExpectedValue(relocs, os) - 150); - EXPECT_LT(count, GetExpectedValue(relocs, os) + 1500); - - FreeLibrary(module); -} - -// Tests that we can locate an specific exported symbol, by name and by ordinal. -TEST(PEImageTest, RetrievesExports) { - HMODULE module = LoadLibrary(L"advapi32.dll"); - ASSERT_TRUE(NULL != module); - - PEImage pe(module); - WORD ordinal; - - EXPECT_TRUE(pe.GetProcOrdinal("RegEnumKeyExW", &ordinal)); - - FARPROC address1 = pe.GetProcAddress("RegEnumKeyExW"); - FARPROC address2 = pe.GetProcAddress(reinterpret_cast(ordinal)); - EXPECT_TRUE(address1 != NULL); - EXPECT_TRUE(address2 != NULL); - EXPECT_TRUE(address1 == address2); - - FreeLibrary(module); -} diff --git a/base/registry.cc b/base/registry.cc deleted file mode 100644 index f8e58b9..0000000 --- a/base/registry.cc +++ /dev/null @@ -1,381 +0,0 @@ -// 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 "base/registry.h" - -#include - -#include "base/logging.h" - -#pragma comment(lib, "shlwapi.lib") // for SHDeleteKey - -RegistryValueIterator::RegistryValueIterator(HKEY root_key, - const wchar_t* folder_key) { - LONG result = RegOpenKeyEx(root_key, folder_key, 0, KEY_READ, &key_); - if (result != ERROR_SUCCESS) { - key_ = NULL; - } else { - DWORD count = 0; - result = ::RegQueryInfoKey(key_, NULL, 0, NULL, NULL, NULL, NULL, &count, - NULL, NULL, NULL, NULL); - - if (result != ERROR_SUCCESS) { - ::RegCloseKey(key_); - key_ = NULL; - } else { - index_ = count - 1; - } - } - - Read(); -} - -RegistryValueIterator::~RegistryValueIterator() { - if (key_) - ::RegCloseKey(key_); -} - -bool RegistryValueIterator::Valid() const { - return key_ != NULL && index_ >= 0; -} - -void RegistryValueIterator::operator++() { - --index_; - Read(); -} - -bool RegistryValueIterator::Read() { - if (Valid()) { - DWORD ncount = arraysize(name_); - value_size_ = sizeof(value_); - LRESULT r = ::RegEnumValue(key_, index_, name_, &ncount, NULL, &type_, - reinterpret_cast(value_), &value_size_); - if (ERROR_SUCCESS == r) - return true; - } - - name_[0] = '\0'; - value_[0] = '\0'; - value_size_ = 0; - return false; -} - -DWORD RegistryValueIterator::ValueCount() const { - DWORD count = 0; - HRESULT result = ::RegQueryInfoKey(key_, NULL, 0, NULL, NULL, NULL, NULL, - &count, NULL, NULL, NULL, NULL); - - if (result != ERROR_SUCCESS) - return 0; - - return count; -} - -RegistryKeyIterator::RegistryKeyIterator(HKEY root_key, - const wchar_t* folder_key) { - LONG result = RegOpenKeyEx(root_key, folder_key, 0, KEY_READ, &key_); - if (result != ERROR_SUCCESS) { - key_ = NULL; - } else { - DWORD count = 0; - HRESULT result = ::RegQueryInfoKey(key_, NULL, 0, NULL, &count, NULL, NULL, - NULL, NULL, NULL, NULL, NULL); - - if (result != ERROR_SUCCESS) { - ::RegCloseKey(key_); - key_ = NULL; - } else { - index_ = count - 1; - } - } - - Read(); -} - -RegistryKeyIterator::~RegistryKeyIterator() { - if (key_) - ::RegCloseKey(key_); -} - -bool RegistryKeyIterator::Valid() const { - return key_ != NULL && index_ >= 0; -} - -void RegistryKeyIterator::operator++() { - --index_; - Read(); -} - -bool RegistryKeyIterator::Read() { - if (Valid()) { - DWORD ncount = arraysize(name_); - FILETIME written; - LRESULT r = ::RegEnumKeyEx(key_, index_, name_, &ncount, NULL, NULL, - NULL, &written); - if (ERROR_SUCCESS == r) - return true; - } - - name_[0] = '\0'; - return false; -} - -DWORD RegistryKeyIterator::SubkeyCount() const { - DWORD count = 0; - HRESULT result = ::RegQueryInfoKey(key_, NULL, 0, NULL, &count, NULL, NULL, - NULL, NULL, NULL, NULL, NULL); - - if (result != ERROR_SUCCESS) - return 0; - - return count; -} - -RegKey::RegKey() - : key_(NULL), - watch_event_(0) { -} - -RegKey::RegKey(HKEY rootkey, const wchar_t* subkey, REGSAM access) - : key_(NULL), - watch_event_(0) { - if (rootkey) { - if (access & (KEY_SET_VALUE | KEY_CREATE_SUB_KEY | KEY_CREATE_LINK)) - Create(rootkey, subkey, access); - else - Open(rootkey, subkey, access); - } else { - DCHECK(!subkey); - } -} - -RegKey::~RegKey() { - Close(); -} - -void RegKey::Close() { - StopWatching(); - if (key_) { - ::RegCloseKey(key_); - key_ = NULL; - } -} - -bool RegKey::Create(HKEY rootkey, const wchar_t* subkey, REGSAM access) { - DWORD disposition_value; - return CreateWithDisposition(rootkey, subkey, &disposition_value, access); -} - -bool RegKey::CreateWithDisposition(HKEY rootkey, const wchar_t* subkey, - DWORD* disposition, REGSAM access) { - DCHECK(rootkey && subkey && access && disposition); - Close(); - - LONG result = RegCreateKeyEx(rootkey, - subkey, - 0, - NULL, - REG_OPTION_NON_VOLATILE, - access, - NULL, - &key_, - disposition); - if (result != ERROR_SUCCESS) { - key_ = NULL; - return false; - } - - return true; -} - -bool RegKey::Open(HKEY rootkey, const wchar_t* subkey, REGSAM access) { - DCHECK(rootkey && subkey && access); - Close(); - - LONG result = RegOpenKeyEx(rootkey, subkey, 0, access, &key_); - if (result != ERROR_SUCCESS) { - key_ = NULL; - return false; - } - return true; -} - -bool RegKey::CreateKey(const wchar_t* name, REGSAM access) { - DCHECK(name && access); - - HKEY subkey = NULL; - LONG result = RegCreateKeyEx(key_, name, 0, NULL, REG_OPTION_NON_VOLATILE, - access, NULL, &subkey, NULL); - Close(); - - key_ = subkey; - return (result == ERROR_SUCCESS); -} - -bool RegKey::OpenKey(const wchar_t* name, REGSAM access) { - DCHECK(name && access); - - HKEY subkey = NULL; - LONG result = RegOpenKeyEx(key_, name, 0, access, &subkey); - - Close(); - - key_ = subkey; - return (result == ERROR_SUCCESS); -} - -DWORD RegKey::ValueCount() { - DWORD count = 0; - HRESULT result = RegQueryInfoKey(key_, NULL, 0, NULL, NULL, NULL, - NULL, &count, NULL, NULL, NULL, NULL); - return (result != ERROR_SUCCESS) ? 0 : count; -} - -bool RegKey::ReadName(int index, std::wstring* name) { - wchar_t buf[256]; - DWORD bufsize = arraysize(buf); - LRESULT r = ::RegEnumValue(key_, index, buf, &bufsize, NULL, NULL, - NULL, NULL); - if (r != ERROR_SUCCESS) - return false; - if (name) - *name = buf; - return true; -} - -bool RegKey::ValueExists(const wchar_t* name) { - if (!key_) - return false; - HRESULT result = RegQueryValueEx(key_, name, 0, NULL, NULL, NULL); - return (result == ERROR_SUCCESS); -} - -bool RegKey::ReadValue(const wchar_t* name, void* data, - DWORD* dsize, DWORD* dtype) { - if (!key_) - return false; - HRESULT result = RegQueryValueEx(key_, name, 0, dtype, - reinterpret_cast(data), dsize); - return (result == ERROR_SUCCESS); -} - -bool RegKey::ReadValue(const wchar_t* name, std::wstring* value) { - DCHECK(value); - const size_t kMaxStringLength = 1024; // This is after expansion. - // Use the one of the other forms of ReadValue if 1024 is too small for you. - wchar_t raw_value[kMaxStringLength]; - DWORD type = REG_SZ, size = sizeof(raw_value); - if (ReadValue(name, raw_value, &size, &type)) { - if (type == REG_SZ) { - *value = raw_value; - } else if (type == REG_EXPAND_SZ) { - wchar_t expanded[kMaxStringLength]; - size = ExpandEnvironmentStrings(raw_value, expanded, kMaxStringLength); - // Success: returns the number of wchar_t's copied - // Fail: buffer too small, returns the size required - // Fail: other, returns 0 - if (size == 0 || size > kMaxStringLength) - return false; - *value = expanded; - } else { - // Not a string. Oops. - return false; - } - return true; - } - - return false; -} - -bool RegKey::ReadValueDW(const wchar_t* name, DWORD* value) { - DCHECK(value); - DWORD type = REG_DWORD; - DWORD size = sizeof(DWORD); - DWORD result = 0; - if (ReadValue(name, &result, &size, &type) && - (type == REG_DWORD || type == REG_BINARY) && - size == sizeof(DWORD)) { - *value = result; - return true; - } - - return false; -} - -bool RegKey::WriteValue(const wchar_t* name, const void * data, - DWORD dsize, DWORD dtype) { - DCHECK(data); - - if (!key_) - return false; - - HRESULT result = RegSetValueEx( - key_, - name, - 0, - dtype, - reinterpret_cast(const_cast(data)), - dsize); - return (result == ERROR_SUCCESS); -} - -bool RegKey::WriteValue(const wchar_t * name, const wchar_t* value) { - return WriteValue(name, value, - static_cast(sizeof(*value) * (wcslen(value) + 1)), REG_SZ); -} - -bool RegKey::WriteValue(const wchar_t* name, DWORD value) { - return WriteValue(name, &value, - static_cast(sizeof(value)), REG_DWORD); -} - -bool RegKey::DeleteKey(const wchar_t* name) { - return (!key_) ? false : (ERROR_SUCCESS == SHDeleteKey(key_, name)); -} - -bool RegKey::DeleteValue(const wchar_t* value_name) { - DCHECK(value_name); - HRESULT result = RegDeleteValue(key_, value_name); - return (result == ERROR_SUCCESS); -} - -bool RegKey::StartWatching() { - if (!watch_event_) - watch_event_ = CreateEvent(NULL, TRUE, FALSE, NULL); - - DWORD filter = REG_NOTIFY_CHANGE_NAME | - REG_NOTIFY_CHANGE_ATTRIBUTES | - REG_NOTIFY_CHANGE_LAST_SET | - REG_NOTIFY_CHANGE_SECURITY; - - // Watch the registry key for a change of value. - HRESULT result = RegNotifyChangeKeyValue(key_, TRUE, filter, - watch_event_, TRUE); - if (SUCCEEDED(result)) { - return true; - } else { - CloseHandle(watch_event_); - watch_event_ = 0; - return false; - } -} - -bool RegKey::StopWatching() { - if (watch_event_) { - CloseHandle(watch_event_); - watch_event_ = 0; - return true; - } - return false; -} - -bool RegKey::HasChanged() { - if (watch_event_) { - if (WaitForSingleObject(watch_event_, 0) == WAIT_OBJECT_0) { - StartWatching(); - return true; - } - } - return false; -} diff --git a/base/registry.h b/base/registry.h index 7584de019..5ef45f2 100644 --- a/base/registry.h +++ b/base/registry.h @@ -6,160 +6,34 @@ #define BASE_REGISTRY_H_ #pragma once -#include -#include +// TODO(brettw) remove this file when all callers are converted to using the +// new location & namespace. +#include "base/win/registry.h" -#include "base/basictypes.h" - -// Utility class to read, write and manipulate the Windows Registry. -// Registry vocabulary primer: a "key" is like a folder, in which there -// are "values", which are pairs, with an associated data type. -class RegKey { +class RegKey : public base::win::RegKey { public: - RegKey(); - RegKey(HKEY rootkey, const wchar_t* subkey, REGSAM access); - ~RegKey(); - - bool Create(HKEY rootkey, const wchar_t* subkey, REGSAM access); - - bool CreateWithDisposition(HKEY rootkey, const wchar_t* subkey, - DWORD* disposition, REGSAM access); - - bool Open(HKEY rootkey, const wchar_t* subkey, REGSAM access); - - // Creates a subkey or open it if it already exists. - bool CreateKey(const wchar_t* name, REGSAM access); - - // Opens a subkey - bool OpenKey(const wchar_t* name, REGSAM access); - - void Close(); - - DWORD ValueCount(); - - // Determine the nth value's name. - bool ReadName(int index, std::wstring* name); - - // True while the key is valid. - bool Valid() const { return key_ != NULL; } - - // Kill a key and everything that live below it; please be careful when using - // it. - bool DeleteKey(const wchar_t* name); - - // Deletes a single value within the key. - bool DeleteValue(const wchar_t* name); - - bool ValueExists(const wchar_t* name); - - bool ReadValue(const wchar_t* name, void* data, DWORD* dsize, DWORD* dtype); - bool ReadValue(const wchar_t* name, std::wstring* value); - bool ReadValueDW(const wchar_t* name, DWORD* value); - - bool WriteValue(const wchar_t* name, const void* data, DWORD dsize, - DWORD dtype); - bool WriteValue(const wchar_t* name, const wchar_t* value); - bool WriteValue(const wchar_t* name, DWORD value); - - // Starts watching the key to see if any of its values have changed. - // The key must have been opened with the KEY_NOTIFY access privelege. - bool StartWatching(); - - // If StartWatching hasn't been called, always returns false. - // Otherwise, returns true if anything under the key has changed. - // This can't be const because the |watch_event_| may be refreshed. - bool HasChanged(); - - // Will automatically be called by destructor if not manually called - // beforehand. Returns true if it was watching, false otherwise. - bool StopWatching(); - - inline bool IsWatching() const { return watch_event_ != 0; } - HANDLE watch_event() const { return watch_event_; } - HKEY Handle() const { return key_; } - - private: - HKEY key_; // The registry key being iterated. - HANDLE watch_event_; - - DISALLOW_COPY_AND_ASSIGN(RegKey); + RegKey() {} + RegKey(HKEY rootkey, const wchar_t* subkey, REGSAM access) + : base::win::RegKey(rootkey, subkey, access) {} + ~RegKey() { base::win::RegKey::~RegKey(); } }; -// Iterates the entries found in a particular folder on the registry. -// For this application I happen to know I wont need data size larger -// than MAX_PATH, but in real life this wouldn't neccessarily be -// adequate. -class RegistryValueIterator { +class RegistryValueIterator : public base::win::RegistryValueIterator { public: - RegistryValueIterator(HKEY root_key, const wchar_t* folder_key); - - ~RegistryValueIterator(); - - DWORD ValueCount() const; - - // True while the iterator is valid. - bool Valid() const; - - // Advances to the next registry entry. - void operator++(); - - const wchar_t* Name() const { return name_; } - const wchar_t* Value() const { return value_; } - DWORD ValueSize() const { return value_size_; } - DWORD Type() const { return type_; } - - int Index() const { return index_; } - - private: - // Read in the current values. - bool Read(); - - // The registry key being iterated. - HKEY key_; - - // Current index of the iteration. - int index_; - - // Current values. - wchar_t name_[MAX_PATH]; - wchar_t value_[MAX_PATH]; - DWORD value_size_; - DWORD type_; - - DISALLOW_COPY_AND_ASSIGN(RegistryValueIterator); + RegistryValueIterator(HKEY root_key, const wchar_t* folder_key) + : base::win::RegistryValueIterator(root_key, folder_key) {} + ~RegistryValueIterator() { + base::win::RegistryValueIterator::~RegistryValueIterator(); + } }; -class RegistryKeyIterator { +class RegistryKeyIterator : public base::win::RegistryKeyIterator { public: - RegistryKeyIterator(HKEY root_key, const wchar_t* folder_key); - - ~RegistryKeyIterator(); - - DWORD SubkeyCount() const; - - // True while the iterator is valid. - bool Valid() const; - - // Advances to the next entry in the folder. - void operator++(); - - const wchar_t* Name() const { return name_; } - - int Index() const { return index_; } - - private: - // Read in the current values. - bool Read(); - - // The registry key being iterated. - HKEY key_; - - // Current index of the iteration. - int index_; - - wchar_t name_[MAX_PATH]; - - DISALLOW_COPY_AND_ASSIGN(RegistryKeyIterator); + RegistryKeyIterator(HKEY root_key, const wchar_t* folder_key) + : base::win::RegistryKeyIterator(root_key, folder_key) {} + ~RegistryKeyIterator() { + base::win::RegistryKeyIterator::~RegistryKeyIterator(); + } }; #endif // BASE_REGISTRY_H_ diff --git a/base/registry_unittest.cc b/base/registry_unittest.cc deleted file mode 100644 index 2618a75..0000000 --- a/base/registry_unittest.cc +++ /dev/null @@ -1,59 +0,0 @@ -// 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 "base/registry.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -const wchar_t kRootKey[] = L"Base_Registry_Unittest"; - -class RegistryTest : public testing::Test { - public: - RegistryTest() {} - - protected: - virtual void SetUp() { - // Create a temporary key. - RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); - key.DeleteKey(kRootKey); - ASSERT_FALSE(key.Open(HKEY_CURRENT_USER, kRootKey, KEY_READ)); - ASSERT_TRUE(key.Create(HKEY_CURRENT_USER, kRootKey, KEY_READ)); - } - - virtual void TearDown() { - // Clean up the temporary key. - RegKey key(HKEY_CURRENT_USER, L"", KEY_SET_VALUE); - ASSERT_TRUE(key.DeleteKey(kRootKey)); - } - - private: - DISALLOW_COPY_AND_ASSIGN(RegistryTest); -}; - -TEST_F(RegistryTest, ValueTest) { - RegKey key; - - std::wstring foo_key(kRootKey); - foo_key += L"\\Foo"; - ASSERT_TRUE(key.Create(HKEY_CURRENT_USER, foo_key.c_str(), KEY_READ)); - - { - ASSERT_TRUE(key.Open(HKEY_CURRENT_USER, foo_key.c_str(), - KEY_READ | KEY_SET_VALUE)); - - const wchar_t* kName = L"Bar"; - const wchar_t* kValue = L"bar"; - EXPECT_TRUE(key.WriteValue(kName, kValue)); - EXPECT_TRUE(key.ValueExists(kName)); - std::wstring out_value; - EXPECT_TRUE(key.ReadValue(kName, &out_value)); - EXPECT_NE(out_value, L""); - EXPECT_STREQ(out_value.c_str(), kValue); - EXPECT_EQ(1U, key.ValueCount()); - EXPECT_TRUE(key.DeleteValue(kName)); - } -} - -} // namespace diff --git a/base/win/pe_image.cc b/base/win/pe_image.cc new file mode 100644 index 0000000..76fdbcd --- /dev/null +++ b/base/win/pe_image.cc @@ -0,0 +1,570 @@ +// 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. + +// This file implements PEImage, a generic class to manipulate PE files. +// This file was adapted from GreenBorder's Code. + +#include "base/win/pe_image.h" + +namespace base { +namespace win { + +#if defined(_WIN64) && !defined(NACL_WIN64) +// TODO(rvargas): Bug 27218. Make sure this is ok. +#error This code is not tested on x64. Please make sure all the base unit tests\ + pass before doing any real work. The current unit tests don't test the\ + differences between 32- and 64-bits implementations. Bugs may slip through.\ + You need to improve the coverage before continuing. +#endif + +// Structure to perform imports enumerations. +struct EnumAllImportsStorage { + PEImage::EnumImportsFunction callback; + PVOID cookie; +}; + +namespace { + + // Compare two strings byte by byte on an unsigned basis. + // if s1 == s2, return 0 + // if s1 < s2, return negative + // if s1 > s2, return positive + // Exception if inputs are invalid. + int StrCmpByByte(LPCSTR s1, LPCSTR s2) { + while (*s1 != '\0' && *s1 == *s2) { + ++s1; + ++s2; + } + + return (*reinterpret_cast(s1) - + *reinterpret_cast(s2)); + } + +} // namespace + +// Callback used to enumerate imports. See EnumImportChunksFunction. +bool ProcessImportChunk(const PEImage &image, LPCSTR module, + PIMAGE_THUNK_DATA name_table, + PIMAGE_THUNK_DATA iat, PVOID cookie) { + EnumAllImportsStorage &storage = *reinterpret_cast( + cookie); + + return image.EnumOneImportChunk(storage.callback, module, name_table, iat, + storage.cookie); +} + +// Callback used to enumerate delay imports. See EnumDelayImportChunksFunction. +bool ProcessDelayImportChunk(const PEImage &image, + PImgDelayDescr delay_descriptor, + LPCSTR module, PIMAGE_THUNK_DATA name_table, + PIMAGE_THUNK_DATA iat, PIMAGE_THUNK_DATA bound_iat, + PIMAGE_THUNK_DATA unload_iat, PVOID cookie) { + EnumAllImportsStorage &storage = *reinterpret_cast( + cookie); + + return image.EnumOneDelayImportChunk(storage.callback, delay_descriptor, + module, name_table, iat, bound_iat, + unload_iat, storage.cookie); +} + +void PEImage::set_module(HMODULE module) { + module_ = module; +} + +PIMAGE_DOS_HEADER PEImage::GetDosHeader() const { + return reinterpret_cast(module_); +} + +PIMAGE_NT_HEADERS PEImage::GetNTHeaders() const { + PIMAGE_DOS_HEADER dos_header = GetDosHeader(); + + return reinterpret_cast( + reinterpret_cast(dos_header) + dos_header->e_lfanew); +} + +PIMAGE_SECTION_HEADER PEImage::GetSectionHeader(UINT section) const { + PIMAGE_NT_HEADERS nt_headers = GetNTHeaders(); + PIMAGE_SECTION_HEADER first_section = IMAGE_FIRST_SECTION(nt_headers); + + if (section < nt_headers->FileHeader.NumberOfSections) + return first_section + section; + else + return NULL; +} + +WORD PEImage::GetNumSections() const { + return GetNTHeaders()->FileHeader.NumberOfSections; +} + +DWORD PEImage::GetImageDirectoryEntrySize(UINT directory) const { + PIMAGE_NT_HEADERS nt_headers = GetNTHeaders(); + + return nt_headers->OptionalHeader.DataDirectory[directory].Size; +} + +PVOID PEImage::GetImageDirectoryEntryAddr(UINT directory) const { + PIMAGE_NT_HEADERS nt_headers = GetNTHeaders(); + + return RVAToAddr( + nt_headers->OptionalHeader.DataDirectory[directory].VirtualAddress); +} + +PIMAGE_SECTION_HEADER PEImage::GetImageSectionFromAddr(PVOID address) const { + PBYTE target = reinterpret_cast(address); + PIMAGE_SECTION_HEADER section; + + for (UINT i = 0; NULL != (section = GetSectionHeader(i)); i++) { + // Don't use the virtual RVAToAddr. + PBYTE start = reinterpret_cast( + PEImage::RVAToAddr(section->VirtualAddress)); + + DWORD size = section->Misc.VirtualSize; + + if ((start <= target) && (start + size > target)) + return section; + } + + return NULL; +} + +PIMAGE_SECTION_HEADER PEImage::GetImageSectionHeaderByName( + LPCSTR section_name) const { + if (NULL == section_name) + return NULL; + + PIMAGE_SECTION_HEADER ret = NULL; + int num_sections = GetNumSections(); + + for (int i = 0; i < num_sections; i++) { + PIMAGE_SECTION_HEADER section = GetSectionHeader(i); + if (0 == _strnicmp(reinterpret_cast(section->Name), section_name, + sizeof(section->Name))) { + ret = section; + break; + } + } + + return ret; +} + +PDWORD PEImage::GetExportEntry(LPCSTR name) const { + PIMAGE_EXPORT_DIRECTORY exports = GetExportDirectory(); + + if (NULL == exports) + return NULL; + + WORD ordinal = 0; + if (!GetProcOrdinal(name, &ordinal)) + return NULL; + + PDWORD functions = reinterpret_cast( + RVAToAddr(exports->AddressOfFunctions)); + + return functions + ordinal - exports->Base; +} + +FARPROC PEImage::GetProcAddress(LPCSTR function_name) const { + PDWORD export_entry = GetExportEntry(function_name); + if (NULL == export_entry) + return NULL; + + PBYTE function = reinterpret_cast(RVAToAddr(*export_entry)); + + PBYTE exports = reinterpret_cast( + GetImageDirectoryEntryAddr(IMAGE_DIRECTORY_ENTRY_EXPORT)); + DWORD size = GetImageDirectoryEntrySize(IMAGE_DIRECTORY_ENTRY_EXPORT); + + // Check for forwarded exports as a special case. + if (exports <= function && exports + size > function) +#pragma warning(push) +#pragma warning(disable: 4312) + // This cast generates a warning because it is 32 bit specific. + return reinterpret_cast(0xFFFFFFFF); +#pragma warning(pop) + + return reinterpret_cast(function); +} + +bool PEImage::GetProcOrdinal(LPCSTR function_name, WORD *ordinal) const { + if (NULL == ordinal) + return false; + + PIMAGE_EXPORT_DIRECTORY exports = GetExportDirectory(); + + if (NULL == exports) + return false; + + if (IsOrdinal(function_name)) { + *ordinal = ToOrdinal(function_name); + } else { + PDWORD names = reinterpret_cast(RVAToAddr(exports->AddressOfNames)); + PDWORD lower = names; + PDWORD upper = names + exports->NumberOfNames; + int cmp = -1; + + // Binary Search for the name. + while (lower != upper) { + PDWORD middle = lower + (upper - lower) / 2; + LPCSTR name = reinterpret_cast(RVAToAddr(*middle)); + + // This may be called by sandbox before MSVCRT dll loads, so can't use + // CRT function here. + cmp = StrCmpByByte(function_name, name); + + if (cmp == 0) { + lower = middle; + break; + } + + if (cmp > 0) + lower = middle + 1; + else + upper = middle; + } + + if (cmp != 0) + return false; + + + PWORD ordinals = reinterpret_cast( + RVAToAddr(exports->AddressOfNameOrdinals)); + + *ordinal = ordinals[lower - names] + static_cast(exports->Base); + } + + return true; +} + +bool PEImage::EnumSections(EnumSectionsFunction callback, PVOID cookie) const { + PIMAGE_NT_HEADERS nt_headers = GetNTHeaders(); + UINT num_sections = nt_headers->FileHeader.NumberOfSections; + PIMAGE_SECTION_HEADER section = GetSectionHeader(0); + + for (UINT i = 0; i < num_sections; i++, section++) { + PVOID section_start = RVAToAddr(section->VirtualAddress); + DWORD size = section->Misc.VirtualSize; + + if (!callback(*this, section, section_start, size, cookie)) + return false; + } + + return true; +} + +bool PEImage::EnumExports(EnumExportsFunction callback, PVOID cookie) const { + PVOID directory = GetImageDirectoryEntryAddr(IMAGE_DIRECTORY_ENTRY_EXPORT); + DWORD size = GetImageDirectoryEntrySize(IMAGE_DIRECTORY_ENTRY_EXPORT); + + // Check if there are any exports at all. + if (NULL == directory || 0 == size) + return true; + + PIMAGE_EXPORT_DIRECTORY exports = reinterpret_cast( + directory); + UINT ordinal_base = exports->Base; + UINT num_funcs = exports->NumberOfFunctions; + UINT num_names = exports->NumberOfNames; + PDWORD functions = reinterpret_cast(RVAToAddr( + exports->AddressOfFunctions)); + PDWORD names = reinterpret_cast(RVAToAddr(exports->AddressOfNames)); + PWORD ordinals = reinterpret_cast(RVAToAddr( + exports->AddressOfNameOrdinals)); + + for (UINT count = 0; count < num_funcs; count++) { + PVOID func = RVAToAddr(functions[count]); + if (NULL == func) + continue; + + // Check for a name. + LPCSTR name = NULL; + UINT hint; + for (hint = 0; hint < num_names; hint++) { + if (ordinals[hint] == count) { + name = reinterpret_cast(RVAToAddr(names[hint])); + break; + } + } + + if (name == NULL) + hint = 0; + + // Check for forwarded exports. + LPCSTR forward = NULL; + if (reinterpret_cast(func) >= reinterpret_cast(directory) && + reinterpret_cast(func) <= reinterpret_cast(directory) + + size) { + forward = reinterpret_cast(func); + func = 0; + } + + if (!callback(*this, ordinal_base + count, hint, name, func, forward, + cookie)) + return false; + } + + return true; +} + +bool PEImage::EnumRelocs(EnumRelocsFunction callback, PVOID cookie) const { + PVOID directory = GetImageDirectoryEntryAddr(IMAGE_DIRECTORY_ENTRY_BASERELOC); + DWORD size = GetImageDirectoryEntrySize(IMAGE_DIRECTORY_ENTRY_BASERELOC); + PIMAGE_BASE_RELOCATION base = reinterpret_cast( + directory); + + if (directory == NULL || size < sizeof(IMAGE_BASE_RELOCATION)) + return true; + + while (base->SizeOfBlock) { + PWORD reloc = reinterpret_cast(base + 1); + UINT num_relocs = (base->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION)) / + sizeof(WORD); + + for (UINT i = 0; i < num_relocs; i++, reloc++) { + WORD type = *reloc >> 12; + PVOID address = RVAToAddr(base->VirtualAddress + (*reloc & 0x0FFF)); + + if (!callback(*this, type, address, cookie)) + return false; + } + + base = reinterpret_cast( + reinterpret_cast(base) + base->SizeOfBlock); + } + + return true; +} + +bool PEImage::EnumImportChunks(EnumImportChunksFunction callback, + PVOID cookie) const { + DWORD size = GetImageDirectoryEntrySize(IMAGE_DIRECTORY_ENTRY_IMPORT); + PIMAGE_IMPORT_DESCRIPTOR import = GetFirstImportChunk(); + + if (import == NULL || size < sizeof(IMAGE_IMPORT_DESCRIPTOR)) + return true; + + for (; import->FirstThunk; import++) { + LPCSTR module_name = reinterpret_cast(RVAToAddr(import->Name)); + PIMAGE_THUNK_DATA name_table = reinterpret_cast( + RVAToAddr(import->OriginalFirstThunk)); + PIMAGE_THUNK_DATA iat = reinterpret_cast( + RVAToAddr(import->FirstThunk)); + + if (!callback(*this, module_name, name_table, iat, cookie)) + return false; + } + + return true; +} + +bool PEImage::EnumOneImportChunk(EnumImportsFunction callback, + LPCSTR module_name, + PIMAGE_THUNK_DATA name_table, + PIMAGE_THUNK_DATA iat, PVOID cookie) const { + if (NULL == name_table) + return false; + + for (; name_table && name_table->u1.Ordinal; name_table++, iat++) { + LPCSTR name = NULL; + WORD ordinal = 0; + WORD hint = 0; + + if (IMAGE_SNAP_BY_ORDINAL(name_table->u1.Ordinal)) { + ordinal = static_cast(IMAGE_ORDINAL32(name_table->u1.Ordinal)); + } else { + PIMAGE_IMPORT_BY_NAME import = reinterpret_cast( + RVAToAddr(name_table->u1.ForwarderString)); + + hint = import->Hint; + name = reinterpret_cast(&import->Name); + } + + if (!callback(*this, module_name, ordinal, name, hint, iat, cookie)) + return false; + } + + return true; +} + +bool PEImage::EnumAllImports(EnumImportsFunction callback, PVOID cookie) const { + EnumAllImportsStorage temp = { callback, cookie }; + return EnumImportChunks(ProcessImportChunk, &temp); +} + +bool PEImage::EnumDelayImportChunks(EnumDelayImportChunksFunction callback, + PVOID cookie) const { + PVOID directory = GetImageDirectoryEntryAddr( + IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT); + DWORD size = GetImageDirectoryEntrySize(IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT); + PImgDelayDescr delay_descriptor = reinterpret_cast(directory); + + if (directory == NULL || size == 0) + return true; + + for (; delay_descriptor->rvaHmod; delay_descriptor++) { + PIMAGE_THUNK_DATA name_table; + PIMAGE_THUNK_DATA iat; + PIMAGE_THUNK_DATA bound_iat; // address of the optional bound IAT + PIMAGE_THUNK_DATA unload_iat; // address of optional copy of original IAT + LPCSTR module_name; + + // check if VC7-style imports, using RVAs instead of + // VC6-style addresses. + bool rvas = (delay_descriptor->grAttrs & dlattrRva) != 0; + + if (rvas) { + module_name = reinterpret_cast( + RVAToAddr(delay_descriptor->rvaDLLName)); + name_table = reinterpret_cast( + RVAToAddr(delay_descriptor->rvaINT)); + iat = reinterpret_cast( + RVAToAddr(delay_descriptor->rvaIAT)); + bound_iat = reinterpret_cast( + RVAToAddr(delay_descriptor->rvaBoundIAT)); + unload_iat = reinterpret_cast( + RVAToAddr(delay_descriptor->rvaUnloadIAT)); + } else { +#pragma warning(push) +#pragma warning(disable: 4312) + // These casts generate warnings because they are 32 bit specific. + module_name = reinterpret_cast(delay_descriptor->rvaDLLName); + name_table = reinterpret_cast( + delay_descriptor->rvaINT); + iat = reinterpret_cast(delay_descriptor->rvaIAT); + bound_iat = reinterpret_cast( + delay_descriptor->rvaBoundIAT); + unload_iat = reinterpret_cast( + delay_descriptor->rvaUnloadIAT); +#pragma warning(pop) + } + + if (!callback(*this, delay_descriptor, module_name, name_table, iat, + bound_iat, unload_iat, cookie)) + return false; + } + + return true; +} + +bool PEImage::EnumOneDelayImportChunk(EnumImportsFunction callback, + PImgDelayDescr delay_descriptor, + LPCSTR module_name, + PIMAGE_THUNK_DATA name_table, + PIMAGE_THUNK_DATA iat, + PIMAGE_THUNK_DATA bound_iat, + PIMAGE_THUNK_DATA unload_iat, + PVOID cookie) const { + UNREFERENCED_PARAMETER(bound_iat); + UNREFERENCED_PARAMETER(unload_iat); + + for (; name_table->u1.Ordinal; name_table++, iat++) { + LPCSTR name = NULL; + WORD ordinal = 0; + WORD hint = 0; + + if (IMAGE_SNAP_BY_ORDINAL(name_table->u1.Ordinal)) { + ordinal = static_cast(IMAGE_ORDINAL32(name_table->u1.Ordinal)); + } else { + PIMAGE_IMPORT_BY_NAME import; + bool rvas = (delay_descriptor->grAttrs & dlattrRva) != 0; + + if (rvas) { + import = reinterpret_cast( + RVAToAddr(name_table->u1.ForwarderString)); + } else { +#pragma warning(push) +#pragma warning(disable: 4312) + // This cast generates a warning because it is 32 bit specific. + import = reinterpret_cast( + name_table->u1.ForwarderString); +#pragma warning(pop) + } + + hint = import->Hint; + name = reinterpret_cast(&import->Name); + } + + if (!callback(*this, module_name, ordinal, name, hint, iat, cookie)) + return false; + } + + return true; +} + +bool PEImage::EnumAllDelayImports(EnumImportsFunction callback, + PVOID cookie) const { + EnumAllImportsStorage temp = { callback, cookie }; + return EnumDelayImportChunks(ProcessDelayImportChunk, &temp); +} + +bool PEImage::VerifyMagic() const { + PIMAGE_DOS_HEADER dos_header = GetDosHeader(); + + if (dos_header->e_magic != IMAGE_DOS_SIGNATURE) + return false; + + PIMAGE_NT_HEADERS nt_headers = GetNTHeaders(); + + if (nt_headers->Signature != IMAGE_NT_SIGNATURE) + return false; + + if (nt_headers->FileHeader.SizeOfOptionalHeader != + sizeof(IMAGE_OPTIONAL_HEADER)) + return false; + + if (nt_headers->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR_MAGIC) + return false; + + return true; +} + +bool PEImage::ImageRVAToOnDiskOffset(DWORD rva, DWORD *on_disk_offset) const { + LPVOID address = RVAToAddr(rva); + return ImageAddrToOnDiskOffset(address, on_disk_offset); +} + +bool PEImage::ImageAddrToOnDiskOffset(LPVOID address, + DWORD *on_disk_offset) const { + if (NULL == address) + return false; + + // Get the section that this address belongs to. + PIMAGE_SECTION_HEADER section_header = GetImageSectionFromAddr(address); + if (NULL == section_header) + return false; + +#pragma warning(push) +#pragma warning(disable: 4311) + // These casts generate warnings because they are 32 bit specific. + // Don't follow the virtual RVAToAddr, use the one on the base. + DWORD offset_within_section = reinterpret_cast(address) - + reinterpret_cast(PEImage::RVAToAddr( + section_header->VirtualAddress)); +#pragma warning(pop) + + *on_disk_offset = section_header->PointerToRawData + offset_within_section; + return true; +} + +PVOID PEImage::RVAToAddr(DWORD rva) const { + if (rva == 0) + return NULL; + + return reinterpret_cast(module_) + rva; +} + +PVOID PEImageAsData::RVAToAddr(DWORD rva) const { + if (rva == 0) + return NULL; + + PVOID in_memory = PEImage::RVAToAddr(rva); + DWORD dummy; + + if (!ImageAddrToOnDiskOffset(in_memory, &dummy)) + return NULL; + + return in_memory; +} + +} // namespace win +} // namespace base diff --git a/base/win/pe_image.h b/base/win/pe_image.h new file mode 100644 index 0000000..e1205e0 --- /dev/null +++ b/base/win/pe_image.h @@ -0,0 +1,264 @@ +// 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. + +// This file was adapted from GreenBorder's Code. +// To understand what this class is about (for other than well known functions +// as GetProcAddress), a good starting point is "An In-Depth Look into the +// Win32 Portable Executable File Format" by Matt Pietrek: +// http://msdn.microsoft.com/msdnmag/issues/02/02/PE/default.aspx + +#ifndef BASE_WIN_PE_IMAGE_H_ +#define BASE_WIN_PE_IMAGE_H_ +#pragma once + +#include +#include + +namespace base { +namespace win { + +// This class is a wrapper for the Portable Executable File Format (PE). +// It's main purpose is to provide an easy way to work with imports and exports +// from a file, mapped in memory as image. +class PEImage { + public: + // Callback to enumerate sections. + // cookie is the value passed to the enumerate method. + // Returns true to continue the enumeration. + typedef bool (*EnumSectionsFunction)(const PEImage &image, + PIMAGE_SECTION_HEADER header, + PVOID section_start, DWORD section_size, + PVOID cookie); + + // Callback to enumerate exports. + // function is the actual address of the symbol. If forward is not null, it + // contains the dll and symbol to forward this export to. cookie is the value + // passed to the enumerate method. + // Returns true to continue the enumeration. + typedef bool (*EnumExportsFunction)(const PEImage &image, DWORD ordinal, + DWORD hint, LPCSTR name, PVOID function, + LPCSTR forward, PVOID cookie); + + // Callback to enumerate import blocks. + // name_table and iat point to the imports name table and address table for + // this block. cookie is the value passed to the enumerate method. + // Returns true to continue the enumeration. + typedef bool (*EnumImportChunksFunction)(const PEImage &image, LPCSTR module, + PIMAGE_THUNK_DATA name_table, + PIMAGE_THUNK_DATA iat, PVOID cookie); + + // Callback to enumerate imports. + // module is the dll that exports this symbol. cookie is the value passed to + // the enumerate method. + // Returns true to continue the enumeration. + typedef bool (*EnumImportsFunction)(const PEImage &image, LPCSTR module, + DWORD ordinal, LPCSTR name, DWORD hint, + PIMAGE_THUNK_DATA iat, PVOID cookie); + + // Callback to enumerate dalayed import blocks. + // module is the dll that exports this block of symbols. cookie is the value + // passed to the enumerate method. + // Returns true to continue the enumeration. + typedef bool (*EnumDelayImportChunksFunction)(const PEImage &image, + PImgDelayDescr delay_descriptor, + LPCSTR module, + PIMAGE_THUNK_DATA name_table, + PIMAGE_THUNK_DATA iat, + PIMAGE_THUNK_DATA bound_iat, + PIMAGE_THUNK_DATA unload_iat, + PVOID cookie); + + // Callback to enumerate relocations. + // cookie is the value passed to the enumerate method. + // Returns true to continue the enumeration. + typedef bool (*EnumRelocsFunction)(const PEImage &image, WORD type, + PVOID address, PVOID cookie); + + explicit PEImage(HMODULE module) : module_(module) {} + explicit PEImage(const void* module) { + module_ = reinterpret_cast(const_cast(module)); + } + + // Gets the HMODULE for this object. + HMODULE module() const; + + // Sets this object's HMODULE. + void set_module(HMODULE module); + + // Checks if this symbol is actually an ordinal. + static bool IsOrdinal(LPCSTR name); + + // Converts a named symbol to the corresponding ordinal. + static WORD ToOrdinal(LPCSTR name); + + // Returns the DOS_HEADER for this PE. + PIMAGE_DOS_HEADER GetDosHeader() const; + + // Returns the NT_HEADER for this PE. + PIMAGE_NT_HEADERS GetNTHeaders() const; + + // Returns number of sections of this PE. + WORD GetNumSections() const; + + // Returns the header for a given section. + // returns NULL if there is no such section. + PIMAGE_SECTION_HEADER GetSectionHeader(UINT section) const; + + // Returns the size of a given directory entry. + DWORD GetImageDirectoryEntrySize(UINT directory) const; + + // Returns the address of a given directory entry. + PVOID GetImageDirectoryEntryAddr(UINT directory) const; + + // Returns the section header for a given address. + // Use: s = image.GetImageSectionFromAddr(a); + // Post: 's' is the section header of the section that contains 'a' + // or NULL if there is no such section. + PIMAGE_SECTION_HEADER GetImageSectionFromAddr(PVOID address) const; + + // Returns the section header for a given section. + PIMAGE_SECTION_HEADER GetImageSectionHeaderByName(LPCSTR section_name) const; + + // Returns the first block of imports. + PIMAGE_IMPORT_DESCRIPTOR GetFirstImportChunk() const; + + // Returns the exports directory. + PIMAGE_EXPORT_DIRECTORY GetExportDirectory() const; + + // Returns a given export entry. + // Use: e = image.GetExportEntry(f); + // Pre: 'f' is either a zero terminated string or ordinal + // Post: 'e' is a pointer to the export directory entry + // that contains 'f's export RVA, or NULL if 'f' + // is not exported from this image + PDWORD GetExportEntry(LPCSTR name) const; + + // Returns the address for a given exported symbol. + // Use: p = image.GetProcAddress(f); + // Pre: 'f' is either a zero terminated string or ordinal. + // Post: if 'f' is a non-forwarded export from image, 'p' is + // the exported function. If 'f' is a forwarded export + // then p is the special value 0xFFFFFFFF. In this case + // RVAToAddr(*GetExportEntry) can be used to resolve + // the string that describes the forward. + FARPROC GetProcAddress(LPCSTR function_name) const; + + // Retrieves the ordinal for a given exported symbol. + // Returns true if the symbol was found. + bool GetProcOrdinal(LPCSTR function_name, WORD *ordinal) const; + + // Enumerates PE sections. + // cookie is a generic cookie to pass to the callback. + // Returns true on success. + bool EnumSections(EnumSectionsFunction callback, PVOID cookie) const; + + // Enumerates PE exports. + // cookie is a generic cookie to pass to the callback. + // Returns true on success. + bool EnumExports(EnumExportsFunction callback, PVOID cookie) const; + + // Enumerates PE imports. + // cookie is a generic cookie to pass to the callback. + // Returns true on success. + bool EnumAllImports(EnumImportsFunction callback, PVOID cookie) const; + + // Enumerates PE import blocks. + // cookie is a generic cookie to pass to the callback. + // Returns true on success. + bool EnumImportChunks(EnumImportChunksFunction callback, PVOID cookie) const; + + // Enumerates the imports from a single PE import block. + // cookie is a generic cookie to pass to the callback. + // Returns true on success. + bool EnumOneImportChunk(EnumImportsFunction callback, LPCSTR module_name, + PIMAGE_THUNK_DATA name_table, PIMAGE_THUNK_DATA iat, + PVOID cookie) const; + + + // Enumerates PE delay imports. + // cookie is a generic cookie to pass to the callback. + // Returns true on success. + bool EnumAllDelayImports(EnumImportsFunction callback, PVOID cookie) const; + + // Enumerates PE delay import blocks. + // cookie is a generic cookie to pass to the callback. + // Returns true on success. + bool EnumDelayImportChunks(EnumDelayImportChunksFunction callback, + PVOID cookie) const; + + // Enumerates imports from a single PE delay import block. + // cookie is a generic cookie to pass to the callback. + // Returns true on success. + bool EnumOneDelayImportChunk(EnumImportsFunction callback, + PImgDelayDescr delay_descriptor, + LPCSTR module_name, + PIMAGE_THUNK_DATA name_table, + PIMAGE_THUNK_DATA iat, + PIMAGE_THUNK_DATA bound_iat, + PIMAGE_THUNK_DATA unload_iat, + PVOID cookie) const; + + // Enumerates PE relocation entries. + // cookie is a generic cookie to pass to the callback. + // Returns true on success. + bool EnumRelocs(EnumRelocsFunction callback, PVOID cookie) const; + + // Verifies the magic values on the PE file. + // Returns true if all values are correct. + bool VerifyMagic() const; + + // Converts an rva value to the appropriate address. + virtual PVOID RVAToAddr(DWORD rva) const; + + // Converts an rva value to an offset on disk. + // Returns true on success. + bool ImageRVAToOnDiskOffset(DWORD rva, DWORD *on_disk_offset) const; + + // Converts an address to an offset on disk. + // Returns true on success. + bool ImageAddrToOnDiskOffset(LPVOID address, DWORD *on_disk_offset) const; + + private: + HMODULE module_; +}; + +// This class is an extension to the PEImage class that allows working with PE +// files mapped as data instead of as image file. +class PEImageAsData : public PEImage { + public: + explicit PEImageAsData(HMODULE hModule) : PEImage(hModule) {} + + virtual PVOID RVAToAddr(DWORD rva) const; +}; + +inline bool PEImage::IsOrdinal(LPCSTR name) { +#pragma warning(push) +#pragma warning(disable: 4311) + // This cast generates a warning because it is 32 bit specific. + return reinterpret_cast(name) <= 0xFFFF; +#pragma warning(pop) +} + +inline WORD PEImage::ToOrdinal(LPCSTR name) { + return reinterpret_cast(name); +} + +inline HMODULE PEImage::module() const { + return module_; +} + +inline PIMAGE_IMPORT_DESCRIPTOR PEImage::GetFirstImportChunk() const { + return reinterpret_cast( + GetImageDirectoryEntryAddr(IMAGE_DIRECTORY_ENTRY_IMPORT)); +} + +inline PIMAGE_EXPORT_DIRECTORY PEImage::GetExportDirectory() const { + return reinterpret_cast( + GetImageDirectoryEntryAddr(IMAGE_DIRECTORY_ENTRY_EXPORT)); +} + +} // namespace win +} // namespace base + +#endif // BASE_WIN_PE_IMAGE_H_ diff --git a/base/win/pe_image_unittest.cc b/base/win/pe_image_unittest.cc new file mode 100644 index 0000000..899ce94 --- /dev/null +++ b/base/win/pe_image_unittest.cc @@ -0,0 +1,219 @@ +// 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. + +// This file contains unit tests for PEImage. + +#include "testing/gtest/include/gtest/gtest.h" +#include "base/win/pe_image.h" +#include "base/win/windows_version.h" + +namespace base { +namespace win { + +// Just counts the number of invocations. +bool ExportsCallback(const PEImage &image, + DWORD ordinal, + DWORD hint, + LPCSTR name, + PVOID function, + LPCSTR forward, + PVOID cookie) { + int* count = reinterpret_cast(cookie); + (*count)++; + return true; +} + +// Just counts the number of invocations. +bool ImportsCallback(const PEImage &image, + LPCSTR module, + DWORD ordinal, + LPCSTR name, + DWORD hint, + PIMAGE_THUNK_DATA iat, + PVOID cookie) { + int* count = reinterpret_cast(cookie); + (*count)++; + return true; +} + +// Just counts the number of invocations. +bool SectionsCallback(const PEImage &image, + PIMAGE_SECTION_HEADER header, + PVOID section_start, + DWORD section_size, + PVOID cookie) { + int* count = reinterpret_cast(cookie); + (*count)++; + return true; +} + +// Just counts the number of invocations. +bool RelocsCallback(const PEImage &image, + WORD type, + PVOID address, + PVOID cookie) { + int* count = reinterpret_cast(cookie); + (*count)++; + return true; +} + +// Just counts the number of invocations. +bool ImportChunksCallback(const PEImage &image, + LPCSTR module, + PIMAGE_THUNK_DATA name_table, + PIMAGE_THUNK_DATA iat, + PVOID cookie) { + int* count = reinterpret_cast(cookie); + (*count)++; + return true; +} + +// Just counts the number of invocations. +bool DelayImportChunksCallback(const PEImage &image, + PImgDelayDescr delay_descriptor, + LPCSTR module, + PIMAGE_THUNK_DATA name_table, + PIMAGE_THUNK_DATA iat, + PIMAGE_THUNK_DATA bound_iat, + PIMAGE_THUNK_DATA unload_iat, + PVOID cookie) { + int* count = reinterpret_cast(cookie); + (*count)++; + return true; +} + +// We'll be using some known values for the tests. +enum Value { + sections = 0, + imports_dlls, + delay_dlls, + exports, + imports, + delay_imports, + relocs +}; + +// Retrieves the expected value from advapi32.dll based on the OS. +int GetExpectedValue(Value value, DWORD os) { + const int xp_delay_dlls = 2; + const int xp_exports = 675; + const int xp_imports = 422; + const int xp_delay_imports = 8; + const int xp_relocs = 9180; + const int vista_delay_dlls = 4; + const int vista_exports = 799; + const int vista_imports = 476; + const int vista_delay_imports = 24; + const int vista_relocs = 10188; + const int w2k_delay_dlls = 0; + const int w2k_exports = 566; + const int w2k_imports = 357; + const int w2k_delay_imports = 0; + const int w2k_relocs = 7388; + const int win7_delay_dlls = 7; + const int win7_exports = 806; + const int win7_imports = 568; + const int win7_delay_imports = 71; + const int win7_relocs = 7812; + + // Contains the expected value, for each enumerated property (Value), and the + // OS version: [Value][os_version] + const int expected[][4] = { + {4, 4, 4, 4}, + {3, 3, 3, 13}, + {w2k_delay_dlls, xp_delay_dlls, vista_delay_dlls, win7_delay_dlls}, + {w2k_exports, xp_exports, vista_exports, win7_exports}, + {w2k_imports, xp_imports, vista_imports, win7_imports}, + {w2k_delay_imports, xp_delay_imports, + vista_delay_imports, win7_delay_imports}, + {w2k_relocs, xp_relocs, vista_relocs, win7_relocs} + }; + + if (value > relocs) + return 0; + if (50 == os) + os = 0; // 5.0 + else if (51 == os || 52 == os) + os = 1; + else if (os == 60) + os = 2; // 6.x + else if (os >= 61) + os = 3; + else + return 0; + + return expected[value][os]; +} + +// Tests that we are able to enumerate stuff from a PE file, and that +// the actual number of items found is within the expected range. +TEST(PEImageTest, EnumeratesPE) { + // Windows Server 2003 is not supported as a test environment for this test. + if (base::win::GetVersion() == base::win::VERSION_SERVER_2003) + return; + HMODULE module = LoadLibrary(L"advapi32.dll"); + ASSERT_TRUE(NULL != module); + + PEImage pe(module); + int count = 0; + EXPECT_TRUE(pe.VerifyMagic()); + + DWORD os = pe.GetNTHeaders()->OptionalHeader.MajorOperatingSystemVersion; + os = os * 10 + pe.GetNTHeaders()->OptionalHeader.MinorOperatingSystemVersion; + + pe.EnumSections(SectionsCallback, &count); + EXPECT_EQ(GetExpectedValue(sections, os), count); + + count = 0; + pe.EnumImportChunks(ImportChunksCallback, &count); + EXPECT_EQ(GetExpectedValue(imports_dlls, os), count); + + count = 0; + pe.EnumDelayImportChunks(DelayImportChunksCallback, &count); + EXPECT_EQ(GetExpectedValue(delay_dlls, os), count); + + count = 0; + pe.EnumExports(ExportsCallback, &count); + EXPECT_GT(count, GetExpectedValue(exports, os) - 20); + EXPECT_LT(count, GetExpectedValue(exports, os) + 100); + + count = 0; + pe.EnumAllImports(ImportsCallback, &count); + EXPECT_GT(count, GetExpectedValue(imports, os) - 20); + EXPECT_LT(count, GetExpectedValue(imports, os) + 100); + + count = 0; + pe.EnumAllDelayImports(ImportsCallback, &count); + EXPECT_GT(count, GetExpectedValue(delay_imports, os) - 2); + EXPECT_LT(count, GetExpectedValue(delay_imports, os) + 8); + + count = 0; + pe.EnumRelocs(RelocsCallback, &count); + EXPECT_GT(count, GetExpectedValue(relocs, os) - 150); + EXPECT_LT(count, GetExpectedValue(relocs, os) + 1500); + + FreeLibrary(module); +} + +// Tests that we can locate an specific exported symbol, by name and by ordinal. +TEST(PEImageTest, RetrievesExports) { + HMODULE module = LoadLibrary(L"advapi32.dll"); + ASSERT_TRUE(NULL != module); + + PEImage pe(module); + WORD ordinal; + + EXPECT_TRUE(pe.GetProcOrdinal("RegEnumKeyExW", &ordinal)); + + FARPROC address1 = pe.GetProcAddress("RegEnumKeyExW"); + FARPROC address2 = pe.GetProcAddress(reinterpret_cast(ordinal)); + EXPECT_TRUE(address1 != NULL); + EXPECT_TRUE(address2 != NULL); + EXPECT_TRUE(address1 == address2); + + FreeLibrary(module); +} + +} // namespace win +} // namespace base diff --git a/base/win/registry.cc b/base/win/registry.cc new file mode 100644 index 0000000..545c337 --- /dev/null +++ b/base/win/registry.cc @@ -0,0 +1,387 @@ +// 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 "base/win/registry.h" + +#include + +#include "base/logging.h" + +#pragma comment(lib, "shlwapi.lib") // for SHDeleteKey + +namespace base { +namespace win { + +RegistryValueIterator::RegistryValueIterator(HKEY root_key, + const wchar_t* folder_key) { + LONG result = RegOpenKeyEx(root_key, folder_key, 0, KEY_READ, &key_); + if (result != ERROR_SUCCESS) { + key_ = NULL; + } else { + DWORD count = 0; + result = ::RegQueryInfoKey(key_, NULL, 0, NULL, NULL, NULL, NULL, &count, + NULL, NULL, NULL, NULL); + + if (result != ERROR_SUCCESS) { + ::RegCloseKey(key_); + key_ = NULL; + } else { + index_ = count - 1; + } + } + + Read(); +} + +RegistryValueIterator::~RegistryValueIterator() { + if (key_) + ::RegCloseKey(key_); +} + +bool RegistryValueIterator::Valid() const { + return key_ != NULL && index_ >= 0; +} + +void RegistryValueIterator::operator++() { + --index_; + Read(); +} + +bool RegistryValueIterator::Read() { + if (Valid()) { + DWORD ncount = arraysize(name_); + value_size_ = sizeof(value_); + LRESULT r = ::RegEnumValue(key_, index_, name_, &ncount, NULL, &type_, + reinterpret_cast(value_), &value_size_); + if (ERROR_SUCCESS == r) + return true; + } + + name_[0] = '\0'; + value_[0] = '\0'; + value_size_ = 0; + return false; +} + +DWORD RegistryValueIterator::ValueCount() const { + DWORD count = 0; + HRESULT result = ::RegQueryInfoKey(key_, NULL, 0, NULL, NULL, NULL, NULL, + &count, NULL, NULL, NULL, NULL); + + if (result != ERROR_SUCCESS) + return 0; + + return count; +} + +RegistryKeyIterator::RegistryKeyIterator(HKEY root_key, + const wchar_t* folder_key) { + LONG result = RegOpenKeyEx(root_key, folder_key, 0, KEY_READ, &key_); + if (result != ERROR_SUCCESS) { + key_ = NULL; + } else { + DWORD count = 0; + HRESULT result = ::RegQueryInfoKey(key_, NULL, 0, NULL, &count, NULL, NULL, + NULL, NULL, NULL, NULL, NULL); + + if (result != ERROR_SUCCESS) { + ::RegCloseKey(key_); + key_ = NULL; + } else { + index_ = count - 1; + } + } + + Read(); +} + +RegistryKeyIterator::~RegistryKeyIterator() { + if (key_) + ::RegCloseKey(key_); +} + +bool RegistryKeyIterator::Valid() const { + return key_ != NULL && index_ >= 0; +} + +void RegistryKeyIterator::operator++() { + --index_; + Read(); +} + +bool RegistryKeyIterator::Read() { + if (Valid()) { + DWORD ncount = arraysize(name_); + FILETIME written; + LRESULT r = ::RegEnumKeyEx(key_, index_, name_, &ncount, NULL, NULL, + NULL, &written); + if (ERROR_SUCCESS == r) + return true; + } + + name_[0] = '\0'; + return false; +} + +DWORD RegistryKeyIterator::SubkeyCount() const { + DWORD count = 0; + HRESULT result = ::RegQueryInfoKey(key_, NULL, 0, NULL, &count, NULL, NULL, + NULL, NULL, NULL, NULL, NULL); + + if (result != ERROR_SUCCESS) + return 0; + + return count; +} + +RegKey::RegKey() + : key_(NULL), + watch_event_(0) { +} + +RegKey::RegKey(HKEY rootkey, const wchar_t* subkey, REGSAM access) + : key_(NULL), + watch_event_(0) { + if (rootkey) { + if (access & (KEY_SET_VALUE | KEY_CREATE_SUB_KEY | KEY_CREATE_LINK)) + Create(rootkey, subkey, access); + else + Open(rootkey, subkey, access); + } else { + DCHECK(!subkey); + } +} + +RegKey::~RegKey() { + Close(); +} + +void RegKey::Close() { + StopWatching(); + if (key_) { + ::RegCloseKey(key_); + key_ = NULL; + } +} + +bool RegKey::Create(HKEY rootkey, const wchar_t* subkey, REGSAM access) { + DWORD disposition_value; + return CreateWithDisposition(rootkey, subkey, &disposition_value, access); +} + +bool RegKey::CreateWithDisposition(HKEY rootkey, const wchar_t* subkey, + DWORD* disposition, REGSAM access) { + DCHECK(rootkey && subkey && access && disposition); + Close(); + + LONG result = RegCreateKeyEx(rootkey, + subkey, + 0, + NULL, + REG_OPTION_NON_VOLATILE, + access, + NULL, + &key_, + disposition); + if (result != ERROR_SUCCESS) { + key_ = NULL; + return false; + } + + return true; +} + +bool RegKey::Open(HKEY rootkey, const wchar_t* subkey, REGSAM access) { + DCHECK(rootkey && subkey && access); + Close(); + + LONG result = RegOpenKeyEx(rootkey, subkey, 0, access, &key_); + if (result != ERROR_SUCCESS) { + key_ = NULL; + return false; + } + return true; +} + +bool RegKey::CreateKey(const wchar_t* name, REGSAM access) { + DCHECK(name && access); + + HKEY subkey = NULL; + LONG result = RegCreateKeyEx(key_, name, 0, NULL, REG_OPTION_NON_VOLATILE, + access, NULL, &subkey, NULL); + Close(); + + key_ = subkey; + return (result == ERROR_SUCCESS); +} + +bool RegKey::OpenKey(const wchar_t* name, REGSAM access) { + DCHECK(name && access); + + HKEY subkey = NULL; + LONG result = RegOpenKeyEx(key_, name, 0, access, &subkey); + + Close(); + + key_ = subkey; + return (result == ERROR_SUCCESS); +} + +DWORD RegKey::ValueCount() { + DWORD count = 0; + HRESULT result = RegQueryInfoKey(key_, NULL, 0, NULL, NULL, NULL, + NULL, &count, NULL, NULL, NULL, NULL); + return (result != ERROR_SUCCESS) ? 0 : count; +} + +bool RegKey::ReadName(int index, std::wstring* name) { + wchar_t buf[256]; + DWORD bufsize = arraysize(buf); + LRESULT r = ::RegEnumValue(key_, index, buf, &bufsize, NULL, NULL, + NULL, NULL); + if (r != ERROR_SUCCESS) + return false; + if (name) + *name = buf; + return true; +} + +bool RegKey::ValueExists(const wchar_t* name) { + if (!key_) + return false; + HRESULT result = RegQueryValueEx(key_, name, 0, NULL, NULL, NULL); + return (result == ERROR_SUCCESS); +} + +bool RegKey::ReadValue(const wchar_t* name, void* data, + DWORD* dsize, DWORD* dtype) { + if (!key_) + return false; + HRESULT result = RegQueryValueEx(key_, name, 0, dtype, + reinterpret_cast(data), dsize); + return (result == ERROR_SUCCESS); +} + +bool RegKey::ReadValue(const wchar_t* name, std::wstring* value) { + DCHECK(value); + const size_t kMaxStringLength = 1024; // This is after expansion. + // Use the one of the other forms of ReadValue if 1024 is too small for you. + wchar_t raw_value[kMaxStringLength]; + DWORD type = REG_SZ, size = sizeof(raw_value); + if (ReadValue(name, raw_value, &size, &type)) { + if (type == REG_SZ) { + *value = raw_value; + } else if (type == REG_EXPAND_SZ) { + wchar_t expanded[kMaxStringLength]; + size = ExpandEnvironmentStrings(raw_value, expanded, kMaxStringLength); + // Success: returns the number of wchar_t's copied + // Fail: buffer too small, returns the size required + // Fail: other, returns 0 + if (size == 0 || size > kMaxStringLength) + return false; + *value = expanded; + } else { + // Not a string. Oops. + return false; + } + return true; + } + + return false; +} + +bool RegKey::ReadValueDW(const wchar_t* name, DWORD* value) { + DCHECK(value); + DWORD type = REG_DWORD; + DWORD size = sizeof(DWORD); + DWORD result = 0; + if (ReadValue(name, &result, &size, &type) && + (type == REG_DWORD || type == REG_BINARY) && + size == sizeof(DWORD)) { + *value = result; + return true; + } + + return false; +} + +bool RegKey::WriteValue(const wchar_t* name, const void * data, + DWORD dsize, DWORD dtype) { + DCHECK(data); + + if (!key_) + return false; + + HRESULT result = RegSetValueEx( + key_, + name, + 0, + dtype, + reinterpret_cast(const_cast(data)), + dsize); + return (result == ERROR_SUCCESS); +} + +bool RegKey::WriteValue(const wchar_t * name, const wchar_t* value) { + return WriteValue(name, value, + static_cast(sizeof(*value) * (wcslen(value) + 1)), REG_SZ); +} + +bool RegKey::WriteValue(const wchar_t* name, DWORD value) { + return WriteValue(name, &value, + static_cast(sizeof(value)), REG_DWORD); +} + +bool RegKey::DeleteKey(const wchar_t* name) { + return (!key_) ? false : (ERROR_SUCCESS == SHDeleteKey(key_, name)); +} + +bool RegKey::DeleteValue(const wchar_t* value_name) { + DCHECK(value_name); + HRESULT result = RegDeleteValue(key_, value_name); + return (result == ERROR_SUCCESS); +} + +bool RegKey::StartWatching() { + if (!watch_event_) + watch_event_ = CreateEvent(NULL, TRUE, FALSE, NULL); + + DWORD filter = REG_NOTIFY_CHANGE_NAME | + REG_NOTIFY_CHANGE_ATTRIBUTES | + REG_NOTIFY_CHANGE_LAST_SET | + REG_NOTIFY_CHANGE_SECURITY; + + // Watch the registry key for a change of value. + HRESULT result = RegNotifyChangeKeyValue(key_, TRUE, filter, + watch_event_, TRUE); + if (SUCCEEDED(result)) { + return true; + } else { + CloseHandle(watch_event_); + watch_event_ = 0; + return false; + } +} + +bool RegKey::StopWatching() { + if (watch_event_) { + CloseHandle(watch_event_); + watch_event_ = 0; + return true; + } + return false; +} + +bool RegKey::HasChanged() { + if (watch_event_) { + if (WaitForSingleObject(watch_event_, 0) == WAIT_OBJECT_0) { + StartWatching(); + return true; + } + } + return false; +} + +} // namespace win +} // namespace base diff --git a/base/win/registry.h b/base/win/registry.h new file mode 100644 index 0000000..d1ef25b --- /dev/null +++ b/base/win/registry.h @@ -0,0 +1,171 @@ +// 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. + +#ifndef BASE_WIN_REGISTRY_H_ +#define BASE_WIN_REGISTRY_H_ +#pragma once + +#include +#include + +#include "base/basictypes.h" + +namespace base { +namespace win { + +// Utility class to read, write and manipulate the Windows Registry. +// Registry vocabulary primer: a "key" is like a folder, in which there +// are "values", which are pairs, with an associated data type. +class RegKey { + public: + RegKey(); + RegKey(HKEY rootkey, const wchar_t* subkey, REGSAM access); + ~RegKey(); + + bool Create(HKEY rootkey, const wchar_t* subkey, REGSAM access); + + bool CreateWithDisposition(HKEY rootkey, const wchar_t* subkey, + DWORD* disposition, REGSAM access); + + bool Open(HKEY rootkey, const wchar_t* subkey, REGSAM access); + + // Creates a subkey or open it if it already exists. + bool CreateKey(const wchar_t* name, REGSAM access); + + // Opens a subkey + bool OpenKey(const wchar_t* name, REGSAM access); + + void Close(); + + DWORD ValueCount(); + + // Determine the nth value's name. + bool ReadName(int index, std::wstring* name); + + // True while the key is valid. + bool Valid() const { return key_ != NULL; } + + // Kill a key and everything that live below it; please be careful when using + // it. + bool DeleteKey(const wchar_t* name); + + // Deletes a single value within the key. + bool DeleteValue(const wchar_t* name); + + bool ValueExists(const wchar_t* name); + + bool ReadValue(const wchar_t* name, void* data, DWORD* dsize, DWORD* dtype); + bool ReadValue(const wchar_t* name, std::wstring* value); + bool ReadValueDW(const wchar_t* name, DWORD* value); + + bool WriteValue(const wchar_t* name, const void* data, DWORD dsize, + DWORD dtype); + bool WriteValue(const wchar_t* name, const wchar_t* value); + bool WriteValue(const wchar_t* name, DWORD value); + + // Starts watching the key to see if any of its values have changed. + // The key must have been opened with the KEY_NOTIFY access privelege. + bool StartWatching(); + + // If StartWatching hasn't been called, always returns false. + // Otherwise, returns true if anything under the key has changed. + // This can't be const because the |watch_event_| may be refreshed. + bool HasChanged(); + + // Will automatically be called by destructor if not manually called + // beforehand. Returns true if it was watching, false otherwise. + bool StopWatching(); + + inline bool IsWatching() const { return watch_event_ != 0; } + HANDLE watch_event() const { return watch_event_; } + HKEY Handle() const { return key_; } + + private: + HKEY key_; // The registry key being iterated. + HANDLE watch_event_; + + DISALLOW_COPY_AND_ASSIGN(RegKey); +}; + +// Iterates the entries found in a particular folder on the registry. +// For this application I happen to know I wont need data size larger +// than MAX_PATH, but in real life this wouldn't neccessarily be +// adequate. +class RegistryValueIterator { + public: + RegistryValueIterator(HKEY root_key, const wchar_t* folder_key); + + ~RegistryValueIterator(); + + DWORD ValueCount() const; + + // True while the iterator is valid. + bool Valid() const; + + // Advances to the next registry entry. + void operator++(); + + const wchar_t* Name() const { return name_; } + const wchar_t* Value() const { return value_; } + DWORD ValueSize() const { return value_size_; } + DWORD Type() const { return type_; } + + int Index() const { return index_; } + + private: + // Read in the current values. + bool Read(); + + // The registry key being iterated. + HKEY key_; + + // Current index of the iteration. + int index_; + + // Current values. + wchar_t name_[MAX_PATH]; + wchar_t value_[MAX_PATH]; + DWORD value_size_; + DWORD type_; + + DISALLOW_COPY_AND_ASSIGN(RegistryValueIterator); +}; + +class RegistryKeyIterator { + public: + RegistryKeyIterator(HKEY root_key, const wchar_t* folder_key); + + ~RegistryKeyIterator(); + + DWORD SubkeyCount() const; + + // True while the iterator is valid. + bool Valid() const; + + // Advances to the next entry in the folder. + void operator++(); + + const wchar_t* Name() const { return name_; } + + int Index() const { return index_; } + + private: + // Read in the current values. + bool Read(); + + // The registry key being iterated. + HKEY key_; + + // Current index of the iteration. + int index_; + + wchar_t name_[MAX_PATH]; + + DISALLOW_COPY_AND_ASSIGN(RegistryKeyIterator); +}; + +} // namespace win +} // namespace base + +#endif // BASE_WIN_REGISTRY_H_ diff --git a/base/win/registry_unittest.cc b/base/win/registry_unittest.cc new file mode 100644 index 0000000..524612a --- /dev/null +++ b/base/win/registry_unittest.cc @@ -0,0 +1,65 @@ +// 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 "base/win/registry.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace base { +namespace win { + +namespace { + +const wchar_t kRootKey[] = L"Base_Registry_Unittest"; + +class RegistryTest : public testing::Test { + public: + RegistryTest() {} + + protected: + virtual void SetUp() { + // Create a temporary key. + RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); + key.DeleteKey(kRootKey); + ASSERT_FALSE(key.Open(HKEY_CURRENT_USER, kRootKey, KEY_READ)); + ASSERT_TRUE(key.Create(HKEY_CURRENT_USER, kRootKey, KEY_READ)); + } + + virtual void TearDown() { + // Clean up the temporary key. + RegKey key(HKEY_CURRENT_USER, L"", KEY_SET_VALUE); + ASSERT_TRUE(key.DeleteKey(kRootKey)); + } + + private: + DISALLOW_COPY_AND_ASSIGN(RegistryTest); +}; + +TEST_F(RegistryTest, ValueTest) { + RegKey key; + + std::wstring foo_key(kRootKey); + foo_key += L"\\Foo"; + ASSERT_TRUE(key.Create(HKEY_CURRENT_USER, foo_key.c_str(), KEY_READ)); + + { + ASSERT_TRUE(key.Open(HKEY_CURRENT_USER, foo_key.c_str(), + KEY_READ | KEY_SET_VALUE)); + + const wchar_t* kName = L"Bar"; + const wchar_t* kValue = L"bar"; + EXPECT_TRUE(key.WriteValue(kName, kValue)); + EXPECT_TRUE(key.ValueExists(kName)); + std::wstring out_value; + EXPECT_TRUE(key.ReadValue(kName, &out_value)); + EXPECT_NE(out_value, L""); + EXPECT_STREQ(out_value.c_str(), kValue); + EXPECT_EQ(1U, key.ValueCount()); + EXPECT_TRUE(key.DeleteValue(kName)); + } +} + +} // namespace + +} // namespace win +} // namespace base diff --git a/base/win_util.cc b/base/win_util.cc index 70d2829..a576122 100644 --- a/base/win_util.cc +++ b/base/win_util.cc @@ -12,7 +12,7 @@ #include #include "base/logging.h" -#include "base/registry.h" +#include "base/win/registry.h" #include "base/scoped_handle.h" #include "base/scoped_ptr.h" #include "base/string_util.h" @@ -127,7 +127,7 @@ std::wstring GetClassName(HWND window) { } bool UserAccountControlIsEnabled() { - RegKey key(HKEY_LOCAL_MACHINE, + base::win::RegKey key(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", KEY_READ); DWORD uac_enabled; @@ -187,12 +187,12 @@ static const char16 kAutoRunKeyPath[] = bool AddCommandToAutoRun(HKEY root_key, const string16& name, const string16& command) { - RegKey autorun_key(root_key, kAutoRunKeyPath, KEY_SET_VALUE); + base::win::RegKey autorun_key(root_key, kAutoRunKeyPath, KEY_SET_VALUE); return autorun_key.WriteValue(name.c_str(), command.c_str()); } bool RemoveCommandFromAutoRun(HKEY root_key, const string16& name) { - RegKey autorun_key(root_key, kAutoRunKeyPath, KEY_SET_VALUE); + base::win::RegKey autorun_key(root_key, kAutoRunKeyPath, KEY_SET_VALUE); return autorun_key.DeleteValue(name.c_str()); } diff --git a/base/windows_message_list.h b/base/windows_message_list.h deleted file mode 100644 index 3452bab..0000000 --- a/base/windows_message_list.h +++ /dev/null @@ -1,249 +0,0 @@ -// Copyright (c) 2006-2008 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. - -// WARNING: DO NOT USE standard header file protection. -// This file may be include several times in its entirety. - -// This file contains a list of all messages supported by Windows as would be -// handled in a message loop. We only list the messages provided in -// , and do not currently include (the otherwise undefined) -// #define WM_SYSTIMER 0x118 - -// By using various macro tricks, this list can be used to create pretty print -// functions for the messages. See message_loop.cc for an example. - -// Start list of Windows Messages given in -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NULL) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_CREATE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_DESTROY) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MOVE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_SIZE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_ACTIVATE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_SETFOCUS) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_KILLFOCUS) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_ENABLE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_SETREDRAW) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_SETTEXT) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_GETTEXT) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_GETTEXTLENGTH) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_PAINT) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_CLOSE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_QUERYENDSESSION) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_QUERYOPEN) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_ENDSESSION) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_QUIT) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_ERASEBKGND) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_SYSCOLORCHANGE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_SHOWWINDOW) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_WININICHANGE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_SETTINGCHANGE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_DEVMODECHANGE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_ACTIVATEAPP) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_FONTCHANGE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_TIMECHANGE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_CANCELMODE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_SETCURSOR) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MOUSEACTIVATE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_CHILDACTIVATE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_QUEUESYNC) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_GETMINMAXINFO) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_PAINTICON) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_ICONERASEBKGND) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NEXTDLGCTL) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_SPOOLERSTATUS) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_DRAWITEM) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MEASUREITEM) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_DELETEITEM) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_VKEYTOITEM) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_CHARTOITEM) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_SETFONT) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_GETFONT) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_SETHOTKEY) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_GETHOTKEY) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_QUERYDRAGICON) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_COMPAREITEM) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_GETOBJECT) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_COMPACTING) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_COMMNOTIFY) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_WINDOWPOSCHANGING) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_WINDOWPOSCHANGED) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_POWER) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_COPYDATA) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_CANCELJOURNAL) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NOTIFY) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_INPUTLANGCHANGEREQUEST) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_INPUTLANGCHANGE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_TCARD) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_HELP) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_USERCHANGED) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NOTIFYFORMAT) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_CONTEXTMENU) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_STYLECHANGING) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_STYLECHANGED) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_DISPLAYCHANGE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_GETICON) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_SETICON) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NCCREATE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NCDESTROY) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NCCALCSIZE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NCHITTEST) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NCPAINT) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NCACTIVATE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_GETDLGCODE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_SYNCPAINT) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NCMOUSEMOVE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NCLBUTTONDOWN) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NCLBUTTONUP) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NCLBUTTONDBLCLK) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NCRBUTTONDOWN) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NCRBUTTONUP) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NCRBUTTONDBLCLK) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NCMBUTTONDOWN) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NCMBUTTONUP) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NCMBUTTONDBLCLK) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NCXBUTTONDOWN) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NCXBUTTONUP) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NCXBUTTONDBLCLK) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_INPUT_DEVICE_CHANGE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_INPUT) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_KEYFIRST) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_KEYDOWN) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_KEYUP) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_CHAR) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_DEADCHAR) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_SYSKEYDOWN) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_SYSKEYUP) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_SYSCHAR) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_SYSDEADCHAR) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_UNICHAR) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_KEYLAST) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_KEYLAST) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_IME_STARTCOMPOSITION) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_IME_ENDCOMPOSITION) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_IME_COMPOSITION) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_IME_KEYLAST) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_INITDIALOG) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_COMMAND) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_SYSCOMMAND) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_TIMER) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_HSCROLL) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_VSCROLL) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_INITMENU) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_INITMENUPOPUP) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MENUSELECT) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MENUCHAR) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_ENTERIDLE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MENURBUTTONUP) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MENUDRAG) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MENUGETOBJECT) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_UNINITMENUPOPUP) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MENUCOMMAND) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_CHANGEUISTATE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_UPDATEUISTATE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_QUERYUISTATE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_CTLCOLORMSGBOX) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_CTLCOLOREDIT) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_CTLCOLORLISTBOX) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_CTLCOLORBTN) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_CTLCOLORDLG) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_CTLCOLORSCROLLBAR) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_CTLCOLORSTATIC) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MOUSEFIRST) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MOUSEMOVE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_LBUTTONDOWN) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_LBUTTONUP) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_LBUTTONDBLCLK) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_RBUTTONDOWN) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_RBUTTONUP) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_RBUTTONDBLCLK) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MBUTTONDOWN) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MBUTTONUP) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MBUTTONDBLCLK) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MOUSEWHEEL) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_XBUTTONDOWN) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_XBUTTONUP) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_XBUTTONDBLCLK) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MOUSEHWHEEL) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MOUSELAST) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MOUSELAST) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MOUSELAST) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MOUSELAST) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_PARENTNOTIFY) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_ENTERMENULOOP) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_EXITMENULOOP) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NEXTMENU) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_SIZING) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_CAPTURECHANGED) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MOVING) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_POWERBROADCAST) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_DEVICECHANGE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MDICREATE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MDIDESTROY) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MDIACTIVATE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MDIRESTORE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MDINEXT) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MDIMAXIMIZE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MDITILE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MDICASCADE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MDIICONARRANGE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MDIGETACTIVE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MDISETMENU) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_ENTERSIZEMOVE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_EXITSIZEMOVE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_DROPFILES) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MDIREFRESHMENU) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_IME_SETCONTEXT) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_IME_NOTIFY) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_IME_CONTROL) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_IME_COMPOSITIONFULL) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_IME_SELECT) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_IME_CHAR) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_IME_REQUEST) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_IME_KEYDOWN) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_IME_KEYUP) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MOUSEHOVER) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_MOUSELEAVE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NCMOUSEHOVER) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_NCMOUSELEAVE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_WTSSESSION_CHANGE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_TABLET_FIRST) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_TABLET_LAST) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_CUT) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_COPY) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_PASTE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_CLEAR) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_UNDO) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_RENDERFORMAT) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_RENDERALLFORMATS) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_DESTROYCLIPBOARD) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_DRAWCLIPBOARD) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_PAINTCLIPBOARD) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_VSCROLLCLIPBOARD) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_SIZECLIPBOARD) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_ASKCBFORMATNAME) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_CHANGECBCHAIN) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_HSCROLLCLIPBOARD) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_QUERYNEWPALETTE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_PALETTEISCHANGING) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_PALETTECHANGED) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_HOTKEY) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_PRINT) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_PRINTCLIENT) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_APPCOMMAND) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_THEMECHANGED) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_CLIPBOARDUPDATE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_DWMCOMPOSITIONCHANGED) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_DWMNCRENDERINGCHANGED) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_DWMCOLORIZATIONCOLORCHANGED) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_DWMWINDOWMAXIMIZEDCHANGE) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_GETTITLEBARINFOEX) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_HANDHELDFIRST) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_HANDHELDLAST) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_AFXFIRST) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_AFXLAST) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_PENWINFIRST) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_PENWINLAST) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_APP) -A_NAMED_MESSAGE_FROM_WINUSER_H(WM_USER) -// End list of Windows Messages given in diff --git a/chrome/app/breakpad_win.cc b/chrome/app/breakpad_win.cc index 3f4f862..308678e 100644 --- a/chrome/app/breakpad_win.cc +++ b/chrome/app/breakpad_win.cc @@ -16,12 +16,12 @@ #include "base/environment.h" #include "base/file_util.h" #include "base/file_version_info.h" -#include "base/registry.h" #include "base/scoped_ptr.h" #include "base/string_split.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "base/win_util.h" +#include "base/win/registry.h" #include "breakpad/src/client/windows/handler/exception_handler.h" #include "chrome/app/hard_error_handler_win.h" #include "chrome/common/child_process_logging.h" @@ -432,13 +432,15 @@ bool ShowRestartDialogIfCrashed(bool* exit_now) { static bool MetricsReportingControlledByPolicy(bool* result) { std::wstring key_name = UTF8ToWide(policy::key::kMetricsReportingEnabled); DWORD value; - RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, policy::kRegistrySubKey, KEY_READ); + base::win::RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, + policy::kRegistrySubKey, KEY_READ); if (hkcu_policy_key.ReadValueDW(key_name.c_str(), &value)) { *result = value != 0; return true; } - RegKey hklm_policy_key(HKEY_CURRENT_USER, policy::kRegistrySubKey, KEY_READ); + base::win::RegKey hklm_policy_key(HKEY_CURRENT_USER, + policy::kRegistrySubKey, KEY_READ); if (hklm_policy_key.ReadValueDW(key_name.c_str(), &value)) { *result = value != 0; return true; diff --git a/chrome/browser/autofill/autofill_ie_toolbar_import_win.cc b/chrome/browser/autofill/autofill_ie_toolbar_import_win.cc index de151e3..dcfe0a5 100644 --- a/chrome/browser/autofill/autofill_ie_toolbar_import_win.cc +++ b/chrome/browser/autofill/autofill_ie_toolbar_import_win.cc @@ -5,14 +5,16 @@ #include "chrome/browser/autofill/autofill_ie_toolbar_import_win.h" #include "base/basictypes.h" -#include "base/registry.h" #include "base/string16.h" +#include "base/win/registry.h" #include "chrome/browser/autofill/autofill_profile.h" #include "chrome/browser/autofill/credit_card.h" #include "chrome/browser/autofill/field_types.h" #include "chrome/browser/autofill/personal_data_manager.h" #include "chrome/browser/sync/util/data_encryption.h" +using base::win::RegKey; + // Forward declaration. This function is not in unnamed namespace as it // is referenced in the unittest. bool ImportCurrentUserProfiles(std::vector* profiles, @@ -177,7 +179,8 @@ bool ImportCurrentUserProfiles(std::vector* profiles, profile_reg_values[i].field_type; } - RegistryKeyIterator iterator_profiles(HKEY_CURRENT_USER, kProfileKey); + base::win::RegistryKeyIterator iterator_profiles(HKEY_CURRENT_USER, + kProfileKey); for (; iterator_profiles.Valid(); ++iterator_profiles) { std::wstring key_name(kProfileKey); key_name.append(L"\\"); @@ -208,7 +211,8 @@ bool ImportCurrentUserProfiles(std::vector* profiles, // We import CC profiles only if they are not password protected. if (password_hash.empty() && IsEmptySalt(salt)) { - RegistryKeyIterator iterator_cc(HKEY_CURRENT_USER, kCreditCardKey); + base::win::RegistryKeyIterator iterator_cc(HKEY_CURRENT_USER, + kCreditCardKey); for (; iterator_cc.Valid(); ++iterator_cc) { std::wstring key_name(kCreditCardKey); key_name.append(L"\\"); diff --git a/chrome/browser/autofill/autofill_ie_toolbar_import_win_unittest.cc b/chrome/browser/autofill/autofill_ie_toolbar_import_win_unittest.cc index 9aa7649..0512139 100644 --- a/chrome/browser/autofill/autofill_ie_toolbar_import_win_unittest.cc +++ b/chrome/browser/autofill/autofill_ie_toolbar_import_win_unittest.cc @@ -5,14 +5,16 @@ #include "chrome/browser/autofill/autofill_ie_toolbar_import_win.h" #include "base/basictypes.h" -#include "base/registry.h" #include "base/string16.h" +#include "base/win/registry.h" #include "chrome/browser/autofill/autofill_profile.h" #include "chrome/browser/autofill/credit_card.h" #include "chrome/browser/autofill/field_types.h" #include "chrome/browser/sync/util/data_encryption.h" #include "testing/gtest/include/gtest/gtest.h" +using base::win::RegKey; + // Defined in autofill_ie_toolbar_import_win.cc. Not exposed in the header file. bool ImportCurrentUserProfiles(std::vector* profiles, std::vector* credit_cards); diff --git a/chrome/browser/background_mode_manager.cc b/chrome/browser/background_mode_manager.cc index ef16b49..080e3b2 100644 --- a/chrome/browser/background_mode_manager.cc +++ b/chrome/browser/background_mode_manager.cc @@ -53,7 +53,7 @@ static const char kXdgConfigHome[] = "XDG_CONFIG_HOME"; #endif #if defined(OS_WIN) -#include "base/registry.h" +#include "base/win/registry.h" const HKEY kBackgroundModeRegistryRootKey = HKEY_CURRENT_USER; const wchar_t* kBackgroundModeRegistrySubkey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; @@ -401,10 +401,10 @@ void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) { // TODO(rickcam): Bug 53597: Make RegKey mockable. // TODO(rickcam): Bug 53600: Use distinct registry keys per flavor+profile. const wchar_t* key_name = kBackgroundModeRegistryKeyName; - RegKey read_key(kBackgroundModeRegistryRootKey, - kBackgroundModeRegistrySubkey, KEY_READ); - RegKey write_key(kBackgroundModeRegistryRootKey, - kBackgroundModeRegistrySubkey, KEY_WRITE); + base::win::RegKey read_key(kBackgroundModeRegistryRootKey, + kBackgroundModeRegistrySubkey, KEY_READ); + base::win::RegKey write_key(kBackgroundModeRegistryRootKey, + kBackgroundModeRegistrySubkey, KEY_WRITE); if (should_launch) { FilePath executable; if (!PathService::Get(base::FILE_EXE, &executable)) diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc index 4360909..73f31c4 100644 --- a/chrome/browser/download/download_util.cc +++ b/chrome/browser/download/download_util.cc @@ -72,8 +72,7 @@ #include "app/os_exchange_data_provider_win.h" #include "app/win_util.h" #include "base/base_drag_source.h" -#include "base/registry.h" -#include "base/scoped_comptr_win.h" +#include "base/win/scoped_comptr.h" #include "base/win_util.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/views/frame/browser_view.h" @@ -602,7 +601,7 @@ void UpdateAppIconDownloadProgress(int download_count, if (base::win::GetVersion() < base::win::VERSION_WIN7) return; - ScopedComPtr taskbar; + base::win::ScopedComPtr taskbar; HRESULT result = taskbar.CreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER); if (FAILED(result)) { diff --git a/chrome/browser/extensions/extension_rlz_apitest.cc b/chrome/browser/extensions/extension_rlz_apitest.cc index ce97ae0f..10bfba6 100644 --- a/chrome/browser/extensions/extension_rlz_apitest.cc +++ b/chrome/browser/extensions/extension_rlz_apitest.cc @@ -4,7 +4,7 @@ #include -#include "base/registry.h" +#include "base/win/registry.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/extensions/extension_function.h" #include "chrome/browser/extensions/extension_function_dispatcher.h" @@ -51,8 +51,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Rlz) { rlz_lib::ClearProductState(rlz_lib::DESKTOP, access_points); // Check that the state has really been cleared. - RegKey key(HKEY_CURRENT_USER, L"Software\\Google\\Common\\Rlz\\Events\\N", - KEY_READ); + base::win::RegKey key(HKEY_CURRENT_USER, + L"Software\\Google\\Common\\Rlz\\Events\\N", + KEY_READ); ASSERT_FALSE(key.Valid()); key.Open(HKEY_CURRENT_USER, L"Software\\Google\\Common\\Rlz\\Events\\D", diff --git a/chrome/browser/extensions/external_registry_extension_provider_win.cc b/chrome/browser/extensions/external_registry_extension_provider_win.cc index c18aaa7..02ae850 100644 --- a/chrome/browser/extensions/external_registry_extension_provider_win.cc +++ b/chrome/browser/extensions/external_registry_extension_provider_win.cc @@ -1,14 +1,14 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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/extensions/external_registry_extension_provider_win.h" #include "base/file_path.h" -#include "base/registry.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "base/version.h" +#include "base/win/registry.h" // The Registry hive where to look for external extensions. const HKEY kRegRoot = HKEY_LOCAL_MACHINE; @@ -30,10 +30,10 @@ ExternalRegistryExtensionProvider::~ExternalRegistryExtensionProvider() { void ExternalRegistryExtensionProvider::VisitRegisteredExtension( Visitor* visitor, const std::set& ids_to_ignore) const { - RegistryKeyIterator iterator(kRegRoot, - ASCIIToWide(kRegistryExtensions).c_str()); + base::win::RegistryKeyIterator iterator( + kRegRoot, ASCIIToWide(kRegistryExtensions).c_str()); while (iterator.Valid()) { - RegKey key; + base::win::RegKey key; std::wstring key_path = ASCIIToWide(kRegistryExtensions); key_path.append(L"\\"); key_path.append(iterator.Name()); @@ -78,7 +78,7 @@ void ExternalRegistryExtensionProvider::VisitRegisteredExtension( Version* ExternalRegistryExtensionProvider::RegisteredVersion( const std::string& id, Extension::Location* location) const { - RegKey key; + base::win::RegKey key; std::wstring key_path = ASCIIToWide(kRegistryExtensions); key_path.append(L"\\"); key_path.append(ASCIIToWide(id)); diff --git a/chrome/browser/first_run/first_run_win.cc b/chrome/browser/first_run/first_run_win.cc index df3f46d..4f9175d 100644 --- a/chrome/browser/first_run/first_run_win.cc +++ b/chrome/browser/first_run/first_run_win.cc @@ -18,12 +18,12 @@ #include "base/file_util.h" #include "base/object_watcher.h" #include "base/path_service.h" -#include "base/registry.h" #include "base/scoped_comptr_win.h" #include "base/scoped_ptr.h" #include "base/string_number_conversions.h" #include "base/string_split.h" #include "base/utf_string_conversions.h" +#include "base/win/registry.h" #include "base/win/windows_version.h" #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/extensions/extension_updater.h" @@ -280,7 +280,7 @@ bool Upgrade::SwapNewChromeExeIfPresent() { bool user_install = InstallUtil::IsPerUserInstall(curr_chrome_exe.c_str()); HKEY reg_root = user_install ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; BrowserDistribution *dist = BrowserDistribution::GetDistribution(); - RegKey key; + base::win::RegKey key; std::wstring rename_cmd; if (key.Open(reg_root, dist->GetVersionKey().c_str(), KEY_READ) && key.ReadValue(google_update::kRegRenameCmdField, &rename_cmd)) { diff --git a/chrome/browser/history/history_publisher_win.cc b/chrome/browser/history/history_publisher_win.cc index 3a7a548..39ef521 100644 --- a/chrome/browser/history/history_publisher_win.cc +++ b/chrome/browser/history/history_publisher_win.cc @@ -9,13 +9,13 @@ #include #include -#include "base/registry.h" #include "base/scoped_bstr_win.h" #include "base/scoped_comptr_win.h" #include "base/scoped_variant_win.h" #include "base/string_util.h" #include "base/time.h" #include "base/utf_string_conversions.h" +#include "base/win/registry.h" #include "googleurl/src/gurl.h" namespace { @@ -42,7 +42,7 @@ bool CoCreateIndexerFromName(const wchar_t* name, void AddRegisteredIndexers(HKEY root, const wchar_t* path, std::vector< ScopedComPtr >* indexers) { IChromeHistoryIndexer* indexer; - RegistryKeyIterator r_iter(root, path); + base::win::RegistryKeyIterator r_iter(root, path); while (r_iter.Valid()) { if (CoCreateIndexerFromName(r_iter.Name(), &indexer)) { indexers->push_back(ScopedComPtr(indexer)); diff --git a/chrome/browser/importer/firefox_importer_utils_win.cc b/chrome/browser/importer/firefox_importer_utils_win.cc index 3200eb1..7fc2a41 100644 --- a/chrome/browser/importer/firefox_importer_utils_win.cc +++ b/chrome/browser/importer/firefox_importer_utils_win.cc @@ -7,7 +7,7 @@ #include #include "base/file_util.h" -#include "base/registry.h" +#include "base/win/registry.h" // NOTE: Keep these in order since we need test all those paths according // to priority. For example. One machine has multiple users. One non-admin @@ -28,8 +28,8 @@ int GetCurrentFirefoxMajorVersionFromRegistry() { // written under HKLM\Mozilla. Otherwise it the keys will be written under // HKCU\Mozilla. for (int i = 0; i < arraysize(kFireFoxRegistryPaths); ++i) { - RegKey reg_key(kFireFoxRegistryPaths[i], - L"Software\\Mozilla\\Mozilla Firefox", KEY_READ); + base::win::RegKey reg_key(kFireFoxRegistryPaths[i], + L"Software\\Mozilla\\Mozilla Firefox", KEY_READ); bool result = reg_key.ReadValue(L"CurrentVersion", ver_buffer, &ver_buffer_length, NULL); @@ -45,14 +45,16 @@ std::wstring GetFirefoxInstallPathFromRegistry() { std::wstring registry_path = L"Software\\Mozilla\\Mozilla Firefox"; wchar_t buffer[MAX_PATH]; DWORD buffer_length = sizeof(buffer); - RegKey reg_key(HKEY_LOCAL_MACHINE, registry_path.c_str(), KEY_READ); + base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, registry_path.c_str(), + KEY_READ); bool result = reg_key.ReadValue(L"CurrentVersion", buffer, &buffer_length, NULL); if (!result) return std::wstring(); registry_path += L"\\" + std::wstring(buffer) + L"\\Main"; buffer_length = sizeof(buffer); - RegKey reg_key_directory(HKEY_LOCAL_MACHINE, registry_path.c_str(), KEY_READ); + base::win::RegKey reg_key_directory(HKEY_LOCAL_MACHINE, + registry_path.c_str(), KEY_READ); result = reg_key_directory.ReadValue(L"Install Directory", buffer, &buffer_length, NULL); if (!result) diff --git a/chrome/browser/importer/ie_importer.cc b/chrome/browser/importer/ie_importer.cc index 2d6d319..07b2d34 100644 --- a/chrome/browser/importer/ie_importer.cc +++ b/chrome/browser/importer/ie_importer.cc @@ -19,13 +19,13 @@ #include "app/win_util.h" #include "base/file_path.h" #include "base/file_util.h" -#include "base/registry.h" #include "base/scoped_comptr_win.h" #include "base/string_split.h" #include "base/string_util.h" #include "base/time.h" #include "base/values.h" #include "base/utf_string_conversions.h" +#include "base/win/registry.h" #include "base/win/windows_version.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/importer/importer_bridge.h" @@ -40,6 +40,8 @@ #include "webkit/glue/password_form.h" using base::Time; +using base::win::RegKey; +using base::win::RegistryValueIterator; using webkit_glue::PasswordForm; namespace { @@ -354,7 +356,8 @@ void IEImporter::ImportSearchEngines() { const TemplateURL* default_search_engine = NULL; std::map search_engines_map; key.ReadValue(L"DefaultScope", &default_search_engine_name); - RegistryKeyIterator key_iterator(HKEY_CURRENT_USER, kSearchScopePath); + base::win::RegistryKeyIterator key_iterator(HKEY_CURRENT_USER, + kSearchScopePath); while (key_iterator.Valid()) { std::wstring sub_key_name = kSearchScopePath; sub_key_name.append(L"\\").append(key_iterator.Name()); diff --git a/chrome/browser/platform_util_win.cc b/chrome/browser/platform_util_win.cc index a807a42..c20c925 100644 --- a/chrome/browser/platform_util_win.cc +++ b/chrome/browser/platform_util_win.cc @@ -14,10 +14,10 @@ #include "base/file_util.h" #include "base/path_service.h" #include "base/logging.h" -#include "base/registry.h" #include "base/scoped_comptr_win.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" +#include "base/win/registry.h" #include "chrome/installer/util/google_update_settings.h" #include "chrome/installer/util/google_update_constants.h" #include "chrome/installer/util/install_util.h" @@ -110,7 +110,7 @@ void OpenExternal(const GURL& url) { return; } - RegKey key; + base::win::RegKey key; std::wstring registry_path = ASCIIToWide(url.scheme()) + L"\\shell\\open\\command"; key.Open(HKEY_CLASSES_ROOT, registry_path.c_str(), KEY_READ); diff --git a/chrome/browser/plugin_service.h b/chrome/browser/plugin_service.h index 9ff7988..abb55a1 100644 --- a/chrome/browser/plugin_service.h +++ b/chrome/browser/plugin_service.h @@ -21,8 +21,8 @@ #include "googleurl/src/gurl.h" #if defined(OS_WIN) -#include "base/registry.h" #include "base/scoped_ptr.h" +#include "base/win/registry.h" #endif #if defined(OS_CHROMEOS) @@ -168,8 +168,8 @@ class PluginService #if defined(OS_WIN) // Registry keys for getting notifications when new plugins are installed. - RegKey hkcu_key_; - RegKey hklm_key_; + base::win::RegKey hkcu_key_; + base::win::RegKey hklm_key_; scoped_ptr hkcu_event_; scoped_ptr hklm_event_; base::WaitableEventWatcher hkcu_watcher_; diff --git a/chrome/browser/policy/configuration_policy_provider_win.cc b/chrome/browser/policy/configuration_policy_provider_win.cc index 18edc88..c1ae3705 100644 --- a/chrome/browser/policy/configuration_policy_provider_win.cc +++ b/chrome/browser/policy/configuration_policy_provider_win.cc @@ -10,7 +10,6 @@ #include "base/logging.h" #include "base/object_watcher.h" -#include "base/registry.h" #include "base/scoped_ptr.h" #include "base/string_number_conversions.h" #include "base/string_piece.h" @@ -18,10 +17,39 @@ #include "base/sys_string_conversions.h" #include "base/utf_string_conversions.h" #include "base/values.h" +#include "base/win/registry.h" #include "chrome/common/policy_constants.h" +using base::win::RegKey; + namespace policy { +namespace { + +bool ReadRegistryStringValue(RegKey* key, const string16& name, + string16* result) { + DWORD value_size = 0; + DWORD key_type = 0; + scoped_array buffer; + + if (!key->ReadValue(name.c_str(), 0, &value_size, &key_type)) + return false; + if (key_type != REG_SZ) + return false; + + // According to the Microsoft documentation, the string + // buffer may not be explicitly 0-terminated. Allocate a + // slightly larger buffer and pre-fill to zeros to guarantee + // the 0-termination. + buffer.reset(new uint8[value_size + 2]); + memset(buffer.get(), 0, value_size + 2); + key->ReadValue(name.c_str(), buffer.get(), &value_size, NULL); + result->assign(reinterpret_cast(buffer.get())); + return true; +} + +} // namespace + // Period at which to run the reload task in case the group policy change // watchers fail. const int kReloadIntervalMinutes = 15; @@ -155,28 +183,6 @@ bool ConfigurationPolicyProviderWin::GetRegistryPolicyString( return ReadRegistryStringValue(&policy_key, name, result); } -bool ConfigurationPolicyProviderWin::ReadRegistryStringValue( - RegKey* key, const string16& name, string16* result) { - DWORD value_size = 0; - DWORD key_type = 0; - scoped_array buffer; - - if (!key->ReadValue(name.c_str(), 0, &value_size, &key_type)) - return false; - if (key_type != REG_SZ) - return false; - - // According to the Microsoft documentation, the string - // buffer may not be explicitly 0-terminated. Allocate a - // slightly larger buffer and pre-fill to zeros to guarantee - // the 0-termination. - buffer.reset(new uint8[value_size + 2]); - memset(buffer.get(), 0, value_size + 2); - key->ReadValue(name.c_str(), buffer.get(), &value_size, NULL); - result->assign(reinterpret_cast(buffer.get())); - return true; -} - bool ConfigurationPolicyProviderWin::GetRegistryPolicyStringList( const string16& key, ListValue* result) { string16 path = string16(kRegistrySubKey); diff --git a/chrome/browser/policy/configuration_policy_provider_win.h b/chrome/browser/policy/configuration_policy_provider_win.h index e0d797f..26bc3e6 100644 --- a/chrome/browser/policy/configuration_policy_provider_win.h +++ b/chrome/browser/policy/configuration_policy_provider_win.h @@ -14,7 +14,11 @@ #include "chrome/browser/policy/configuration_policy_store.h" #include "chrome/browser/policy/configuration_policy_provider.h" +namespace base { +namespace win { class RegKey; +} // namespace win +} // namespace base namespace policy { @@ -99,8 +103,6 @@ class ConfigurationPolicyProviderWin // Reads a string registry value |name| at the specified |key| and puts the // resulting string in |result|. - bool ReadRegistryStringValue(RegKey* key, const string16& name, - string16* result); bool GetRegistryPolicyString(const string16& name, string16* result); // Gets a list value contained under |key| one level below the policy root. diff --git a/chrome/browser/policy/configuration_policy_provider_win_unittest.cc b/chrome/browser/policy/configuration_policy_provider_win_unittest.cc index 0dac818..f7a3524 100644 --- a/chrome/browser/policy/configuration_policy_provider_win_unittest.cc +++ b/chrome/browser/policy/configuration_policy_provider_win_unittest.cc @@ -6,12 +6,12 @@ #include -#include "base/registry.h" #include "base/scoped_ptr.h" #include "base/stl_util-inl.h" #include "base/string_number_conversions.h" #include "base/string_piece.h" #include "base/utf_string_conversions.h" +#include "base/win/registry.h" #include "chrome/browser/policy/configuration_policy_pref_store.h" #include "chrome/browser/policy/configuration_policy_provider_win.h" #include "chrome/browser/policy/mock_configuration_policy_store.h" @@ -19,6 +19,8 @@ #include "chrome/common/pref_names.h" #include "testing/gtest/include/gtest/gtest.h" +using base::win::RegKey; + namespace policy { const wchar_t kUnitTestRegistrySubKey[] = L"SOFTWARE\\Chromium Unit Tests"; diff --git a/chrome/browser/rlz/rlz_unittest.cc b/chrome/browser/rlz/rlz_unittest.cc index 8680de6..f2ca69f 100644 --- a/chrome/browser/rlz/rlz_unittest.cc +++ b/chrome/browser/rlz/rlz_unittest.cc @@ -4,11 +4,14 @@ #include "chrome/browser/rlz/rlz.h" -#include "base/registry.h" #include "base/path_service.h" +#include "base/win/registry.h" #include "testing/gtest/include/gtest/gtest.h" +using base::win::RegKey; + namespace { + // Gets rid of registry leftovers from testing. Returns false if there // is nothing to clean. bool CleanValue(const wchar_t* key_name, const wchar_t* value) { diff --git a/chrome/browser/shell_integration_win.cc b/chrome/browser/shell_integration_win.cc index 98e6729..2d53d28 100644 --- a/chrome/browser/shell_integration_win.cc +++ b/chrome/browser/shell_integration_win.cc @@ -13,12 +13,12 @@ #include "base/file_util.h" #include "base/message_loop.h" #include "base/path_service.h" -#include "base/registry.h" #include "base/scoped_comptr_win.h" #include "base/string_util.h" #include "base/task.h" #include "base/utf_string_conversions.h" #include "base/win_util.h" +#include "base/win/registry.h" #include "base/win/windows_version.h" #include "chrome/browser/browser_thread.h" #include "chrome/browser/web_applications/web_app.h" @@ -340,7 +340,7 @@ ShellIntegration::DefaultBrowserState ShellIntegration::IsDefaultBrowser() { HKEY root_key = HKEY_CLASSES_ROOT; // Check \shell\open\command std::wstring key_path(kChromeProtocols[i] + ShellUtil::kRegShellOpen); - RegKey key(root_key, key_path.c_str(), KEY_READ); + base::win::RegKey key(root_key, key_path.c_str(), KEY_READ); std::wstring value; if (!key.Valid() || !key.ReadValue(L"", &value)) return NOT_DEFAULT_BROWSER; @@ -371,14 +371,15 @@ bool ShellIntegration::IsFirefoxDefaultBrowser() { bool ff_default = false; if (base::win::GetVersion() >= base::win::VERSION_VISTA) { std::wstring app_cmd; - RegKey key(HKEY_CURRENT_USER, ShellUtil::kRegVistaUrlPrefs, KEY_READ); + base::win::RegKey key(HKEY_CURRENT_USER, + ShellUtil::kRegVistaUrlPrefs, KEY_READ); if (key.Valid() && key.ReadValue(L"Progid", &app_cmd) && app_cmd == L"FirefoxURL") ff_default = true; } else { std::wstring key_path(L"http"); key_path.append(ShellUtil::kRegShellOpen); - RegKey key(HKEY_CLASSES_ROOT, key_path.c_str(), KEY_READ); + base::win::RegKey key(HKEY_CLASSES_ROOT, key_path.c_str(), KEY_READ); std::wstring app_cmd; if (key.Valid() && key.ReadValue(L"", &app_cmd) && std::wstring::npos != StringToLowerASCII(app_cmd).find(L"firefox")) diff --git a/chrome/browser/views/external_protocol_dialog.cc b/chrome/browser/views/external_protocol_dialog.cc index 6dda2e3..3022c28 100644 --- a/chrome/browser/views/external_protocol_dialog.cc +++ b/chrome/browser/views/external_protocol_dialog.cc @@ -7,10 +7,10 @@ #include "app/l10n_util.h" #include "app/message_box_flags.h" #include "base/metrics/histogram.h" -#include "base/registry.h" #include "base/string_util.h" #include "base/thread.h" #include "base/utf_string_conversions.h" +#include "base/win/registry.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/external_protocol_handler.h" #include "chrome/browser/tab_contents/tab_contents.h" @@ -160,7 +160,7 @@ std::wstring ExternalProtocolDialog::GetApplicationForProtocol( std::wstring url_spec = ASCIIToWide(url.possibly_invalid_spec()); std::wstring cmd_key_path = ASCIIToWide(url.scheme() + "\\shell\\open\\command"); - RegKey cmd_key(HKEY_CLASSES_ROOT, cmd_key_path.c_str(), KEY_READ); + base::win::RegKey cmd_key(HKEY_CLASSES_ROOT, cmd_key_path.c_str(), KEY_READ); size_t split_offset = url_spec.find(L':'); if (split_offset == std::wstring::npos) return std::wstring(); diff --git a/chrome/browser/views/shell_dialogs_win.cc b/chrome/browser/views/shell_dialogs_win.cc index e8ec6e8..d3fe7ae 100644 --- a/chrome/browser/views/shell_dialogs_win.cc +++ b/chrome/browser/views/shell_dialogs_win.cc @@ -14,11 +14,11 @@ #include "app/l10n_util.h" #include "base/file_util.h" #include "base/message_loop.h" -#include "base/registry.h" #include "base/scoped_comptr_win.h" #include "base/string_split.h" #include "base/thread.h" #include "base/utf_string_conversions.h" +#include "base/win/registry.h" #include "base/win/windows_version.h" #include "chrome/browser/browser_thread.h" #include "gfx/font.h" @@ -49,7 +49,7 @@ std::wstring AppendExtensionIfNeeded(const std::wstring& filename, std::wstring file_extension(file_util::GetFileExtensionFromPath(filename)); std::wstring key(L"." + file_extension); if (!(filter_selected.empty() || filter_selected == L"*.*") && - !RegKey(HKEY_CLASSES_ROOT, key.c_str(), KEY_READ).Valid() && + !base::win::RegKey(HKEY_CLASSES_ROOT, key.c_str(), KEY_READ).Valid() && file_extension != suggested_ext) { if (return_value[return_value.length() - 1] != L'.') return_value.append(L"."); @@ -73,10 +73,10 @@ namespace { static bool GetRegistryDescriptionFromExtension(const std::wstring& file_ext, std::wstring* reg_description) { DCHECK(reg_description); - RegKey reg_ext(HKEY_CLASSES_ROOT, file_ext.c_str(), KEY_READ); + base::win::RegKey reg_ext(HKEY_CLASSES_ROOT, file_ext.c_str(), KEY_READ); std::wstring reg_app; if (reg_ext.ReadValue(NULL, ®_app) && !reg_app.empty()) { - RegKey reg_link(HKEY_CLASSES_ROOT, reg_app.c_str(), KEY_READ); + base::win::RegKey reg_link(HKEY_CLASSES_ROOT, reg_app.c_str(), KEY_READ); if (reg_link.ReadValue(NULL, reg_description)) return true; } diff --git a/chrome/common/chrome_plugin_lib.cc b/chrome/common/chrome_plugin_lib.cc index 5d1264b..f0dd8c1 100644 --- a/chrome/common/chrome_plugin_lib.cc +++ b/chrome/common/chrome_plugin_lib.cc @@ -12,7 +12,7 @@ #include "base/perftimer.h" #include "base/thread.h" #if defined(OS_WIN) -#include "base/registry.h" +#include "base/win/registry.h" #endif #include "base/string_util.h" #include "chrome/common/chrome_counters.h" @@ -149,7 +149,7 @@ void ChromePluginLib::LoadChromePlugins(const CPBrowserFuncs* bfuncs) { std::wstring reg_path = kRegistryChromePlugins; reg_path.append(L"\\"); reg_path.append(iter.Name()); - RegKey key(HKEY_CURRENT_USER, reg_path.c_str()); + base::win::RegKey key(HKEY_CURRENT_USER, reg_path.c_str()); DWORD is_persistent; if (key.ReadValueDW(kRegistryLoadOnStartup, &is_persistent) && diff --git a/chrome/installer/setup/install.cc b/chrome/installer/setup/install.cc index 04bca30..3a80634 100644 --- a/chrome/installer/setup/install.cc +++ b/chrome/installer/setup/install.cc @@ -2,17 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/installer/setup/install.h" + #include #include -#include "chrome/installer/setup/install.h" - #include "base/command_line.h" #include "base/file_util.h" #include "base/logging.h" #include "base/path_service.h" -#include "base/registry.h" #include "base/scoped_ptr.h" +#include "base/win/registry.h" #include "chrome/installer/setup/setup_constants.h" #include "chrome/installer/util/browser_distribution.h" #include "chrome/installer/util/create_reg_key_work_item.h" @@ -216,7 +216,7 @@ void DeleteUninstallShortcutsForMSI(bool is_system_install) { // First attempt to delete the old installation's ARP dialog entry. HKEY reg_root = is_system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; - RegKey root_key(reg_root, L"", KEY_ALL_ACCESS); + base::win::RegKey root_key(reg_root, L"", KEY_ALL_ACCESS); BrowserDistribution* dist = BrowserDistribution::GetDistribution(); std::wstring uninstall_reg = dist->GetUninstallRegPath(); InstallUtil::DeleteRegistryKey(root_key, uninstall_reg); @@ -604,7 +604,8 @@ installer_util::InstallStatus InstallNewVersion( std::wstring new_chrome_exe = AppendPath(install_path, installer_util::kChromeNewExe); BrowserDistribution* dist = BrowserDistribution::GetDistribution(); - RegKey chrome_key(reg_root, dist->GetVersionKey().c_str(), KEY_READ); + base::win::RegKey chrome_key(reg_root, dist->GetVersionKey().c_str(), + KEY_READ); if (file_util::PathExists(FilePath::FromWStringHack(new_chrome_exe))) chrome_key.ReadValue(google_update::kRegOldVersionField, current_version); if (current_version->empty()) diff --git a/chrome/installer/setup/uninstall.cc b/chrome/installer/setup/uninstall.cc index 9ab8aab..173aea9 100644 --- a/chrome/installer/setup/uninstall.cc +++ b/chrome/installer/setup/uninstall.cc @@ -8,10 +8,10 @@ #include "base/file_util.h" #include "base/path_service.h" -#include "base/registry.h" #include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" +#include "base/win/registry.h" #include "base/win/windows_version.h" #include "chrome/common/result_codes.h" #include "chrome/common/chrome_constants.h" @@ -30,6 +30,8 @@ // Build-time generated include file. #include "registered_dlls.h" // NOLINT +using base::win::RegKey; + namespace { // This functions checks for any Chrome instances that are diff --git a/chrome/installer/util/browser_distribution.cc b/chrome/installer/util/browser_distribution.cc index 4220005..baf7031 100644 --- a/chrome/installer/util/browser_distribution.cc +++ b/chrome/installer/util/browser_distribution.cc @@ -11,7 +11,7 @@ #include "base/command_line.h" #include "base/lock.h" -#include "base/registry.h" +#include "base/win/registry.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/env_vars.h" #include "chrome/installer/util/chrome_frame_distribution.h" @@ -122,7 +122,7 @@ std::wstring BrowserDistribution::GetStatsServerURL() { return L""; } -std::wstring BrowserDistribution::GetDistributionData(RegKey* key) { +std::wstring BrowserDistribution::GetDistributionData(base::win::RegKey* key) { return L""; } diff --git a/chrome/installer/util/browser_distribution.h b/chrome/installer/util/browser_distribution.h index e829969..39eecdd 100644 --- a/chrome/installer/util/browser_distribution.h +++ b/chrome/installer/util/browser_distribution.h @@ -12,7 +12,11 @@ #include "chrome/installer/util/util_constants.h" #include "chrome/installer/util/version.h" +namespace base { +namespace win { class RegKey; +} // namespace win +} // namespace base class BrowserDistribution { public: @@ -53,7 +57,7 @@ class BrowserDistribution { virtual std::wstring GetStatsServerURL(); - virtual std::wstring GetDistributionData(RegKey* key); + virtual std::wstring GetDistributionData(base::win::RegKey* key); virtual std::wstring GetUninstallLinkName(); diff --git a/chrome/installer/util/compat_checks.cc b/chrome/installer/util/compat_checks.cc index f84a27f..09eb0f2 100644 --- a/chrome/installer/util/compat_checks.cc +++ b/chrome/installer/util/compat_checks.cc @@ -4,10 +4,10 @@ #include "chrome/installer/util/compat_checks.h" -#include "base/registry.h" #include "base/string_number_conversions.h" #include "base/string_split.h" #include "base/string_util.h" +#include "base/win/registry.h" namespace { @@ -15,7 +15,7 @@ namespace { std::wstring GetSEPVersion() { const wchar_t kProductKey[] = L"SOFTWARE\\Symantec\\Symantec Endpoint Protection\\SMC"; - RegKey key(HKEY_LOCAL_MACHINE, kProductKey, KEY_READ); + base::win::RegKey key(HKEY_LOCAL_MACHINE, kProductKey, KEY_READ); std::wstring version_str; key.ReadValue(L"ProductVersion", &version_str); return version_str; diff --git a/chrome/installer/util/create_reg_key_work_item.cc b/chrome/installer/util/create_reg_key_work_item.cc index 4c1eb2c..6c4a2a0 100644 --- a/chrome/installer/util/create_reg_key_work_item.cc +++ b/chrome/installer/util/create_reg_key_work_item.cc @@ -6,11 +6,13 @@ #include "base/file_util.h" #include "base/logging.h" -#include "base/registry.h" +#include "base/win/registry.h" #include "chrome/installer/util/create_reg_key_work_item.h" #include "chrome/installer/util/install_util.h" #include "chrome/installer/util/logging_installer.h" +using base::win::RegKey; + namespace { // TODO: refactor this because it is only used once. diff --git a/chrome/installer/util/create_reg_key_work_item_unittest.cc b/chrome/installer/util/create_reg_key_work_item_unittest.cc index 4f8a9ee..c4f9d88 100644 --- a/chrome/installer/util/create_reg_key_work_item_unittest.cc +++ b/chrome/installer/util/create_reg_key_work_item_unittest.cc @@ -5,33 +5,38 @@ #include #include "base/file_util.h" -#include "base/registry.h" #include "base/scoped_ptr.h" #include "base/string_util.h" +#include "base/win/registry.h" #include "chrome/installer/util/create_reg_key_work_item.h" #include "chrome/installer/util/work_item.h" #include "testing/gtest/include/gtest/gtest.h" +using base::win::RegKey; + namespace { - wchar_t test_root[] = L"TmpTmp"; - class CreateRegKeyWorkItemTest : public testing::Test { - protected: - virtual void SetUp() { - // Create a temporary key for testing - RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); - key.DeleteKey(test_root); - ASSERT_FALSE(key.Open(HKEY_CURRENT_USER, test_root, KEY_READ)); - ASSERT_TRUE(key.Create(HKEY_CURRENT_USER, test_root, KEY_READ)); - } - virtual void TearDown() { - logging::CloseLogFile(); - // Clean up the temporary key - RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); - ASSERT_TRUE(key.DeleteKey(test_root)); - } - }; + +wchar_t test_root[] = L"TmpTmp"; + +class CreateRegKeyWorkItemTest : public testing::Test { + protected: + virtual void SetUp() { + // Create a temporary key for testing + RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); + key.DeleteKey(test_root); + ASSERT_FALSE(key.Open(HKEY_CURRENT_USER, test_root, KEY_READ)); + ASSERT_TRUE(key.Create(HKEY_CURRENT_USER, test_root, KEY_READ)); + } + virtual void TearDown() { + logging::CloseLogFile(); + // Clean up the temporary key + RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); + ASSERT_TRUE(key.DeleteKey(test_root)); + } }; +} // namespace + TEST_F(CreateRegKeyWorkItemTest, CreateKey) { RegKey key; diff --git a/chrome/installer/util/delete_after_reboot_helper.cc b/chrome/installer/util/delete_after_reboot_helper.cc index 6806f78..345ba01a 100644 --- a/chrome/installer/util/delete_after_reboot_helper.cc +++ b/chrome/installer/util/delete_after_reboot_helper.cc @@ -16,7 +16,7 @@ #include #include "base/file_util.h" -#include "base/registry.h" +#include "base/win/registry.h" #include "base/string_util.h" // The moves-pending-reboot is a MULTISZ registry key in the HKLM part of the @@ -245,8 +245,8 @@ HRESULT GetPendingMovesValue( // Get the current value of the key // If the Key is missing, that's totally acceptable. - RegKey session_manager_key(HKEY_LOCAL_MACHINE, kSessionManagerKey, - KEY_QUERY_VALUE); + base::win::RegKey session_manager_key(HKEY_LOCAL_MACHINE, kSessionManagerKey, + KEY_QUERY_VALUE); HKEY session_manager_handle = session_manager_key.Handle(); if (!session_manager_handle) { return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); @@ -351,8 +351,8 @@ bool RemoveFromMovesPendingReboot(const wchar_t* directory) { } // Write the key back into a buffer. - RegKey session_manager_key(HKEY_LOCAL_MACHINE, kSessionManagerKey, - KEY_CREATE_SUB_KEY | KEY_SET_VALUE); + base::win::RegKey session_manager_key(HKEY_LOCAL_MACHINE, kSessionManagerKey, + KEY_CREATE_SUB_KEY | KEY_SET_VALUE); if (!session_manager_key.Handle()) { // Couldn't open / create the key. LOG(ERROR) << "Failed to open session manager key for writing."; diff --git a/chrome/installer/util/delete_after_reboot_helper_unittest.cc b/chrome/installer/util/delete_after_reboot_helper_unittest.cc index 114825c..5d8adaf 100644 --- a/chrome/installer/util/delete_after_reboot_helper_unittest.cc +++ b/chrome/installer/util/delete_after_reboot_helper_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -6,9 +6,9 @@ #include #include "base/file_util.h" -#include "base/registry.h" #include "base/scoped_ptr.h" #include "base/string_util.h" +#include "base/win/registry.h" #include "chrome/installer/util/delete_after_reboot_helper.h" #include "testing/gtest/include/gtest/gtest.h" @@ -43,8 +43,9 @@ class DeleteAfterRebootHelperTest : public testing::Test { // Try and restore the pending moves value, if we have one. if (IsUserAnAdmin() && original_pending_moves_.size() > 1) { - RegKey session_manager_key(HKEY_LOCAL_MACHINE, kSessionManagerKey, - KEY_CREATE_SUB_KEY | KEY_SET_VALUE); + base::win::RegKey session_manager_key( + HKEY_LOCAL_MACHINE, kSessionManagerKey, + KEY_CREATE_SUB_KEY | KEY_SET_VALUE); if (!session_manager_key.Handle()) { // Couldn't open / create the key. DLOG(ERROR) << "Failed to open session manager key for writing."; diff --git a/chrome/installer/util/delete_reg_value_work_item.cc b/chrome/installer/util/delete_reg_value_work_item.cc index 7246d52..1c114e2 100644 --- a/chrome/installer/util/delete_reg_value_work_item.cc +++ b/chrome/installer/util/delete_reg_value_work_item.cc @@ -5,9 +5,11 @@ #include "chrome/installer/util/delete_reg_value_work_item.h" #include "base/logging.h" -#include "base/registry.h" +#include "base/win/registry.h" #include "chrome/installer/util/logging_installer.h" +using base::win::RegKey; + DeleteRegValueWorkItem::DeleteRegValueWorkItem(HKEY predefined_root, const std::wstring& key_path, const std::wstring& value_name, diff --git a/chrome/installer/util/delete_reg_value_work_item_unittest.cc b/chrome/installer/util/delete_reg_value_work_item_unittest.cc index c9d5783..fcec35c 100644 --- a/chrome/installer/util/delete_reg_value_work_item_unittest.cc +++ b/chrome/installer/util/delete_reg_value_work_item_unittest.cc @@ -1,37 +1,42 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// 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 #include "base/file_util.h" -#include "base/registry.h" #include "base/scoped_ptr.h" #include "base/string_util.h" +#include "base/win/registry.h" #include "chrome/installer/util/delete_reg_value_work_item.h" #include "chrome/installer/util/work_item.h" #include "testing/gtest/include/gtest/gtest.h" +using base::win::RegKey; + namespace { - wchar_t test_root[] = L"DeleteRegValueWorkItemTest"; - class DeleteRegValueWorkItemTest : public testing::Test { - protected: - virtual void SetUp() { - // Create a temporary key for testing - RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); - key.DeleteKey(test_root); - ASSERT_FALSE(key.Open(HKEY_CURRENT_USER, test_root, KEY_READ)); - ASSERT_TRUE(key.Create(HKEY_CURRENT_USER, test_root, KEY_READ)); - } - virtual void TearDown() { - logging::CloseLogFile(); - // Clean up the temporary key - RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); - ASSERT_TRUE(key.DeleteKey(test_root)); - } - }; + +wchar_t test_root[] = L"DeleteRegValueWorkItemTest"; + +class DeleteRegValueWorkItemTest : public testing::Test { + protected: + virtual void SetUp() { + // Create a temporary key for testing + RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); + key.DeleteKey(test_root); + ASSERT_FALSE(key.Open(HKEY_CURRENT_USER, test_root, KEY_READ)); + ASSERT_TRUE(key.Create(HKEY_CURRENT_USER, test_root, KEY_READ)); + } + virtual void TearDown() { + logging::CloseLogFile(); + // Clean up the temporary key + RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); + ASSERT_TRUE(key.DeleteKey(test_root)); + } }; +} // namespace + // Delete a value. The value should get deleted after Do() and should be // recreated after Rollback(). TEST_F(DeleteRegValueWorkItemTest, DeleteExistingValue) { diff --git a/chrome/installer/util/google_chrome_distribution.cc b/chrome/installer/util/google_chrome_distribution.cc index c0fc09dc..90c684c 100644 --- a/chrome/installer/util/google_chrome_distribution.cc +++ b/chrome/installer/util/google_chrome_distribution.cc @@ -16,11 +16,11 @@ #include "base/file_path.h" #include "base/path_service.h" #include "base/rand_util.h" -#include "base/registry.h" #include "base/scoped_ptr.h" #include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" +#include "base/win/registry.h" #include "base/win/windows_version.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/json_value_serializer.h" @@ -39,6 +39,7 @@ #pragma comment(lib, "wtsapi32.lib") namespace { + const wchar_t kChromeGuid[] = L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; const wchar_t kBrowserAppId[] = L"Chrome"; @@ -437,13 +438,14 @@ std::wstring GoogleChromeDistribution::GetStatsServerURL() { return L"https://clients4.google.com/firefox/metrics/collect"; } -std::wstring GoogleChromeDistribution::GetDistributionData(RegKey* key) { +std::wstring GoogleChromeDistribution::GetDistributionData( + base::win::RegKey* key) { DCHECK(NULL != key); std::wstring sub_key(google_update::kRegPathClientState); sub_key.append(L"\\"); sub_key.append(product_guid()); - RegKey client_state_key(key->Handle(), sub_key.c_str(), KEY_READ); + base::win::RegKey client_state_key(key->Handle(), sub_key.c_str(), KEY_READ); std::wstring result; std::wstring brand_value; if (client_state_key.ReadValue(google_update::kRegRLZBrandField, diff --git a/chrome/installer/util/google_chrome_distribution.h b/chrome/installer/util/google_chrome_distribution.h index a8eb493..53d754b 100644 --- a/chrome/installer/util/google_chrome_distribution.h +++ b/chrome/installer/util/google_chrome_distribution.h @@ -55,7 +55,7 @@ class GoogleChromeDistribution : public BrowserDistribution { // This method reads data from the Google Update ClientState key for // potential use in the uninstall survey. It must be called before the // key returned by GetVersionKey() is deleted. - virtual std::wstring GetDistributionData(RegKey* key); + virtual std::wstring GetDistributionData(base::win::RegKey* key); virtual std::wstring GetUninstallLinkName(); diff --git a/chrome/installer/util/google_chrome_distribution_dummy.cc b/chrome/installer/util/google_chrome_distribution_dummy.cc index b2cafe9..a50dd11 100644 --- a/chrome/installer/util/google_chrome_distribution_dummy.cc +++ b/chrome/installer/util/google_chrome_distribution_dummy.cc @@ -78,7 +78,8 @@ std::wstring GoogleChromeDistribution::GetStatsServerURL() { return std::wstring(); } -std::wstring GoogleChromeDistribution::GetDistributionData(RegKey* key) { +std::wstring GoogleChromeDistribution::GetDistributionData( + base::win::RegKey* key) { NOTREACHED(); return std::wstring(); } diff --git a/chrome/installer/util/google_update_settings.cc b/chrome/installer/util/google_update_settings.cc index 91867f3..747fbb1 100644 --- a/chrome/installer/util/google_update_settings.cc +++ b/chrome/installer/util/google_update_settings.cc @@ -7,15 +7,17 @@ #include #include "base/command_line.h" -#include "base/registry.h" #include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/time.h" +#include "base/win/registry.h" #include "chrome/common/chrome_switches.h" #include "chrome/installer/util/browser_distribution.h" #include "chrome/installer/util/google_update_constants.h" #include "chrome/installer/util/install_util.h" +using base::win::RegKey; + namespace { bool ReadGoogleUpdateStrKey(const wchar_t* const name, std::wstring* value) { diff --git a/chrome/installer/util/google_update_settings_unittest.cc b/chrome/installer/util/google_update_settings_unittest.cc index 5b5d1e2..75f15a8 100644 --- a/chrome/installer/util/google_update_settings_unittest.cc +++ b/chrome/installer/util/google_update_settings_unittest.cc @@ -5,14 +5,16 @@ #include #include // For SHDeleteKey. -#include "base/registry.h" #include "base/scoped_ptr.h" +#include "base/win/registry.h" #include "chrome/installer/util/browser_distribution.h" #include "chrome/installer/util/google_update_constants.h" #include "chrome/installer/util/google_update_settings.h" #include "chrome/installer/util/work_item_list.h" #include "testing/gtest/include/gtest/gtest.h" +using base::win::RegKey; + namespace { const wchar_t kHKCUReplacement[] = diff --git a/chrome/installer/util/install_util.cc b/chrome/installer/util/install_util.cc index a0dfad1..601d0eb 100644 --- a/chrome/installer/util/install_util.cc +++ b/chrome/installer/util/install_util.cc @@ -16,10 +16,10 @@ #include "base/file_util.h" #include "base/logging.h" #include "base/path_service.h" -#include "base/registry.h" #include "base/scoped_ptr.h" #include "base/string_util.h" #include "base/values.h" +#include "base/win/registry.h" #include "base/win/windows_version.h" #include "chrome/common/json_value_serializer.h" #include "chrome/installer/util/browser_distribution.h" @@ -29,6 +29,8 @@ #include "chrome/installer/util/util_constants.h" #include "chrome/installer/util/work_item_list.h" +using base::win::RegKey; + bool InstallUtil::ExecuteExeAsAdmin(const std::wstring& exe, const std::wstring& params, DWORD* exit_code) { diff --git a/chrome/installer/util/install_util.h b/chrome/installer/util/install_util.h index e72cf04..f33bfb6 100644 --- a/chrome/installer/util/install_util.h +++ b/chrome/installer/util/install_util.h @@ -19,7 +19,12 @@ #include "chrome/installer/util/version.h" class WorkItemList; + +namespace base { +namespace win { class RegKey; +} // namespace win +} // namespace base // This is a utility class that provides common installation related // utility methods that can be used by installer and also unit tested @@ -105,7 +110,8 @@ class InstallUtil { WorkItemList* registration_list); // Deletes the registry key at path key_path under the key given by root_key. - static bool DeleteRegistryKey(RegKey& root_key, const std::wstring& key_path); + static bool DeleteRegistryKey(base::win::RegKey& root_key, + const std::wstring& key_path); // Deletes the registry value named value_name at path key_path under the key // given by reg_root. diff --git a/chrome/installer/util/set_reg_value_work_item.cc b/chrome/installer/util/set_reg_value_work_item.cc index 0cf9129..0dae573 100644 --- a/chrome/installer/util/set_reg_value_work_item.cc +++ b/chrome/installer/util/set_reg_value_work_item.cc @@ -5,7 +5,7 @@ #include "chrome/installer/util/set_reg_value_work_item.h" #include "base/logging.h" -#include "base/registry.h" +#include "base/win/registry.h" #include "chrome/installer/util/logging_installer.h" SetRegValueWorkItem::~SetRegValueWorkItem() { @@ -49,7 +49,7 @@ bool SetRegValueWorkItem::Do() { return false; } - RegKey key; + base::win::RegKey key; if (!key.Open(predefined_root_, key_path_.c_str(), KEY_READ | KEY_SET_VALUE)) { LOG(ERROR) << "can not open " << key_path_; @@ -121,7 +121,7 @@ void SetRegValueWorkItem::Rollback() { return; } - RegKey key; + base::win::RegKey key; if (!key.Open(predefined_root_, key_path_.c_str(), KEY_READ | KEY_SET_VALUE)) { status_ = VALUE_ROLL_BACK; diff --git a/chrome/installer/util/set_reg_value_work_item_unittest.cc b/chrome/installer/util/set_reg_value_work_item_unittest.cc index 7e347e2..13faba5 100644 --- a/chrome/installer/util/set_reg_value_work_item_unittest.cc +++ b/chrome/installer/util/set_reg_value_work_item_unittest.cc @@ -5,37 +5,41 @@ #include #include "base/file_util.h" -#include "base/registry.h" #include "base/scoped_ptr.h" #include "base/string_util.h" +#include "base/win/registry.h" #include "chrome/installer/util/set_reg_value_work_item.h" #include "chrome/installer/util/work_item.h" #include "testing/gtest/include/gtest/gtest.h" +using base::win::RegKey; + namespace { - wchar_t test_root[] = L"TempTemp"; - wchar_t data_str_1[] = L"data_111"; - wchar_t data_str_2[] = L"data_222"; - DWORD dword1 = 0; - DWORD dword2 = 1; - class SetRegValueWorkItemTest : public testing::Test { - protected: - virtual void SetUp() { - // Create a temporary key for testing - RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); - key.DeleteKey(test_root); - ASSERT_FALSE(key.Open(HKEY_CURRENT_USER, test_root, KEY_READ)); - ASSERT_TRUE(key.Create(HKEY_CURRENT_USER, test_root, KEY_READ)); - } - virtual void TearDown() { - logging::CloseLogFile(); - // Clean up the temporary key - RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); - ASSERT_TRUE(key.DeleteKey(test_root)); - } - }; + +wchar_t test_root[] = L"TempTemp"; +wchar_t data_str_1[] = L"data_111"; +wchar_t data_str_2[] = L"data_222"; +DWORD dword1 = 0; +DWORD dword2 = 1; +class SetRegValueWorkItemTest : public testing::Test { + protected: + virtual void SetUp() { + // Create a temporary key for testing + RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); + key.DeleteKey(test_root); + ASSERT_FALSE(key.Open(HKEY_CURRENT_USER, test_root, KEY_READ)); + ASSERT_TRUE(key.Create(HKEY_CURRENT_USER, test_root, KEY_READ)); + } + virtual void TearDown() { + logging::CloseLogFile(); + // Clean up the temporary key + RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); + ASSERT_TRUE(key.DeleteKey(test_root)); + } }; +} // namespace + // Write a new value without overwrite flag. The value should be set. TEST_F(SetRegValueWorkItemTest, WriteNewNonOverwrite) { RegKey key; diff --git a/chrome/installer/util/shell_util.cc b/chrome/installer/util/shell_util.cc index 257a78f..212f04b 100644 --- a/chrome/installer/util/shell_util.cc +++ b/chrome/installer/util/shell_util.cc @@ -16,7 +16,6 @@ #include "base/file_path.h" #include "base/file_util.h" #include "base/logging.h" -#include "base/registry.h" #include "base/scoped_ptr.h" #include "base/stl_util-inl.h" #include "base/string_number_conversions.h" @@ -24,6 +23,7 @@ #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "base/values.h" +#include "base/win/registry.h" #include "base/win/windows_version.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" @@ -33,6 +33,8 @@ #include "installer_util_strings.h" +using base::win::RegKey; + namespace { // This class represents a single registry entry. The objective is to @@ -570,7 +572,8 @@ void ShellUtil::GetRegisteredBrowsers(std::map* browsers) { std::wstring base_key(ShellUtil::kRegStartMenuInternet); HKEY root = HKEY_LOCAL_MACHINE; - for (RegistryKeyIterator iter(root, base_key.c_str()); iter.Valid(); ++iter) { + for (base::win::RegistryKeyIterator iter(root, base_key.c_str()); + iter.Valid(); ++iter) { std::wstring key = base_key + L"\\" + iter.Name(); RegKey capabilities(root, (key + L"\\Capabilities").c_str(), KEY_READ); std::wstring name; diff --git a/chrome/installer/util/work_item_list_unittest.cc b/chrome/installer/util/work_item_list_unittest.cc index 8b91fcd..1ba6e52 100644 --- a/chrome/installer/util/work_item_list_unittest.cc +++ b/chrome/installer/util/work_item_list_unittest.cc @@ -7,49 +7,53 @@ #include "base/base_paths.h" #include "base/file_util.h" #include "base/path_service.h" -#include "base/registry.h" #include "base/scoped_ptr.h" #include "base/string_util.h" +#include "base/win/registry.h" #include "chrome/installer/util/work_item.h" #include "chrome/installer/util/work_item_list.h" #include "testing/gtest/include/gtest/gtest.h" +using base::win::RegKey; + namespace { - wchar_t test_root[] = L"ListList"; - wchar_t data_str[] = L"data_111"; - - class WorkItemListTest : public testing::Test { - protected: - virtual void SetUp() { - // Create a temporary key for testing - RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); - key.DeleteKey(test_root); - ASSERT_FALSE(key.Open(HKEY_CURRENT_USER, test_root, KEY_READ)); - ASSERT_TRUE(key.Create(HKEY_CURRENT_USER, test_root, KEY_READ)); - - // Create a temp directory for test. - ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_)); - test_dir_ = test_dir_.AppendASCII("WorkItemListTest"); - file_util::Delete(test_dir_, true); - ASSERT_FALSE(file_util::PathExists(test_dir_)); - file_util::CreateDirectoryW(test_dir_); - ASSERT_TRUE(file_util::PathExists(test_dir_)); - } - - virtual void TearDown() { - logging::CloseLogFile(); - // Clean up test directory - ASSERT_TRUE(file_util::Delete(test_dir_, true)); - ASSERT_FALSE(file_util::PathExists(test_dir_)); - // Clean up the temporary key - RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); - ASSERT_TRUE(key.DeleteKey(test_root)); - } - - FilePath test_dir_; - }; + +wchar_t test_root[] = L"ListList"; +wchar_t data_str[] = L"data_111"; + +class WorkItemListTest : public testing::Test { + protected: + virtual void SetUp() { + // Create a temporary key for testing + RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); + key.DeleteKey(test_root); + ASSERT_FALSE(key.Open(HKEY_CURRENT_USER, test_root, KEY_READ)); + ASSERT_TRUE(key.Create(HKEY_CURRENT_USER, test_root, KEY_READ)); + + // Create a temp directory for test. + ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_)); + test_dir_ = test_dir_.AppendASCII("WorkItemListTest"); + file_util::Delete(test_dir_, true); + ASSERT_FALSE(file_util::PathExists(test_dir_)); + file_util::CreateDirectoryW(test_dir_); + ASSERT_TRUE(file_util::PathExists(test_dir_)); + } + + virtual void TearDown() { + logging::CloseLogFile(); + // Clean up test directory + ASSERT_TRUE(file_util::Delete(test_dir_, true)); + ASSERT_FALSE(file_util::PathExists(test_dir_)); + // Clean up the temporary key + RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); + ASSERT_TRUE(key.DeleteKey(test_root)); + } + + FilePath test_dir_; }; +} // namespace + // Execute a WorkItem list successfully and then rollback. TEST_F(WorkItemListTest, ExecutionSuccess) { scoped_ptr work_item_list(WorkItem::CreateWorkItemList()); diff --git a/chrome/test/mini_installer_test/chrome_mini_installer.cc b/chrome/test/mini_installer_test/chrome_mini_installer.cc index e53b020..0d18716 100644 --- a/chrome/test/mini_installer_test/chrome_mini_installer.cc +++ b/chrome/test/mini_installer_test/chrome_mini_installer.cc @@ -10,15 +10,17 @@ #include "base/platform_thread.h" #include "base/process.h" #include "base/process_util.h" -#include "base/registry.h" #include "base/string_number_conversions.h" #include "base/string_util.h" +#include "base/win/registry.h" #include "chrome/installer/util/browser_distribution.h" #include "chrome/installer/util/google_update_constants.h" #include "chrome/test/mini_installer_test/mini_installer_test_constants.h" #include "chrome/test/mini_installer_test/mini_installer_test_util.h" #include "testing/gtest/include/gtest/gtest.h" +using base::win::RegKey; + ChromeMiniInstaller::ChromeMiniInstaller(const std::wstring& install_type, bool is_chrome_frame) : is_chrome_frame_(is_chrome_frame), diff --git a/chrome/test/plugin/plugin_test.cpp b/chrome/test/plugin/plugin_test.cpp index 0a9ca83..56d41aa 100644 --- a/chrome/test/plugin/plugin_test.cpp +++ b/chrome/test/plugin/plugin_test.cpp @@ -51,7 +51,7 @@ #include "webkit/glue/plugins/plugin_list.h" #if defined(OS_WIN) -#include "base/registry.h" +#include "base/win/registry.h" #endif class PluginTest : public UITest { @@ -80,7 +80,7 @@ class PluginTest : public UITest { if (strcmp(test_info->name(), "MediaPlayerNew") == 0) { // The installer adds our process names to the registry key below. Since // the installer might not have run on this machine, add it manually. - RegKey regkey; + base::win::RegKey regkey; if (regkey.Open(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\MediaPlayer\\ShimInclusionList", KEY_WRITE)) { diff --git a/chrome_frame/chrome_tab.cc b/chrome_frame/chrome_tab.cc index 013995d..b81be69 100644 --- a/chrome_frame/chrome_tab.cc +++ b/chrome_frame/chrome_tab.cc @@ -17,11 +17,11 @@ #include "base/logging.h" #include "base/logging_win.h" #include "base/path_service.h" -#include "base/registry.h" #include "base/string_number_conversions.h" #include "base/string_piece.h" #include "base/string_util.h" #include "base/sys_string_conversions.h" +#include "base/win/registry.h" #include "base/win/windows_version.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" @@ -40,6 +40,8 @@ #include "chrome_frame/utils.h" #include "googleurl/src/url_util.h" +using base::win::RegKey; + namespace { // This function has the side effect of initializing an unprotected // vector pointer inside GoogleUrl. If this is called during DLL loading, diff --git a/chrome_frame/crash_reporting/crash_metrics.cc b/chrome_frame/crash_reporting/crash_metrics.cc index 3a6c9ee..e5d8fb5 100644 --- a/chrome_frame/crash_reporting/crash_metrics.cc +++ b/chrome_frame/crash_reporting/crash_metrics.cc @@ -5,7 +5,7 @@ #include "chrome_frame/crash_reporting/crash_metrics.h" #include "base/metrics/histogram.h" -#include "base/registry.h" +#include "base/win/registry.h" #include "chrome_frame/utils.h" static const wchar_t kChromeFrameMetricsKey[] = @@ -28,7 +28,7 @@ CrashMetricsReporter* CrashMetricsReporter::GetInstance() { bool CrashMetricsReporter::SetMetric(Metric metric, int value) { DCHECK(metric >= NAVIGATION_COUNT && metric <= LAST_METRIC); - RegKey metric_key; + base::win::RegKey metric_key; if (metric_key.Create(HKEY_CURRENT_USER, kChromeFrameMetricsKey, KEY_SET_VALUE)) { if (metric_key.WriteValue(g_metric_names[metric], value)) { @@ -47,7 +47,7 @@ int CrashMetricsReporter::GetMetric(Metric metric) { DCHECK(metric >= NAVIGATION_COUNT && metric <= LAST_METRIC); int ret = 0; - RegKey metric_key; + base::win::RegKey metric_key; if (metric_key.Open(HKEY_CURRENT_USER, kChromeFrameMetricsKey, KEY_QUERY_VALUE)) { int value = 0; diff --git a/chrome_frame/policy_settings.cc b/chrome_frame/policy_settings.cc index 7e5be2c..d00e69a 100644 --- a/chrome_frame/policy_settings.cc +++ b/chrome_frame/policy_settings.cc @@ -5,9 +5,9 @@ #include "chrome_frame/policy_settings.h" #include "base/logging.h" -#include "base/registry.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" +#include "base/win/registry.h" #include "chrome/common/policy_constants.h" #include "chrome_frame/utils.h" @@ -45,7 +45,7 @@ void PolicySettings::RefreshFromRegistry() { default_renderer_ = RENDERER_NOT_SPECIFIED; renderer_exclusion_list_.clear(); - RegKey config_key; + base::win::RegKey config_key; DWORD value = RENDERER_NOT_SPECIFIED; HKEY root_key[] = { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER }; std::wstring settings_value( diff --git a/chrome_frame/test/chrome_frame_test_utils.cc b/chrome_frame/test/chrome_frame_test_utils.cc index e98d353..99fedd2 100644 --- a/chrome_frame/test/chrome_frame_test_utils.cc +++ b/chrome_frame/test/chrome_frame_test_utils.cc @@ -14,13 +14,13 @@ #include "base/file_version_info.h" #include "base/path_service.h" #include "base/process_util.h" -#include "base/registry.h" // to find IE and firefox #include "base/scoped_handle.h" #include "base/scoped_ptr.h" #include "base/string_util.h" #include "base/stringprintf.h" #include "base/utf_string_conversions.h" #include "base/win_util.h" +#include "base/win/registry.h" #include "base/win/windows_version.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_paths.h" @@ -116,7 +116,8 @@ std::wstring GetExecutableAppPath(const std::wstring& file) { L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\"; std::wstring app_path; - RegKey key(HKEY_LOCAL_MACHINE, (kAppPathsKey + file).c_str(), KEY_READ); + base::win::RegKey key(HKEY_LOCAL_MACHINE, (kAppPathsKey + file).c_str(), + KEY_READ); if (key.Handle()) { key.ReadValue(NULL, &app_path); } @@ -129,7 +130,7 @@ std::wstring FormatCommandForApp(const std::wstring& exe_name, std::wstring reg_path( base::StringPrintf(L"Applications\\%ls\\shell\\open\\command", exe_name.c_str())); - RegKey key(HKEY_CLASSES_ROOT, reg_path.c_str(), KEY_READ); + base::win::RegKey key(HKEY_CLASSES_ROOT, reg_path.c_str(), KEY_READ); std::wstring command; if (key.Handle()) { diff --git a/chrome_frame/test/perf/chrome_frame_perftest.cc b/chrome_frame/test/perf/chrome_frame_perftest.cc index 729f787..34c1183 100644 --- a/chrome_frame/test/perf/chrome_frame_perftest.cc +++ b/chrome_frame/test/perf/chrome_frame_perftest.cc @@ -17,7 +17,6 @@ #include "base/file_util.h" #include "base/path_service.h" #include "base/process_util.h" -#include "base/registry.h" #include "base/scoped_ptr.h" #include "base/scoped_bstr_win.h" #include "base/scoped_comptr_win.h" @@ -27,6 +26,7 @@ #include "base/time.h" #include "base/trace_event_win.h" #include "base/utf_string_conversions.h" +#include "base/win/registry.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths_internal.h" @@ -1092,7 +1092,7 @@ TEST_F(ChromeFrameCreationTest, PerfCold) { // from the cache. This could also fail if the Flash control is in use. // On Vista this could fail because of UAC TEST_F(FlashCreationTest, PerfCold) { - RegKey flash_key(HKEY_CLASSES_ROOT, kFlashControlKey, KEY_READ); + base::win::RegKey flash_key(HKEY_CLASSES_ROOT, kFlashControlKey, KEY_READ); std::wstring plugin_path; ASSERT_TRUE(flash_key.ReadValue(L"", &plugin_path)); @@ -1112,7 +1112,8 @@ TEST_F(FlashCreationTest, PerfCold) { // correctly causing the attempt to evict the dll from the system cache to // fail. TEST_F(SilverlightCreationTest, DISABLED_PerfCold) { - RegKey silverlight_key(HKEY_CLASSES_ROOT, kSilverlightControlKey, KEY_READ); + base::win::RegKey silverlight_key(HKEY_CLASSES_ROOT, kSilverlightControlKey, + KEY_READ); std::wstring plugin_path; ASSERT_TRUE(silverlight_key.ReadValue(L"", &plugin_path)); diff --git a/chrome_frame/test/policy_settings_unittest.cc b/chrome_frame/test/policy_settings_unittest.cc index a31e764..52a3c55 100644 --- a/chrome_frame/test/policy_settings_unittest.cc +++ b/chrome_frame/test/policy_settings_unittest.cc @@ -4,14 +4,16 @@ #include "base/basictypes.h" #include "base/logging.h" -#include "base/registry.h" #include "base/scoped_ptr.h" #include "base/stringprintf.h" #include "base/utf_string_conversions.h" +#include "base/win/registry.h" #include "chrome/common/policy_constants.h" #include "chrome_frame/policy_settings.h" #include "testing/gtest/include/gtest/gtest.h" +using base::win::RegKey; + namespace { // A best effort way to zap CF policy entries that may be in the registry. diff --git a/chrome_frame/test/util_unittests.cc b/chrome_frame/test/util_unittests.cc index 055bae9..bc18062 100644 --- a/chrome_frame/test/util_unittests.cc +++ b/chrome_frame/test/util_unittests.cc @@ -5,12 +5,14 @@ #include "base/file_path.h" #include "base/file_version_info.h" #include "base/file_version_info_win.h" -#include "base/registry.h" +#include "base/win/registry.h" #include "chrome_frame/utils.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/gmock/include/gmock/gmock.h" +using base::win::RegKey; + const wchar_t kChannelName[] = L"-dev"; const wchar_t kSuffix[] = L"-fix"; diff --git a/chrome_frame/utils.cc b/chrome_frame/utils.cc index ec631bd..4437668 100644 --- a/chrome_frame/utils.cc +++ b/chrome_frame/utils.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome_frame/utils.h" + #include #include #include @@ -14,7 +16,6 @@ #include "base/lazy_instance.h" #include "base/logging.h" #include "base/path_service.h" -#include "base/registry.h" #include "base/scoped_bstr_win.h" #include "base/scoped_comptr_win.h" #include "base/scoped_variant_win.h" @@ -24,6 +25,7 @@ #include "base/stringprintf.h" #include "base/thread_local.h" #include "base/utf_string_conversions.h" +#include "base/win/registry.h" #include "chrome/common/chrome_paths_internal.h" #include "chrome/common/url_constants.h" #include "chrome/installer/util/chrome_frame_distribution.h" @@ -31,14 +33,14 @@ #include "chrome_frame/html_utils.h" #include "chrome_frame/policy_settings.h" #include "chrome_frame/simple_resource_loader.h" -#include "chrome_frame/utils.h" #include "googleurl/src/gurl.h" #include "googleurl/src/url_canon.h" - #include "grit/chromium_strings.h" #include "net/base/escape.h" #include "net/http/http_util.h" +using base::win::RegKey; + // Note that these values are all lower case and are compared to // lower-case-transformed values. const wchar_t kMetaTag[] = L"meta"; @@ -754,7 +756,7 @@ RendererType RendererTypeForUrl(const std::wstring& url) { } bool match_found = false; - RegistryValueIterator url_list(config_key.Handle(), url_list_name); + base::win::RegistryValueIterator url_list(config_key.Handle(), url_list_name); while (!match_found && url_list.Valid()) { if (MatchPattern(url, url_list.Name())) { match_found = true; @@ -1518,7 +1520,7 @@ void WaitWithMessageLoop(HANDLE* handles, int count, DWORD timeout) { void EnumerateKeyValues(HKEY parent_key, const wchar_t* sub_key_name, std::vector* values) { DCHECK(values); - RegistryValueIterator url_list(parent_key, sub_key_name); + base::win::RegistryValueIterator url_list(parent_key, sub_key_name); while (url_list.Valid()) { values->push_back(url_list.Value()); ++url_list; diff --git a/net/base/platform_mime_util_win.cc b/net/base/platform_mime_util_win.cc index bffb81a..b93008b 100644 --- a/net/base/platform_mime_util_win.cc +++ b/net/base/platform_mime_util_win.cc @@ -6,8 +6,8 @@ #include "net/base/platform_mime_util.h" -#include "base/registry.h" #include "base/utf_string_conversions.h" +#include "base/win/registry.h" namespace net { @@ -16,8 +16,8 @@ bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension( // check windows registry for file extension's mime type (registry key // names are not case-sensitive). std::wstring value, key = L"." + ext; - RegKey(HKEY_CLASSES_ROOT, key.c_str(), KEY_READ).ReadValue(L"Content Type", - &value); + base::win::RegKey(HKEY_CLASSES_ROOT, key.c_str(), KEY_READ).ReadValue( + L"Content Type", &value); if (!value.empty()) { *result = WideToUTF8(value); return true; @@ -28,8 +28,8 @@ bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension( bool PlatformMimeUtil::GetPreferredExtensionForMimeType( const std::string& mime_type, FilePath::StringType* ext) const { std::wstring key(L"MIME\\Database\\Content Type\\" + UTF8ToWide(mime_type)); - if (!RegKey(HKEY_CLASSES_ROOT, key.c_str(), KEY_READ).ReadValue(L"Extension", - ext)) { + if (!base::win::RegKey(HKEY_CLASSES_ROOT, key.c_str(), KEY_READ).ReadValue( + L"Extension", ext)) { return false; } // Strip off the leading dot, this should always be the case. diff --git a/net/base/ssl_config_service_win.cc b/net/base/ssl_config_service_win.cc index 82f44bf..14c4d24 100644 --- a/net/base/ssl_config_service_win.cc +++ b/net/base/ssl_config_service_win.cc @@ -4,10 +4,11 @@ #include "net/base/ssl_config_service_win.h" -#include "base/registry.h" +#include "base/win/registry.h" using base::TimeDelta; using base::TimeTicks; +using base::win::RegKey; namespace net { diff --git a/net/proxy/proxy_config_service_win.cc b/net/proxy/proxy_config_service_win.cc index 1cd8a8c..d0a387f 100644 --- a/net/proxy/proxy_config_service_win.cc +++ b/net/proxy/proxy_config_service_win.cc @@ -8,11 +8,11 @@ #include #include "base/logging.h" -#include "base/registry.h" #include "base/scoped_ptr.h" #include "base/string_tokenizer.h" #include "base/string_util.h" #include "base/stl_util-inl.h" +#include "base/win/registry.h" #include "net/base/net_errors.h" #include "net/proxy/proxy_config.h" @@ -61,7 +61,7 @@ class ProxyConfigServiceWin::KeyEntry { } private: - RegKey key_; + base::win::RegKey key_; base::ObjectWatcher watcher_; }; diff --git a/sandbox/src/eat_resolver.cc b/sandbox/src/eat_resolver.cc index d4f6e83..f057006 100644 --- a/sandbox/src/eat_resolver.cc +++ b/sandbox/src/eat_resolver.cc @@ -4,7 +4,7 @@ #include "sandbox/src/eat_resolver.h" -#include "base/pe_image.h" +#include "base/win/pe_image.h" #include "sandbox/src/sandbox_nt_util.h" namespace sandbox { @@ -64,7 +64,7 @@ NTSTATUS EatResolverThunk::ResolveTarget(const void* module, if (!module) return STATUS_INVALID_PARAMETER; - PEImage pe(module); + base::win::PEImage pe(module); if (!pe.VerifyMagic()) return STATUS_INVALID_IMAGE_FORMAT; diff --git a/sandbox/src/interception.cc b/sandbox/src/interception.cc index 28edf2c..003ebd8 100644 --- a/sandbox/src/interception.cc +++ b/sandbox/src/interception.cc @@ -10,8 +10,8 @@ #include "sandbox/src/interception.h" #include "base/logging.h" -#include "base/pe_image.h" #include "base/scoped_ptr.h" +#include "base/win/pe_image.h" #include "sandbox/src/interception_internal.h" #include "sandbox/src/interceptors.h" #include "sandbox/src/sandbox.h" @@ -411,7 +411,7 @@ bool InterceptionManager::PatchClientFunctions(DllInterceptionData* thunks, if (!ntdll_base) return false; - PEImage ntdll_image(ntdll_base); + base::win::PEImage ntdll_image(ntdll_base); // Bypass purify's interception. wchar_t* loader_get = reinterpret_cast( diff --git a/sandbox/src/policy_broker.cc b/sandbox/src/policy_broker.cc index ff67667..0a63750 100644 --- a/sandbox/src/policy_broker.cc +++ b/sandbox/src/policy_broker.cc @@ -7,7 +7,7 @@ #include "sandbox/src/policy_broker.h" #include "base/logging.h" -#include "base/pe_image.h" +#include "base/win/pe_image.h" #include "base/win/windows_version.h" #include "sandbox/src/interception.h" #include "sandbox/src/interceptors.h" @@ -41,7 +41,7 @@ SANDBOX_INTERCEPT NtExports g_nt; bool SetupNtdllImports(TargetProcess *child) { HMODULE ntdll = ::GetModuleHandle(kNtdllName); - PEImage ntdll_image(ntdll); + base::win::PEImage ntdll_image(ntdll); // Bypass purify's interception. wchar_t* loader_get = reinterpret_cast( diff --git a/sandbox/src/resolver.cc b/sandbox/src/resolver.cc index 7ed02e4..295bfb2 100644 --- a/sandbox/src/resolver.cc +++ b/sandbox/src/resolver.cc @@ -4,7 +4,7 @@ #include "sandbox/src/resolver.h" -#include "base/pe_image.h" +#include "base/win/pe_image.h" #include "sandbox/src/sandbox_nt_util.h" namespace sandbox { @@ -47,7 +47,7 @@ NTSTATUS ResolverThunk::ResolveInterceptor(const void* interceptor_module, if (!interceptor_module) return STATUS_INVALID_PARAMETER; - PEImage pe(interceptor_module); + base::win::PEImage pe(interceptor_module); if (!pe.VerifyMagic()) return STATUS_INVALID_IMAGE_FORMAT; diff --git a/sandbox/src/sandbox_nt_util.cc b/sandbox/src/sandbox_nt_util.cc index 89da4e0..20035b3 100644 --- a/sandbox/src/sandbox_nt_util.cc +++ b/sandbox/src/sandbox_nt_util.cc @@ -4,7 +4,7 @@ #include "sandbox/src/sandbox_nt_util.h" -#include "base/pe_image.h" +#include "base/win/pe_image.h" #include "sandbox/src/sandbox_factory.h" #include "sandbox/src/target_services.h" @@ -357,7 +357,7 @@ UNICODE_STRING* GetImageInfoFromModule(HMODULE module, uint32* flags) { __try { do { *flags = 0; - PEImage pe(module); + base::win::PEImage pe(module); if (!pe.VerifyMagic()) break; diff --git a/sandbox/src/service_resolver.cc b/sandbox/src/service_resolver.cc index 728555e..79579a0 100644 --- a/sandbox/src/service_resolver.cc +++ b/sandbox/src/service_resolver.cc @@ -5,7 +5,7 @@ #include "sandbox/src/service_resolver.h" #include "base/logging.h" -#include "base/pe_image.h" +#include "base/win/pe_image.h" namespace sandbox { @@ -28,7 +28,7 @@ NTSTATUS ServiceResolverThunk::ResolveTarget(const void* module, if (NULL == module) return STATUS_UNSUCCESSFUL; - PEImage module_image(module); + base::win::PEImage module_image(module); *address = module_image.GetProcAddress(function_name); if (NULL == *address) { diff --git a/sandbox/src/sidestep_resolver.cc b/sandbox/src/sidestep_resolver.cc index 74409a8..0a2803c 100644 --- a/sandbox/src/sidestep_resolver.cc +++ b/sandbox/src/sidestep_resolver.cc @@ -4,7 +4,7 @@ #include "sandbox/src/sidestep_resolver.h" -#include "base/pe_image.h" +#include "base/win/pe_image.h" #include "sandbox/src/sandbox_nt_util.h" #include "sandbox/src/sidestep/preamble_patcher.h" @@ -191,7 +191,7 @@ bool SmartSidestepResolverThunk::IsInternalCall(const void* base, DCHECK_NT(base); DCHECK_NT(return_address); - PEImage pe(base); + base::win::PEImage pe(base); if (pe.GetImageSectionFromAddr(return_address)) return true; return false; diff --git a/sandbox/src/target_process.cc b/sandbox/src/target_process.cc index a9848c5..1341949 100644 --- a/sandbox/src/target_process.cc +++ b/sandbox/src/target_process.cc @@ -5,8 +5,8 @@ #include "sandbox/src/target_process.h" #include "base/basictypes.h" -#include "base/pe_image.h" #include "base/scoped_ptr.h" +#include "base/win/pe_image.h" #include "sandbox/src/crosscall_server.h" #include "sandbox/src/crosscall_client.h" #include "sandbox/src/policy_low_level.h" @@ -54,7 +54,7 @@ void* GetBaseAddress(const wchar_t* exe_name, void* entry_point) { if (NULL == exe) return exe; - PEImage pe(exe); + base::win::PEImage pe(exe); if (!pe.VerifyMagic()) { ::FreeLibrary(exe); return exe; diff --git a/webkit/glue/plugins/plugin_list_win.cc b/webkit/glue/plugins/plugin_list_win.cc index e515e10..4869262 100644 --- a/webkit/glue/plugins/plugin_list_win.cc +++ b/webkit/glue/plugins/plugin_list_win.cc @@ -12,11 +12,11 @@ #include "base/command_line.h" #include "base/file_util.h" #include "base/path_service.h" -#include "base/registry.h" #include "base/scoped_ptr.h" #include "base/string_number_conversions.h" #include "base/string_split.h" #include "base/string_util.h" +#include "base/win/registry.h" #include "webkit/glue/plugins/plugin_constants_win.h" #include "webkit/glue/plugins/plugin_lib.h" #include "webkit/glue/webkit_glue.h" @@ -67,7 +67,7 @@ bool GetInstalledPath(const TCHAR* app, FilePath* out) { reg_path.append(L"\\"); reg_path.append(app); - RegKey key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ); + base::win::RegKey key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ); std::wstring path; if (key.ReadValue(kRegistryPath, &path)) { *out = FilePath(path); @@ -82,13 +82,13 @@ void GetPluginsInRegistryDirectory( HKEY root_key, const std::wstring& registry_folder, std::set* plugin_dirs) { - for (RegistryKeyIterator iter(root_key, registry_folder.c_str()); + for (base::win::RegistryKeyIterator iter(root_key, registry_folder.c_str()); iter.Valid(); ++iter) { // Use the registry to gather plugin across the file system. std::wstring reg_path = registry_folder; reg_path.append(L"\\"); reg_path.append(iter.Name()); - RegKey key(root_key, reg_path.c_str(), KEY_READ); + base::win::RegKey key(root_key, reg_path.c_str(), KEY_READ); std::wstring path; if (key.ReadValue(kRegistryPath, &path)) @@ -99,11 +99,12 @@ void GetPluginsInRegistryDirectory( // Enumerate through the registry key to find all installed FireFox paths. // FireFox 3 beta and version 2 can coexist. See bug: 1025003 void GetFirefoxInstalledPaths(std::vector* out) { - RegistryKeyIterator it(HKEY_LOCAL_MACHINE, kRegistryFirefoxInstalled); + base::win::RegistryKeyIterator it(HKEY_LOCAL_MACHINE, + kRegistryFirefoxInstalled); for (; it.Valid(); ++it) { std::wstring full_path = std::wstring(kRegistryFirefoxInstalled) + L"\\" + it.Name() + L"\\Main"; - RegKey key(HKEY_LOCAL_MACHINE, full_path.c_str(), KEY_READ); + base::win::RegKey key(HKEY_LOCAL_MACHINE, full_path.c_str(), KEY_READ); std::wstring install_dir; if (!key.ReadValue(L"Install Directory", &install_dir)) continue; @@ -180,7 +181,8 @@ void GetWindowsMediaDirectory(std::set* plugin_dirs) { void GetJavaDirectory(std::set* plugin_dirs) { // Load the new NPAPI Java plugin // 1. Open the main JRE key under HKLM - RegKey java_key(HKEY_LOCAL_MACHINE, kRegistryJava, KEY_QUERY_VALUE); + base::win::RegKey java_key(HKEY_LOCAL_MACHINE, kRegistryJava, + KEY_QUERY_VALUE); // 2. Read the current Java version std::wstring java_version; diff --git a/webkit/glue/plugins/webplugin_delegate_impl_win.cc b/webkit/glue/plugins/webplugin_delegate_impl_win.cc index 867727f..da7a68f 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl_win.cc +++ b/webkit/glue/plugins/webplugin_delegate_impl_win.cc @@ -13,12 +13,12 @@ #include "base/lazy_instance.h" #include "base/message_loop.h" #include "base/metrics/stats_counters.h" -#include "base/registry.h" #include "base/scoped_ptr.h" #include "base/string_number_conversions.h" #include "base/string_split.h" #include "base/string_util.h" #include "base/stringprintf.h" +#include "base/win/registry.h" #include "base/win/windows_version.h" #include "skia/ext/platform_canvas.h" #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" @@ -416,7 +416,7 @@ bool WebPluginDelegateImpl::PlatformInitialize() { // for the rest patch this function. if ((quirks_ & PLUGIN_QUIRK_PATCH_REGENUMKEYEXW) && base::win::GetVersion() == base::win::VERSION_XP && - !RegKey().Open(HKEY_LOCAL_MACHINE, + !base::win::RegKey().Open(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\MediaPlayer\\ShimInclusionList\\chrome.exe", KEY_READ) && !g_iat_patch_reg_enum_key_ex_w.Pointer()->is_patched()) { -- cgit v1.1