summaryrefslogtreecommitdiffstats
path: root/base/win/iat_patch_function.h
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-25 12:18:51 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-25 12:18:51 +0000
commitdcd5776135982012e99ea7b7030b3412f61235c7 (patch)
tree2853a787d4c09e4a8417a0c74a312917a05dce08 /base/win/iat_patch_function.h
parent05ba8b8dd541632486513221795d45e4fe71b47f (diff)
downloadchromium_src-dcd5776135982012e99ea7b7030b3412f61235c7.zip
chromium_src-dcd5776135982012e99ea7b7030b3412f61235c7.tar.gz
chromium_src-dcd5776135982012e99ea7b7030b3412f61235c7.tar.bz2
Reland "Move app/win/* files to base/win/, ui/base/win and chrome/common/ directories."
The issue with the r90464 was that in the win shared build we build dlls and we need BASE_API to export functions and symbols. BUG=72317 TEST=None TBR=rsesek@chromium.org,brettw@chromium.org Review URL: http://codereview.chromium.org/7263009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90505 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/win/iat_patch_function.h')
-rw-r--r--base/win/iat_patch_function.h73
1 files changed, 73 insertions, 0 deletions
diff --git a/base/win/iat_patch_function.h b/base/win/iat_patch_function.h
new file mode 100644
index 0000000..3f9acc7
--- /dev/null
+++ b/base/win/iat_patch_function.h
@@ -0,0 +1,73 @@
+// Copyright (c) 2011 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_IAT_PATCH_FUNCTION_H_
+#define BASE_WIN_IAT_PATCH_FUNCTION_H_
+#pragma once
+
+#include <windows.h>
+
+#include "base/base_api.h"
+#include "base/basictypes.h"
+
+namespace base {
+namespace win {
+
+// A class that encapsulates Import Address Table patching helpers and restores
+// the original function in the destructor.
+//
+// It will intercept functions for a specific DLL imported from another DLL.
+// This is the case when, for example, we want to intercept
+// CertDuplicateCertificateContext function (exported from crypt32.dll) called
+// by wininet.dll.
+class BASE_API IATPatchFunction {
+ public:
+ IATPatchFunction();
+ ~IATPatchFunction();
+
+ // Intercept a function in an import table of a specific
+ // module. Save the original function and the import
+ // table address. These values will be used later
+ // during Unpatch
+ //
+ // Arguments:
+ // module Module to be intercepted
+ // imported_from_module Module that exports the 'function_name'
+ // function_name Name of the API to be intercepted
+ //
+ // Returns: Windows error code (winerror.h). NO_ERROR if successful
+ //
+ // Note: Patching a function will make the IAT patch take some "ownership" on
+ // |module|. It will LoadLibrary(module) to keep the DLL alive until a call
+ // to Unpatch(), which will call FreeLibrary() and allow the module to be
+ // unloaded. The idea is to help prevent the DLL from going away while a
+ // patch is still active.
+ DWORD Patch(const wchar_t* module,
+ const char* imported_from_module,
+ const char* function_name,
+ void* new_function);
+
+ // Unpatch the IAT entry using internally saved original
+ // function.
+ //
+ // Returns: Windows error code (winerror.h). NO_ERROR if successful
+ DWORD Unpatch();
+
+ bool is_patched() const {
+ return (NULL != intercept_function_);
+ }
+
+ private:
+ HMODULE module_handle_;
+ void* intercept_function_;
+ void* original_function_;
+ IMAGE_THUNK_DATA* iat_thunk_;
+
+ DISALLOW_COPY_AND_ASSIGN(IATPatchFunction);
+};
+
+} // namespace win
+} // namespace base
+
+#endif // BASE_WIN_IAT_PATCH_FUNCTION_H_