| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef BASE_WIN_IAT_PATCH_FUNCTION_H_ | 5 #ifndef BASE_WIN_IAT_PATCH_FUNCTION_H_ |
| 6 #define BASE_WIN_IAT_PATCH_FUNCTION_H_ | 6 #define BASE_WIN_IAT_PATCH_FUNCTION_H_ |
| 7 | 7 |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 | 9 |
| 10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 // Note: Patching a function will make the IAT patch take some "ownership" on | 40 // Note: Patching a function will make the IAT patch take some "ownership" on |
| 41 // |module|. It will LoadLibrary(module) to keep the DLL alive until a call | 41 // |module|. It will LoadLibrary(module) to keep the DLL alive until a call |
| 42 // to Unpatch(), which will call FreeLibrary() and allow the module to be | 42 // to Unpatch(), which will call FreeLibrary() and allow the module to be |
| 43 // unloaded. The idea is to help prevent the DLL from going away while a | 43 // unloaded. The idea is to help prevent the DLL from going away while a |
| 44 // patch is still active. | 44 // patch is still active. |
| 45 DWORD Patch(const wchar_t* module, | 45 DWORD Patch(const wchar_t* module, |
| 46 const char* imported_from_module, | 46 const char* imported_from_module, |
| 47 const char* function_name, | 47 const char* function_name, |
| 48 void* new_function); | 48 void* new_function); |
| 49 | 49 |
| 50 // Same as Patch(), but uses a handle to a |module| instead of the DLL name. |
| 51 DWORD PatchFromModule(HMODULE module, |
| 52 const char* imported_from_module, |
| 53 const char* function_name, |
| 54 void* new_function); |
| 55 |
| 50 // Unpatch the IAT entry using internally saved original | 56 // Unpatch the IAT entry using internally saved original |
| 51 // function. | 57 // function. |
| 52 // | 58 // |
| 53 // Returns: Windows error code (winerror.h). NO_ERROR if successful | 59 // Returns: Windows error code (winerror.h). NO_ERROR if successful |
| 54 DWORD Unpatch(); | 60 DWORD Unpatch(); |
| 55 | 61 |
| 56 bool is_patched() const { | 62 bool is_patched() const { |
| 57 return (NULL != intercept_function_); | 63 return (NULL != intercept_function_); |
| 58 } | 64 } |
| 59 | 65 |
| 60 void* original_function() const; | 66 void* original_function() const; |
| 61 | 67 |
| 62 | 68 |
| 63 private: | 69 private: |
| 64 HMODULE module_handle_; | 70 HMODULE module_handle_; |
| 65 void* intercept_function_; | 71 void* intercept_function_; |
| 66 void* original_function_; | 72 void* original_function_; |
| 67 IMAGE_THUNK_DATA* iat_thunk_; | 73 IMAGE_THUNK_DATA* iat_thunk_; |
| 68 | 74 |
| 69 DISALLOW_COPY_AND_ASSIGN(IATPatchFunction); | 75 DISALLOW_COPY_AND_ASSIGN(IATPatchFunction); |
| 70 }; | 76 }; |
| 71 | 77 |
| 72 BASE_EXPORT DWORD ModifyCode(void* old_code, void* new_code, int length); | 78 BASE_EXPORT DWORD ModifyCode(void* old_code, void* new_code, int length); |
| 73 | 79 |
| 74 } // namespace win | 80 } // namespace win |
| 75 } // namespace base | 81 } // namespace base |
| 76 | 82 |
| 77 #endif // BASE_WIN_IAT_PATCH_FUNCTION_H_ | 83 #endif // BASE_WIN_IAT_PATCH_FUNCTION_H_ |
| OLD | NEW |