-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMacroApproachTest.cpp
More file actions
104 lines (87 loc) · 3.11 KB
/
MacroApproachTest.cpp
File metadata and controls
104 lines (87 loc) · 3.11 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "ucp3.h"
#include "MacroApproachTest.h"
#include <sstream>
// TODO?: When in doubt regarding the transition to full exe: Add other logging system.
#ifdef OPEN_SHC_DLL
static void createRelativeJump(int from, int to)
{
const int instructionLength = 5;
const int relativeOffset = to - (from + instructionLength);
DWORD oldProtection;
if (!VirtualProtect((void*)from, instructionLength, PAGE_EXECUTE_READWRITE, &oldProtection)) {
std::ostringstream oss;
oss << "Error while trying to remove memory protection to create relative jump from '" << from << "' to '" << to
<< "': " << GetLastError();
ucp_log(Verbosity_FATAL, oss.str().c_str());
}
// create relative jmp
*((char*)from) = (char)0xe9;
*((int*)(from + 1)) = relativeOffset;
DWORD dummyProtection;
if (!VirtualProtect((void*)from, instructionLength, oldProtection, &dummyProtection)) {
std::ostringstream oss;
oss << "Error while trying to re-enable memory protection after creating relative jump from '" << from
<< "' to '" << to << "': " << GetLastError();
ucp_log(Verbosity_FATAL, oss.str().c_str());
}
}
#endif
void Initializer::initializeStruct(
bool& initialized, bool isImplemented, int gameAddress, const void* funcPtr, const char* funcName)
{
if (initialized) {
#ifdef OPEN_SHC_EXE
abort(); // crash silently; if we switch to exe, we should already be sure to never trigger this
#endif
#ifdef OPEN_SHC_DLL
std::ostringstream oss;
oss << "Abort execution, since address '" << gameAddress << "' was resolved more then once.";
ucp_log(Verbosity_FATAL, oss.str().c_str());
#endif
return;
}
initialized = true;
#ifdef OPEN_SHC_DLL
if (ucp_logLevel() < Verbosity_1) {
return;
}
std::ostringstream oss;
if (isImplemented) {
oss << "Implemented '" << (void*)gameAddress << "' at address '" << funcPtr << "' as a '" << funcName;
} else {
oss << "Use '" << (void*)gameAddress << "' as a '" << funcName;
}
ucp_log(Verbosity_1, oss.str().c_str());
#endif
}
void Initializer::initializeFunction(
bool& initialized, bool isImplemented, int gameAddress, const void* funcPtr, const char* funcName)
{
if (initialized) {
#ifdef OPEN_SHC_EXE
abort(); // crash silently; if we switch to exe, we should already be sure to never trigger this
#endif
#ifdef OPEN_SHC_DLL
std::ostringstream oss;
oss << "Abort execution, since address '" << gameAddress << "' was resolved more then once.";
ucp_log(Verbosity_FATAL, oss.str().c_str());
#endif
return;
}
initialized = true;
#ifdef OPEN_SHC_DLL
if (isImplemented) {
createRelativeJump(gameAddress, (int)funcPtr);
}
if (ucp_logLevel() < Verbosity_1) {
return;
}
std::ostringstream oss;
if (isImplemented) {
oss << "Implemented '" << (void*)gameAddress << "' at address '" << funcPtr << "' as '" << funcName;
} else {
oss << "Use '" << (void*)gameAddress << "' as '" << funcName;
}
ucp_log(Verbosity_1, oss.str().c_str());
#endif
}