| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file declares a helpers to intercept functions from a DLL. | 5 // This file declares a helpers to intercept functions from a DLL. |
| 6 // | 6 // |
| 7 // This set of functions are designed to intercept functions for a | 7 // This set of functions are designed to intercept functions for a |
| 8 // specific DLL imported from another DLL. This is the case when, | 8 // specific DLL imported from another DLL. This is the case when, |
| 9 // for example, we want to intercept CertDuplicateCertificateContext | 9 // for example, we want to intercept CertDuplicateCertificateContext |
| 10 // function (exported from crypt32.dll) called by wininet.dll. | 10 // function (exported from crypt32.dll) called by wininet.dll. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 public: | 73 public: |
| 74 IATPatchFunction(); | 74 IATPatchFunction(); |
| 75 ~IATPatchFunction(); | 75 ~IATPatchFunction(); |
| 76 | 76 |
| 77 // Intercept a function in an import table of a specific | 77 // Intercept a function in an import table of a specific |
| 78 // module. Save the original function and the import | 78 // module. Save the original function and the import |
| 79 // table address. These values will be used later | 79 // table address. These values will be used later |
| 80 // during Unpatch | 80 // during Unpatch |
| 81 // | 81 // |
| 82 // Arguments: | 82 // Arguments: |
| 83 // module_handle Module to be intercepted | 83 // module Module to be intercepted |
| 84 // imported_from_module Module that exports the 'function_name' | 84 // imported_from_module Module that exports the 'function_name' |
| 85 // function_name Name of the API to be intercepted | 85 // function_name Name of the API to be intercepted |
| 86 // | 86 // |
| 87 // Returns: Windows error code (winerror.h). NO_ERROR if successful | 87 // Returns: Windows error code (winerror.h). NO_ERROR if successful |
| 88 // | 88 // |
| 89 DWORD Patch(HMODULE module_handle, | 89 // Note: Patching a function will make the IAT patch take some "ownership" on |
| 90 // |module|. It will LoadLibrary(module) to keep the DLL alive until a call |
| 91 // to Unpatch(), which will call FreeLibrary() and allow the module to be |
| 92 // unloaded. The idea is to help prevent the DLL from going away while a |
| 93 // patch is still active. |
| 94 // |
| 95 DWORD Patch(const wchar_t* module, |
| 90 const char* imported_from_module, | 96 const char* imported_from_module, |
| 91 const char* function_name, | 97 const char* function_name, |
| 92 void* new_function); | 98 void* new_function); |
| 93 | 99 |
| 94 // Unpatch the IAT entry using internally saved original | 100 // Unpatch the IAT entry using internally saved original |
| 95 // function. | 101 // function. |
| 96 // | 102 // |
| 97 // Returns: Windows error code (winerror.h). NO_ERROR if successful | 103 // Returns: Windows error code (winerror.h). NO_ERROR if successful |
| 98 // | 104 // |
| 99 DWORD Unpatch(); | 105 DWORD Unpatch(); |
| 100 | 106 |
| 101 bool is_patched() const { | 107 bool is_patched() const { |
| 102 return (NULL != intercept_function_); | 108 return (NULL != intercept_function_); |
| 103 } | 109 } |
| 104 | 110 |
| 105 private: | 111 private: |
| 112 HMODULE module_handle_; |
| 106 void* intercept_function_; | 113 void* intercept_function_; |
| 107 void* original_function_; | 114 void* original_function_; |
| 108 IMAGE_THUNK_DATA* iat_thunk_; | 115 IMAGE_THUNK_DATA* iat_thunk_; |
| 109 | 116 |
| 110 DISALLOW_EVIL_CONSTRUCTORS(IATPatchFunction); | 117 DISALLOW_EVIL_CONSTRUCTORS(IATPatchFunction); |
| 111 }; | 118 }; |
| 112 | 119 |
| 113 } // namespace iat_patch | 120 } // namespace iat_patch |
| 114 | 121 |
| 115 #endif // BASE_IAT_PATCH_H__ | 122 #endif // BASE_IAT_PATCH_H__ |
| 116 | 123 |
| OLD | NEW |