forked from jackalstomper/AutomataSpeedrunMod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDLLHook.cpp
More file actions
42 lines (35 loc) · 1.39 KB
/
DLLHook.cpp
File metadata and controls
42 lines (35 loc) · 1.39 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
#include "DLLHook.hpp"
#include <vector>
DLLHook::DLLHook(const std::string& moduleName) {
m_module = NULL;
AutomataMod::log(AutomataMod::LogLevel::LOG_INFO, "Loading " + moduleName);
std::vector<CHAR> buff(1024);
UINT len = GetSystemWindowsDirectory(buff.data(), buff.size());
if (len > buff.size()) {
buff.resize(len);
len = GetSystemWindowsDirectory(buff.data(), len);
}
if (len == 0) {
// failed to get system directory
AutomataMod::log(AutomataMod::LogLevel::LOG_ERROR, "Failed to get windows system directory. Error code: " + std::to_string(GetLastError()));
return;
}
std::string filePath(buff.begin(), buff.begin() + len);
filePath += "\\system32\\" + moduleName;
AutomataMod::log(AutomataMod::LogLevel::LOG_INFO, "Attempting to load " + filePath);
m_module = LoadLibrary(filePath.c_str());
if (m_module == NULL) {
AutomataMod::log(AutomataMod::LogLevel::LOG_ERROR, "Failed to load " + moduleName + " Error code: " + std::to_string(GetLastError()));
}
AutomataMod::log(AutomataMod::LogLevel::LOG_INFO, "Loaded " + moduleName);
}
DLLHook::~DLLHook() {
if (m_module) {
AutomataMod::log(AutomataMod::LogLevel::LOG_INFO, "DLLHook is dropping loaded DLL");
FreeLibrary(m_module);
m_module = NULL;
}
}
bool DLLHook::isModuleFound() const {
return m_module != NULL;
}