[go: nahoru, domu]

blob: 9070b9d93a6f0328df2bf6d8d52d42bb7d7fd856 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2014 The Chromium Authors
pennymac5446d892016-08-27 10:45:122// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Patrick Monette0196be22019-05-10 03:33:155#ifndef CHROME_CHROME_ELF_HOOK_UTIL_HOOK_UTIL_H_
6#define CHROME_CHROME_ELF_HOOK_UTIL_HOOK_UTIL_H_
pennymac5446d892016-08-27 10:45:127
8#include <windows.h>
9
pennymac5446d892016-08-27 10:45:1210namespace elf_hook {
11
12//------------------------------------------------------------------------------
pennymac5446d892016-08-27 10:45:1213// Import Address Table hooking support
14//------------------------------------------------------------------------------
15class IATHook {
16 public:
17 IATHook();
Peter Boström53c6c5952021-09-17 09:41:2618
19 IATHook(const IATHook&) = delete;
20 IATHook& operator=(const IATHook&) = delete;
21
pennymac5446d892016-08-27 10:45:1222 ~IATHook();
23
24 // Intercept a function in an import table of a specific
25 // module. Saves everything needed to Unhook.
26 //
27 // NOTE: Hook can only be called once at a time, to enable Unhook().
28 //
29 // Arguments:
30 // module Module to be intercepted
31 // imported_from_module Module that exports the 'function_name'
32 // function_name Name of the API to be intercepted
33 // new_function New function pointer
34 //
35 // Returns: Windows error code (winerror.h). NO_ERROR if successful.
36 DWORD Hook(HMODULE module,
37 const char* imported_from_module,
38 const char* function_name,
39 void* new_function);
40
41 // Unhook the IAT entry.
42 //
43 // Returns: Windows error code (winerror.h). NO_ERROR if successful.
44 DWORD Unhook();
45
46 private:
47 void* intercept_function_;
48 void* original_function_;
49 IMAGE_THUNK_DATA* iat_thunk_;
pennymac5446d892016-08-27 10:45:1250};
51
52} // namespace elf_hook
53
Lei Zhang40a9bf92021-04-21 16:28:5454#endif // CHROME_CHROME_ELF_HOOK_UTIL_HOOK_UTIL_H_