forked from citizenfx/fivem
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHooking.cpp
More file actions
76 lines (64 loc) · 1.72 KB
/
Hooking.cpp
File metadata and controls
76 lines (64 loc) · 1.72 KB
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
/*
* This file is part of the CitizenFX project - http://citizen.re/
*
* See LICENSE and MENTIONS in the root of the source tree for information
* regarding licensing.
*/
#include "StdInc.h"
#include "Hooking.h"
namespace hook
{
#ifndef _M_AMD64
void inject_hook::inject()
{
inject_hook_frontend fe(this);
m_assembly = std::make_shared<FunctionAssembly>(fe);
put<uint8_t>(m_address, 0xE9);
put<int>(m_address + 1, (uintptr_t)m_assembly->GetCode() - (uintptr_t)get_adjusted(m_address) - 5);
}
void inject_hook::injectCall()
{
inject_hook_frontend fe(this);
m_assembly = std::make_shared<FunctionAssembly>(fe);
put<uint8_t>(m_address, 0xE8);
put<int>(m_address + 1, (uintptr_t)m_assembly->GetCode() - (uintptr_t)get_adjusted(m_address) - 5);
}
#else
void* AllocateFunctionStub(void* ptr, int type)
{
#if defined(GTA_FIVE) || defined(IS_RDR3)
typedef void*(*AllocateType)(void*, int);
static AllocateType func;
if (func == nullptr)
{
HMODULE coreRuntime = GetModuleHandleW(L"CoreRT.dll");
func = (AllocateType)GetProcAddress(coreRuntime, "AllocateFunctionStubImpl");
}
return func(ptr, type);
#else
return ptr;
#endif
}
void* AllocateStubMemory(size_t size)
{
#if defined(GTA_FIVE) || defined(IS_RDR3)
static decltype(&AllocateStubMemory) func;
if (func == nullptr)
{
HMODULE coreRuntime = GetModuleHandleW(L"CoreRT.dll");
func = (decltype(func))GetProcAddress(coreRuntime, "AllocateStubMemoryImpl");
}
return func(size);
#else
return nullptr;
#endif
}
#endif
ptrdiff_t baseAddressDifference;
}
#ifndef IS_FXSERVER
static InitFunction initHookingFunction([]()
{
hook::set_base();
}, INT32_MIN);
#endif