summaryrefslogtreecommitdiffstats
path: root/sandbox/win
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-22 03:42:01 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-22 03:42:01 +0000
commit00b8ae882e96f41c41c27d3070897f02dd75d30b (patch)
tree97229d0caa31bb658e45d3bd1fb9bd6771a3c8a5 /sandbox/win
parent4f5f7561b68b66ebd906e862175d44d12eff91b1 (diff)
downloadchromium_src-00b8ae882e96f41c41c27d3070897f02dd75d30b.zip
chromium_src-00b8ae882e96f41c41c27d3070897f02dd75d30b.tar.gz
chromium_src-00b8ae882e96f41c41c27d3070897f02dd75d30b.tar.bz2
Remove GetModuleHandleHelper(), which was only needed for Win2k (which we don't support).
BUG=none TEST=none Review URL: https://codereview.chromium.org/10951038 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@158165 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sandbox/win')
-rw-r--r--sandbox/win/src/interception.cc6
-rw-r--r--sandbox/win/src/policy_broker.cc7
-rw-r--r--sandbox/win/src/sandbox_utils.cc49
-rw-r--r--sandbox/win/src/sandbox_utils.h21
-rw-r--r--sandbox/win/src/service_resolver_32.cc18
-rw-r--r--sandbox/win/tests/common/controller.cc8
6 files changed, 26 insertions, 83 deletions
diff --git a/sandbox/win/src/interception.cc b/sandbox/win/src/interception.cc
index d8c5b36..8def6e8 100644
--- a/sandbox/win/src/interception.cc
+++ b/sandbox/win/src/interception.cc
@@ -453,9 +453,9 @@ bool InterceptionManager::PatchClientFunctions(DllInterceptionData* thunks,
wchar_t* loader_get = reinterpret_cast<wchar_t*>(
ntdll_image.GetProcAddress("LdrGetDllHandle"));
if (loader_get) {
- if (!GetModuleHandleHelper(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
- GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
- loader_get, &ntdll_base))
+ if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
+ GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+ loader_get, &ntdll_base))
return false;
}
diff --git a/sandbox/win/src/policy_broker.cc b/sandbox/win/src/policy_broker.cc
index e36c343..fbe4619 100644
--- a/sandbox/win/src/policy_broker.cc
+++ b/sandbox/win/src/policy_broker.cc
@@ -16,7 +16,6 @@
#include "sandbox/win/src/sandbox.h"
#include "sandbox/win/src/sandbox_nt_types.h"
#include "sandbox/win/src/sandbox_types.h"
-#include "sandbox/win/src/sandbox_utils.h"
#include "sandbox/win/src/target_process.h"
// This code executes on the broker side, as a callback from the policy on the
@@ -47,9 +46,9 @@ bool SetupNtdllImports(TargetProcess *child) {
wchar_t* loader_get = reinterpret_cast<wchar_t*>(
ntdll_image.GetProcAddress("LdrGetDllHandle"));
if (loader_get) {
- GetModuleHandleHelper(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
- GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
- loader_get, &ntdll);
+ GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
+ GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+ loader_get, &ntdll);
}
INIT_GLOBAL_NT(AllocateVirtualMemory);
diff --git a/sandbox/win/src/sandbox_utils.cc b/sandbox/win/src/sandbox_utils.cc
index 3aeb6a0..f4511a4 100644
--- a/sandbox/win/src/sandbox_utils.cc
+++ b/sandbox/win/src/sandbox_utils.cc
@@ -9,51 +9,9 @@
#include "base/logging.h"
#include "base/win/windows_version.h"
#include "sandbox/win/src/internal_types.h"
-#include "sandbox/win/src/nt_internals.h"
namespace sandbox {
-bool GetModuleHandleHelper(DWORD flags, const wchar_t* module_name,
- HMODULE* module) {
- DCHECK(module);
-
- HMODULE kernel32_base = ::GetModuleHandle(kKerneldllName);
- if (!kernel32_base) {
- NOTREACHED();
- return false;
- }
-
- GetModuleHandleExFunction get_module_handle_ex = reinterpret_cast<
- GetModuleHandleExFunction>(::GetProcAddress(kernel32_base,
- "GetModuleHandleExW"));
- if (get_module_handle_ex)
- return (get_module_handle_ex(flags, module_name, module) != FALSE);
-
- if (!flags) {
- *module = ::LoadLibrary(module_name);
- } else if (flags & GET_MODULE_HANDLE_EX_FLAG_PIN) {
- NOTREACHED();
- return false;
- } else if (!(flags & GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS)) {
- DCHECK((flags & GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT) ==
- GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT);
-
- *module = ::GetModuleHandle(module_name);
- } else {
- DCHECK((flags & (GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT |
- GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS)) ==
- (GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT |
- GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS));
-
- MEMORY_BASIC_INFORMATION info = {0};
- size_t returned = VirtualQuery(module_name, &info, sizeof(info));
- if (sizeof(info) != returned)
- return false;
- *module = reinterpret_cast<HMODULE>(info.AllocationBase);
- }
- return true;
-}
-
bool IsXPSP2OrLater() {
base::win::Version version = base::win::GetVersion();
return (version > base::win::VERSION_XP) ||
@@ -61,8 +19,11 @@ bool IsXPSP2OrLater() {
(base::win::OSInfo::GetInstance()->service_pack().major >= 2));
}
-void InitObjectAttribs(const std::wstring& name, ULONG attributes, HANDLE root,
- OBJECT_ATTRIBUTES* obj_attr, UNICODE_STRING* uni_name) {
+void InitObjectAttribs(const std::wstring& name,
+ ULONG attributes,
+ HANDLE root,
+ OBJECT_ATTRIBUTES* obj_attr,
+ UNICODE_STRING* uni_name) {
static RtlInitUnicodeStringFunction RtlInitUnicodeString;
if (!RtlInitUnicodeString) {
HMODULE ntdll = ::GetModuleHandle(kNtdllName);
diff --git a/sandbox/win/src/sandbox_utils.h b/sandbox/win/src/sandbox_utils.h
index 8329698..78e76fb 100644
--- a/sandbox/win/src/sandbox_utils.h
+++ b/sandbox/win/src/sandbox_utils.h
@@ -13,25 +13,14 @@
namespace sandbox {
-typedef BOOL (WINAPI* GetModuleHandleExFunction)(DWORD flags,
- LPCWSTR module_name,
- HMODULE* module);
-
-// Windows XP provides a nice function in kernel32.dll called GetModuleHandleEx
-// This function allows us to verify if a function exported by the module
-// lies in the module itself.
-// As we need compatibility with windows 2000, we cannot use this function
-// by calling it by name. This helper function checks if the GetModuleHandleEx
-// function is exported by kernel32 and uses it, otherwise, implemets part of
-// the functionality exposed by GetModuleHandleEx.
-bool GetModuleHandleHelper(DWORD flags, const wchar_t* module_name,
- HMODULE* module);
-
// Returns true if the current OS is Windows XP SP2 or later.
bool IsXPSP2OrLater();
-void InitObjectAttribs(const std::wstring& name, ULONG attributes, HANDLE root,
- OBJECT_ATTRIBUTES* obj_attr, UNICODE_STRING* uni_name);
+void InitObjectAttribs(const std::wstring& name,
+ ULONG attributes,
+ HANDLE root,
+ OBJECT_ATTRIBUTES* obj_attr,
+ UNICODE_STRING* uni_name);
}; // namespace sandbox
diff --git a/sandbox/win/src/service_resolver_32.cc b/sandbox/win/src/service_resolver_32.cc
index d4d2048..3497516 100644
--- a/sandbox/win/src/service_resolver_32.cc
+++ b/sandbox/win/src/service_resolver_32.cc
@@ -5,7 +5,6 @@
#include "sandbox/win/src/service_resolver.h"
#include "base/memory/scoped_ptr.h"
-#include "sandbox/win/src/sandbox_utils.h"
#include "sandbox/win/src/win_utils.h"
namespace {
@@ -210,10 +209,9 @@ bool ServiceResolverThunk::IsFunctionAService(void* local_thunk) const {
HMODULE module_1, module_2;
// last check, call_stub should point to a KiXXSystemCall function on ntdll
- if (!GetModuleHandleHelper(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
- GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
- bit_cast<const wchar_t*>(ki_system_call),
- &module_1))
+ if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
+ GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+ bit_cast<const wchar_t*>(ki_system_call), &module_1))
return false;
if (NULL != ntdll_base_) {
@@ -221,13 +219,11 @@ bool ServiceResolverThunk::IsFunctionAService(void* local_thunk) const {
// able to patch a buffer in memory, so target_ is not inside ntdll.
module_2 = ntdll_base_;
} else {
- if (!GetModuleHandleHelper(
- GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
- GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
- reinterpret_cast<const wchar_t*>(target_),
- &module_2)) {
+ if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
+ GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+ reinterpret_cast<const wchar_t*>(target_),
+ &module_2))
return false;
- }
}
if (module_1 != module_2)
diff --git a/sandbox/win/tests/common/controller.cc b/sandbox/win/tests/common/controller.cc
index 33dd776..921ce12 100644
--- a/sandbox/win/tests/common/controller.cc
+++ b/sandbox/win/tests/common/controller.cc
@@ -11,7 +11,6 @@
#include "base/sys_string_conversions.h"
#include "base/win/windows_version.h"
#include "sandbox/win/src/sandbox_factory.h"
-#include "sandbox/win/src/sandbox_utils.h"
namespace {
@@ -300,10 +299,9 @@ int DispatchCall(int argc, wchar_t **argv) {
return SBOX_TEST_INVALID_PARAMETER;
HMODULE module;
- if (!GetModuleHandleHelper(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
- GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
- reinterpret_cast<wchar_t*>(&DispatchCall),
- &module))
+ if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
+ GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+ reinterpret_cast<wchar_t*>(&DispatchCall), &module))
return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND;
std::string command_name = base::SysWideToMultiByte(argv[3], CP_UTF8);