-
Notifications
You must be signed in to change notification settings - Fork 0
/
commutils.cpp
59 lines (52 loc) · 1.56 KB
/
commutils.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
55
56
57
58
59
#include "stdafx.h"
#include "MinHook.h"
#include "commutils.h"
#include "hookimpl.h"
#include "DriverMgr.h"
#include "HipsCfgObject.h"
#include "HookImplementObject.h"
#include "LogObject.h"
#include "utils.h"
#include "resource.h"
extern BOOL g_initSuccess;
bool g_is_dll_module = false;
std::shared_ptr<CHipsCfgObject> InitializeConfig()
{
//TODO: read hook config information from json file.
HMODULE ModuleHandle = NULL;
std::vector<BYTE> ResBuffer;
if(g_is_dll_module)
ModuleHandle = GetModuleHandle(__TEXT("hipshook.dll"));
else
ModuleHandle = GetModuleHandle(NULL);
std::shared_ptr<CHipsCfgObject> hipsCfgObject = std::make_shared<CHipsCfgObject>();
bool result = ExtractResource(ModuleHandle,
__TEXT("JSONRES"),
MAKEINTRESOURCE(IDR_HIPSHOOK),
ResBuffer);
if (result && ResBuffer.size() > 0)
{
if (hipsCfgObject && hipsCfgObject->Initialize(std::string_view((char*)&ResBuffer[0], ResBuffer.size())))
{
return hipsCfgObject;
}
}
return nullptr;
}
bool InitializeHook(std::shared_ptr<CHipsCfgObject> hipsCfgObject)
{
bool bSuccess = false;
if (hipsCfgObject == nullptr || g_impl_object == nullptr || g_log_object == nullptr)
return false;
if (g_impl_object->Initialize(std::move(hipsCfgObject)) && g_log_object->Initialize(g_impl_object->GetLogMode()) && g_impl_object->Running())
{
bSuccess = true;
}
return bSuccess;
}
void UninitialHook()
{
if (g_impl_object)
g_impl_object->DisableAllApis();
return;
}