-
Notifications
You must be signed in to change notification settings - Fork 18
/
hooker.hpp
442 lines (400 loc) · 25.7 KB
/
hooker.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
/*
* MIT License
*
* Copyright (c) 2017 Rokas Kupstys
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#pragma once
#include <type_traits>
#include <stdexcept>
#include <cstdint>
namespace hooker
{
namespace detail
{
extern "C"
{
#include "hooker.h"
}
struct Helper { };
}
#if __cplusplus >= 201402L
/// Pattern for find_pattern() function.
template <size_t N>
struct pattern
{
/// Bytes to find. Value of wildcard byte or byte half can be anything.
uint8_t pattern[N];
/// Wildcard pattern. Byte value may be one of: 0? = 1, ?0 = 2, ?? = 3.
uint8_t wildcard[N];
};
# define CPP14(x) x
namespace detail
{
// Convert hex character to a number.
constexpr uint8_t char_to_byte(char c)
{
if (c >= '0' && c <= '9')
return c - '0';
else if (c >= 'a' && c <= 'f')
return 0x0A + c - 'a';
else if (c >= 'A' && c <= 'F')
return 0x0A + c - 'A';
else if (c == '?')
return 0;
else
throw std::runtime_error("Not a hex character.");
}
// Convert text hex byte at `idx` to binary.
template <size_t N>
constexpr uint8_t get_pattern_byte(const char(&s)[N], size_t idx)
{
if (s[idx * 3 + 2] != ' ' && s[idx * 3 + 2] != '\0')
throw std::runtime_error("Improperly formatted pattern.");
else
return (char_to_byte(s[idx * 3]) << 4) | char_to_byte(s[idx * 3 + 1]);
}
// Convert text wildcard to binary mask.
template <size_t N>
constexpr uint8_t get_wildcard_byte(const char(&s)[N], size_t idx)
{
return (s[idx * 3] == '?' ? 2 : 0) | (s[idx * 3 + 1] == '?' ? 1 : 0);
}
// Convert a character array to binary version and wildcard array.
template <size_t N, size_t... Is>
constexpr pattern<sizeof...(Is)> decode_string_pattern(const char(&s)[N], std::index_sequence<Is...>)
{
return {
{ get_pattern_byte(s, Is)... },
{ get_wildcard_byte(s, Is)... },
};
}
}
// Create a binary pattern from raw string litteral in format: "AB C? ?D ??".
template <size_t N>
constexpr const pattern<N / 3> mkpat(const char(&s)[N])
{
if ((N % 3) == 0)
return detail::decode_string_pattern(s, std::make_index_sequence<N / 3>());
else
throw std::runtime_error("Improperly formatted pattern.");
}
#else
# define CPP14(x)
#endif
#if __cplusplus > 201703L
using bit_cast = std::bit_cast;
#else
template<typename To, typename From>
#if __cplusplus >= 201703L
[[nodiscard]]
#endif
To bit_cast(From &&from)
#if __cplusplus >= 201402L
noexcept(std::is_nothrow_constructible<To>::value)
#endif
{
static_assert(std::is_trivially_copyable<typename std::remove_cv<typename std::remove_reference<From>::type>::type>::value, "From type must be trivially copable.");
static_assert(std::is_trivially_copyable<typename std::remove_cv<typename std::remove_reference<To>::type>::type>::value, "To type must be trivially copiable.");
static_assert(sizeof(From) == sizeof(To), "Sizes of From and To types must be the same.");
static_assert(std::is_default_constructible<To>::value, "To type must be default constructible.");
#if __cplusplus >= 201402L
auto result = (typename std::aligned_storage_t<sizeof(To), alignof(To)>){};
#else
To result{};
#endif
return *static_cast<To*>(memcpy(&result, &from, sizeof(To)));
}
#endif
namespace detail
{
template<typename Addr>
typename std::enable_if<std::is_integral<Addr>::value, void*>::type
any_to_voidp(Addr addr) { return reinterpret_cast<void*>(static_cast<uintptr_t>(addr)); }
template<typename Addr>
typename std::enable_if<!std::is_integral<Addr>::value, void*>::type
any_to_voidp(Addr addr) { return bit_cast<void*>(addr); }
}
#if _WIN32
/// Calls specified address as __stdcall function passing any amount of arguments. Return type is specified as first template argument. Available only on windows.
/// \param address of function to call.
/// \param ... any amount of arguments with any types.
/// \returns value of type specified as first template argument, or none if no type is specified.
template<typename Result, typename Addr, typename... Args>
Result stdcall(Addr address, Args... arguments)
{
typedef Result(__stdcall*UniversalCall)(Args...);
return UniversalCall(address)(arguments...);
}
# define HOOKER_CDECL __cdecl
#else
# define HOOKER_CDECL
#endif
/// Calls specified address as __cdecl function passing any amount of arguments. Return type is specified as first template argument.
/// \param address of function to call.
/// \param ... any amount of arguments with any types.
/// \returns value of type specified as first template argument, or none if no type is specified.
template<typename Result, typename Addr, typename... Args>
Result ccall(Addr address, Args... arguments)
{
typedef Result(HOOKER_CDECL*UniversalCall)(Args...);
return reinterpret_cast<UniversalCall>(address)(arguments...);
}
#undef HOOKER_CDECL
/// Calls specified address as __thiscall function with provided address as 'this' pointer, passing any amount of arguments. Return type is specified as first template argument.
/// \param address of function to call.
/// \param ... any amount of arguments with any types.
/// \returns value of type specified as first template argument, or none if no type is specified.
template<typename Result, typename Addr, typename This, typename... Args>
Result thiscall(Addr address, This thisPtr, Args... arguments)
{
detail::Helper* thisHelper = bit_cast<detail::Helper*>(thisPtr);
typedef Result(detail::Helper::*TUniversalCall)(Args...);
TUniversalCall UniversalCall = bit_cast<TUniversalCall>(address);
return (thisHelper->*UniversalCall)(arguments...);
}
/// Return object of specified `Type` which is located at `base + offset`.
template<typename Type, typename Base>
Type at_offset(Base base, unsigned offset)
{
return bit_cast<Type>(bit_cast<std::uintptr_t>(base) + offset);
}
/// Return object of specified `Type` which is located at `base + offset`.
template<typename Type, typename Base>
Type from_offset(Base base, unsigned offset)
{
return *at_offset<Type*>(base, offset);
}
/// Change protection of memory range.
/// \param p memory address.
/// \param size of memory at address p.
/// \param protection a combination of HOOKER_MEM_* flags.
/// \param original_protection on supported platforms will be set to current memory protection mode. May be null. If not null - always initialize to a best-guess current protection flags value, because on some platforms (like linux) this variable will not be set.
template<typename Type CPP14(=void*), typename Addr>
bool mem_protect(Addr p, size_t size, size_t protection, size_t* original_protection=nullptr) { return detail::hooker_mem_protect(detail::any_to_voidp(p), size, protection, original_protection) == HOOKER_SUCCESS; }
/// Get mnemonic size of current platform.
template<typename Addr>
size_t get_mnemonic_size(Addr address, size_t min_size) { return detail::hooker_get_mnemonic_size(detail::any_to_voidp(address), min_size); }
/// Hotpatch a call.
template<typename OriginalProc CPP14(=void*), typename Addr, typename ProcAddr>
OriginalProc hotpatch(Addr location, ProcAddr new_proc) { return bit_cast<OriginalProc>(detail::hooker_hotpatch(detail::any_to_voidp(location), detail::any_to_voidp(new_proc))); }
/// Unhotpatch a call.
template<typename Type CPP14(=void*), typename Addr>
bool unhotpatch(Addr location) { return detail::hooker_unhotpatch(detail::any_to_voidp(location)) == HOOKER_SUCCESS; }
/// Writes a jump or call hook from `address` to `new_proc`.
/// \param address a pointer where hook should be written
/// \param new_proc a pointer where hook should point to.
/// \param flags any of HOOKER_HOOK_* flags. They may not be combined.
/// \param nops of bytes to nop after hook instruction. Specify -1 to autocalculate.
/// \returns null on failure or non-null on success.
template<typename Addr, typename ProcAddr>
bool write_instruction(Addr address, ProcAddr new_proc, size_t flags, size_t nops=-1) { return detail::hooker_write_instruction(detail::any_to_voidp(address), detail::any_to_voidp(new_proc), flags, nops) == HOOKER_SUCCESS; }
/// Writes a 5 byte jump with E9 opcode. Difference between pointers is limited to 32bit.
/// \param address a pointer where hook should be written
/// \param new_proc a pointer where hook should point to.
/// \returns null on failure or non-null on success.
template<typename Addr, typename ProcAddr>
bool write_jmp(Addr address, ProcAddr new_proc) { return detail::hooker_write_jmp(detail::any_to_voidp(address), detail::any_to_voidp(new_proc)) == HOOKER_SUCCESS; }
/// Writes a 5 byte call with E8 opcode. Difference between pointers is limited to 32bit.
/// \param address a pointer where hook should be written
/// \param new_proc a pointer where hook should point to.
/// \returns null on failure or non-null on success.
template<typename Addr, typename ProcAddr>
bool write_call(Addr address, ProcAddr new_proc) { return detail::hooker_write_call(detail::any_to_voidp(address), detail::any_to_voidp(new_proc)) == HOOKER_SUCCESS; }
/// Redirect call to custom proc.
/// \param address a start of original call. Warning: It should not contain any relatively-addressed instructions like calls or jumps.
/// \param new_proc a proc that will be called instead of original one.
/// \returns pointer, calling which will invoke original proc. It is user's responsibility to call original code when necessary.
template<typename OriginalProc CPP14(=void*), typename Addr, typename ProcAddr>
OriginalProc hook(Addr address, ProcAddr new_proc, size_t flags=0) { return bit_cast<OriginalProc>(detail::hooker_hook(detail::any_to_voidp(address), detail::any_to_voidp(new_proc), flags)); }
/// Unhook a hook created by hooker::hook(.., .., HOOKER_HOOK_REDIRECT, ..).
/// \param address where hook was written to.
/// \param original result of hooker::redirect() call.
template<typename Addr, typename OriginalProc>
void unhook(Addr address, OriginalProc original) { detail::hooker_unhook(detail::any_to_voidp(address), detail::any_to_voidp(original)); }
/// Return address in object's vmt which is pointing to specified method.
/// \param object is a pointer to a c++ object.
/// \param method is a pointer to a c++ object method.
template<typename Proc, typename Addr, typename ProcAddr>
Proc& get_vmt_address(Addr object, ProcAddr method) { return *bit_cast<Proc*>(detail::hooker_get_vmt_address(reinterpret_cast<void*>(object), detail::any_to_voidp(method))); }
/// Find a first occurrence of memory pattern.
/// \param start a pointer to beginning of memory range.
/// \param size a size of memory range. If size is 0 then entire memory space will be searched. If pattern does not exist this will likely result in a crash. Negative size will search backwards.
/// \param pattern a array of bytes to search for.
/// \param pattern_len a length of pattern array.
/// \param a wildcard byte in the pattern array.
template<typename Type CPP14(=uint8_t*), typename Addr, typename Pattern>
Type find_pattern(Addr start, int size, const Pattern* pattern, size_t pattern_len, uint8_t wildcard) { return bit_cast<Type>(detail::hooker_find_pattern(detail::any_to_voidp(start), size, reinterpret_cast<const uint8_t*>(pattern), pattern_len, wildcard)); }
#if __cplusplus >= 201402L
/// Find a first occurrence of memory pattern.
/// \param start a pointer to beginning of memory range.
/// \param size a size of memory range. If size is 0 then entire memory space will be searched. If pattern does not exist this will likely result in a crash. Negative size will search backwards.
/// \param pattern and wildcard mask.
template<typename Type CPP14(=uint8_t*), typename Addr, size_t N>
Type find_pattern(Addr start, int size, const pattern<N>& pattern) { return bit_cast<Type>(detail::hooker_find_pattern_ex(detail::any_to_voidp(start), size, pattern.pattern, N, pattern.wildcard)); }
#endif
/// Find a first occurrence of string pattern.
/// \param start a pointer to beginning of memory range.
/// \param size a size of memory range. If size is 0 then entire memory space will be searched. If pattern does not exist this will likely result in a crash. Negative size will search backwards.
/// \param pattern a string to search.
/// \param wildcard a wildcard character.
template<typename Type CPP14(=char*), typename Addr>
Type find_pattern(Addr start, int size, const char* pattern, char wildcard='?') { return bit_cast<Type>(detail::hooker_find_pattern(detail::any_to_voidp(start), size, reinterpret_cast<const uint8_t*>(pattern), strlen(pattern), static_cast<uint8_t>(wildcard))); }
/// Find a first occurrence of string pattern.
/// \param start a pointer to beginning of memory range.
/// \param size a size of memory range. If size is 0 then entire memory space will be searched. If pattern does not exist this will likely result in a crash. Negative size will search backwards.
/// \param pattern a string to search.
/// \param pattern_len a length of pattern string.
/// \param wildcard a wildcard character.
template<typename Type CPP14(=char*), typename Addr>
Type find_pattern(Addr start, int size, const char* pattern, int pattern_len, char wildcard='?') { return bit_cast<Type>(detail::hooker_find_pattern(detail::any_to_voidp(start), size, reinterpret_cast<const uint8_t*>(pattern), pattern_len, static_cast<uint8_t>(wildcard))); }
/// Find a first occurrence of specified data.
/// \param start a pointer to beginning of memory range.
/// \param size a size of memory range. If size is 0 then entire memory space will be searched. If pattern does not exist this will likely result in a crash. Negative size will search backwards.
/// \param pattern to search.
/// \param pattern_len is a length of pattern.
template<typename Type CPP14(= char*), typename Addr>
Type find(Addr start, int size, const void* pattern, int pattern_len) { return bit_cast<Type>(detail::hooker_find(detail::any_to_voidp(start), size, reinterpret_cast<const uint8_t*>(pattern), pattern_len)); }
/// Find a first occurrence of specified data.
/// \param start a pointer to beginning of memory range.
/// \param size a size of memory range. If size is 0 then entire memory space will be searched. If pattern does not exist this will likely result in a crash. Negative size will search backwards.
/// \param pattern to search.
/// \param pattern_len is a length of pattern.
template<typename Type CPP14(= char*), typename Addr>
Type find(Addr start, int size, const char* pattern, int pattern_len) { return bit_cast<Type>(detail::hooker_find(detail::any_to_voidp(start), size, reinterpret_cast<const uint8_t*>(pattern), pattern_len)); }
/// Find a first occurrence of specified data.
/// \param start a pointer to beginning of memory range.
/// \param size a size of memory range. If size is 0 then entire memory space will be searched. If pattern does not exist this will likely result in a crash. Negative size will search backwards.
/// \param pattern to search.
/// \param pattern_len is a length of pattern in chars.
template<typename Type CPP14(= char*), typename Addr>
Type find(Addr start, int size, const wchar_t* pattern, int pattern_len) { return bit_cast<Type>(detail::hooker_find(detail::any_to_voidp(start), size, reinterpret_cast<const uint8_t*>(pattern), pattern_len * 2)); }
/// Find a first occurrence of specified data.
/// \param start a pointer to beginning of memory range.
/// \param size a size of memory range. If size is 0 then entire memory space will be searched. If pattern does not exist this will likely result in a crash. Negative size will search backwards.
/// \param pattern to search. It should be a null-terminated string. Null byte is not included in search.
template<typename Type CPP14(= char*), typename Addr>
Type find(Addr start, int size, const char* pattern) { return bit_cast<Type>(detail::hooker_find(detail::any_to_voidp(start), size, reinterpret_cast<const uint8_t*>(pattern), strlen(pattern) + 1)); }
/// Find a first occurrence of specified data.
/// \param start a pointer to beginning of memory range.
/// \param size a size of memory range. If size is 0 then entire memory space will be searched. If pattern does not exist this will likely result in a crash. Negative size will search backwards.
/// \param pattern to search. It should be a null-terminated string. Null byte is not included in search.
template<typename Type CPP14(= char*), typename Addr>
Type find(Addr start, int size, const wchar_t* pattern) { return bit_cast<Type>(detail::hooker_find(detail::any_to_voidp(start), size, reinterpret_cast<const uint8_t*>(pattern), wcslen(pattern) * 2 + 2)); }
/// Find instruction "lea REG, DATA"
/// \param start a pointer to beginning of memory range.
/// \param size a size of memory range. If size is 0 then entire memory space will be searched. If pattern does not exist this will likely result in a crash. Negative size will search backwards.
/// \param data pointer that is loaded by lea instruction.
/// \param data_len length of data.
/// \returns a pointer to lea instruction or 0.
template<typename Type CPP14(= char*), typename Addr>
Type find_lea_data_64(Addr start, int size, const void* data, int data_len) { return bit_cast<Type>(detail::hooker_find_lea_data_64(detail::any_to_voidp(start), size, data, data_len)); }
/// Find instruction "lea REG, DATA"
/// \param start a pointer to beginning of memory range.
/// \param size a size of memory range. If size is 0 then entire memory space will be searched. If pattern does not exist this will likely result in a crash. Negative size will search backwards.
/// \param str a string pointer including null terminator.
/// \returns a pointer to lea instruction or 0.
template<typename Type CPP14(= char*), typename Addr>
Type find_lea_data_64(Addr start, int size, const char* str) { return bit_cast<Type>(detail::hooker_find_lea_data_64(detail::any_to_voidp(start), size, str, strlen(str) + 1)); }
/// Find instruction "lea REG, DATA"
/// \param start a pointer to beginning of memory range.
/// \param size a size of memory range. If size is 0 then entire memory space will be searched. If pattern does not exist this will likely result in a crash. Negative size will search backwards.
/// \param wstr a wide string pointer including null terminator.
/// \returns a pointer to lea instruction or 0.
template<typename Type CPP14(= char*), typename Addr>
Type find_lea_data_64(Addr start, int size, const wchar_t* wstr) { return bit_cast<Type>(detail::hooker_find_lea_data_64(detail::any_to_voidp(start), size, wstr, wcslen(wstr) * 2 + 2)); }
/// Fill memory with nops (0x90 opcode).
/// \param start of the memory address.
/// \param size of the memory that will be filled. Nops a single instruction when not specified.
/// \returns true on success or false on failure.
template<typename Addr>
bool nop(Addr start, size_t size=-1) { return detail::hooker_nop(detail::any_to_voidp(start), size) == HOOKER_SUCCESS; }
/// Write a value to specified memory address.
/// \param start of the memory address.
/// \param value to be written.
/// \returns true on success or false on failure.
template<typename Type, typename Addr>
bool write(Addr address, const Type value) { return detail::hooker_write(detail::any_to_voidp(address), (void*)&value, sizeof(value)) == HOOKER_SUCCESS; }
/// Write an array to specified memory address.
/// \param start of the memory address.
/// \param value to be written.
/// \param count of elements in the array.
template<typename Type, typename Addr>
bool write(Addr address, const Type* value, size_t count) { return detail::hooker_write(detail::any_to_voidp(address), (void*)value, sizeof(Type) * count) == HOOKER_SUCCESS; }
/// Write bytes to specified memory address.
/// \param start of the memory address.
/// \param data to be written.
/// \param size of data.
/// \returns true on success or false on failure.
template<typename Addr>
bool write(Addr address, const void* data, size_t size) { return detail::hooker_write(detail::any_to_voidp(address), data, size) == HOOKER_SUCCESS; }
/// Write a string to a specified memory address.
/// \param start of the memory address.
/// \param data to be written.
/// \param size of data.
/// \returns true on success or false on failure.
template<typename Addr>
bool write(Addr address, const char* data) { return detail::hooker_write(detail::any_to_voidp(address), detail::any_to_voidp(data), strlen(data) + 1) == HOOKER_SUCCESS; }
/// Write a string to a specified memory address.
/// \param start of the memory address.
/// \param data to be written.
/// \param size of data.
/// \returns true on success or false on failure.
template<typename Addr>
bool write(Addr address, const wchar_t* data) { return detail::hooker_write(detail::any_to_voidp(address), detail::any_to_voidp(data), wcslen(data) * 2 + 2) == HOOKER_SUCCESS; }
/// Searches for symbol in specified library. On Windows LoadLibrary() will be called if its not loaded yet, otherwise GetModuleHandle() will be used.
/// On linux dlopen(RTLD_NODELETE) and dlclose() will always be called.
/// \param lib_name string with dynamic library name.
/// \param sym_name string with exported symbol name.
/// \returns pointer to resolved dynamic symbol.
template<typename Proc CPP14(=void*)>
Proc dlsym(const char* lib_name, const char* sym_name) { return bit_cast<Proc>(detail::hooker_dlsym(lib_name, sym_name)); }
#if _WIN32
/// Replaces entry in import address table of specified module.
/// \param mod_name string with name of module whose import table is to be modified.
/// \param imp_mod_name string with name of module which module specified in `mod_name` imports.
/// \param imp_proc_name string with name of symbol imported from module specified in `imp_mod_name`.
/// \param new_proc a pointer that should replace old entry in import address table.
/// \returns original value that was in import address table or null pointer on failure.
template<typename OrigProc CPP14(= void*), typename NewProc>
OrigProc hook_iat(const char* mod_name, const char* imp_mod_name, const char* imp_proc_name, NewProc new_proc) { return bit_cast<OrigProc>(detail::hooker_hook_iat(mod_name, imp_mod_name, imp_proc_name, detail::any_to_voidp(new_proc))); }
/// Replaces entry in import address table of specified module.
/// \param mod_name string with name of module whose import table is to be modified.
/// \param imp_mod_name string with name of module which module specified in `mod_name` imports.
/// \param imp_proc_name string with name of symbol imported from module specified in `imp_mod_name`.
/// \param new_proc a pointer that should replace old entry in import address table.
/// \param old_proc a pointer which will receive Can be null.
/// \returns true on success or false on failure.
template<typename OrigProc CPP14(=void*), typename NewProc>
bool hook_iat(const char* mod_name, const char* imp_mod_name, const char* imp_proc_name, NewProc new_proc, OrigProc* old_proc)
{
auto result = hook_iat<OrigProc>(mod_name, imp_mod_name, imp_proc_name, detail::any_to_voidp(new_proc));
if (old_proc)
*old_proc = result;
return result != HOOKER_ERROR;
}
#endif
};
#if HOOKER_USE_SHORT_NAMESPACE
# ifndef HOOKER_SHORT_NAMESPACE
# define HOOKER_SHORT_NAMESPACE hk
# endif
namespace HOOKER_SHORT_NAMESPACE = hooker;
#endif