-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
66 lines (54 loc) · 3.58 KB
/
Main.cpp
File metadata and controls
66 lines (54 loc) · 3.58 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
/*
* Main.cpp -- Main code of the proxy
*
* * Basic overview:
* - ARCArchive object is a C++ object that inherits from multiple C++ classes/interfaces
* - C++ objects are basically structures that contain pointers to arrays of function addresses (i.e. vtables)
* - Each vtable contains pointers to the implementations of each C++ class/interface function
* - We can thus hook C++ functions by making copies of the vtables and replacing the function pointers
* - Each C++ object keeps its own pointers to vtables, so we can control which objects get hooked and which do not
* - We also can append extra data to the object by making a copy of it
*/
#include <windows.h>
#include "Util/logging.h"
#include "Util/hook.h"
#include "Util/heap.h"
#include "Filesystem/FileSystemHooks.h"
#include "CSV/CSVParserHooks.h"
#define DllExport __declspec(dllexport)
#define xstr(s) str(s)
#define str(s) #s
#define REDIRECT(func) \
{ \
if(lstrcmpiA(name, str(func)) == 0) \
{\
func##_original = reinterpret_cast<func##_original_t>(GetProcAddress(hmodule, name));\
return &func##_hook;\
}\
}
void * WINAPI hookGetProcAddress(HMODULE hmodule, char const *name)
{
REDIRECT(DLL_FileSystem_CreateFileSystemArchive);
REDIRECT(DLL_CSV_Open);
return GetProcAddress(hmodule, name);
}
/*
* Installs the proxy
*/
extern "C" void DllExport Install(wchar_t *modsPath)
{
INIT_LOG(".");
LOG("Filesystem proxy started!");
initialize_heap();
proxy_path = modsPath;
if (!is_directory(proxy_path))
{
LOG("Path " << narrow(proxy_path) << " is not a directory! Creating one!");
return;
}
if (!patch_cur_iat(GetModuleHandleA("mono"), "kernel32.dll", &GetProcAddress, &hookGetProcAddress))
{
LOG("Failed to enable hook!");
}
LOG("Hook done!");
}