-
Notifications
You must be signed in to change notification settings - Fork 20
/
hooker.cpp
54 lines (43 loc) · 1.24 KB
/
hooker.cpp
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
#include <hooker.h>
#include <cbase.h>
namespace Hooker
{
HookerCvarRegister* hookerCvarRegister = NULL;
void HookerCvarRegister::hooker(cvar_t *cvar)
{
char *libraryName;
if (Global::LibrariesCvarToName->retrieve(cvar->name, &libraryName))
{
LibrariesManager::addLibrary(libraryName, (void*)cvar);
}
Hooker::hookerCvarRegister->undoPatch();
g_engfuncs.pfnCVarRegister(cvar);
Hooker::hookerCvarRegister->doPatch();
}
HookerCvarRegister::HookerCvarRegister()
{
createPatch();
doPatch();
}
void HookerCvarRegister::createPatch()
{
memcpy((void*)originalBytes, (void*)g_engfuncs.pfnCVarRegister, this->patchSize);
patchedBytes[0] = 0xE9;
*((long*)(&patchedBytes[1])) = (char*)HookerCvarRegister::hooker - (char*)g_engfuncs.pfnCVarRegister - 5;
}
void HookerCvarRegister::doPatch()
{
if (Memory::ChangeMemoryProtection((void*)g_engfuncs.pfnCVarRegister, this->patchSize, PAGE_EXECUTE_READWRITE))
{
memcpy((void*)g_engfuncs.pfnCVarRegister, (void*)patchedBytes, this->patchSize);
}
else
{
Global::ConfigManagerObj->ModuleConfig.append(ke::AString("PATCHING FAILED\n"));
}
}
void HookerCvarRegister::undoPatch()
{
memcpy((void*)g_engfuncs.pfnCVarRegister, (void*)originalBytes, this->patchSize);
}
}