-
Notifications
You must be signed in to change notification settings - Fork 1
/
dllmain.cpp
183 lines (141 loc) · 4.24 KB
/
dllmain.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include <stdio.h>
#include <Windows.h>
#include <map>
#include <MinHook.h>
#pragma comment(lib, "libMinHook.x86.lib")
/// Replacement files
std::map<const char*, const char*> files = {
{ "panorama\\layout\\mainmenu_inventory.xml", "C:\\mainmenu_inventory.xml" }
};
///
template<typename Fn>
Fn GetFunction(PVOID address, int idx)
{
PVOID* pVTable = *(PVOID**)address;
return reinterpret_cast<Fn>(pVTable[idx]);
}
class IZip
{
public:
inline void AddFileToZip(const char* relativename, const char* fullpath)
{
return GetFunction<void(__thiscall*)(IZip*, const char*, const char*)>(this, 1)(this, relativename, fullpath);
}
inline bool FileExistsInZip(const char* pRelativeName)
{
return GetFunction<bool(__thiscall*)(IZip*, const char*)>(this, 2)(this, pRelativeName);
}
inline void RemoveFileFromZip(const char* relativename)
{
return GetFunction<void(__thiscall*)(IZip*, const char*)>(this, 5)(this, relativename);
}
inline void ParseFromBuffer(void* buffer, int bufferlength)
{
return GetFunction<void (__thiscall*)(IZip*, void*, int)>(this, 14)(this, buffer, bufferlength);
}
};
typedef void(__fastcall* FnParseFromBuffer)(IZip* ecx, int edx, void* buffer, int bufferlength);
FnParseFromBuffer oParseFromBuffer = nullptr;
void __fastcall ParseFromBuffer_Hooked(IZip* ecx, int edx, void* buffer, int bufferlength)
{
printf("\t[+] Hook called. ECX: 0x%p\n", ecx);
oParseFromBuffer(ecx, edx, buffer, bufferlength);
for (const auto& [relative, path] : files)
{
printf("\t[?] File %s\n", relative);
if (!ecx->FileExistsInZip(relative))
{
printf("\t %c%c Not found in archive\n", 192, 196);
continue;
}
ecx->RemoveFileFromZip(relative);
ecx->AddFileToZip(relative, path);
printf("\t %c%c Swapped to %s\n", 192, 196, path);
}
if (MH_DisableHook(MH_ALL_HOOKS) != MH_OK)
{
printf("\t[-] Failed to remove hook\n");
return;
}
printf("\t[+] Hook removed\n");
}
PVOID FindPattern(PVOID base, size_t length, const char* pattern, const char* mask)
{
length -= strlen(mask);
for (int i = 0; i <= length; i++)
{
bool found = true;
for (int p = 0; mask[p]; p++)
{
if (mask[p] == 'x' && pattern[p] != static_cast<char*>(base)[i + p])
{
found = false;
break;
}
}
if (found)
return static_cast<PBYTE>(base) + i;
}
return nullptr;
}
void NewThread(HMODULE hModule)
{
FILE* file = nullptr;
HMODULE hPanorama = nullptr;
PVOID pParseFromBuffer = nullptr;
AllocConsole();
AttachConsole(ATTACH_PARENT_PROCESS);
freopen_s(&file, "CONOUT$", "w", stdout);
if (!file)
goto exit;
while (hPanorama == nullptr)
{
hPanorama = GetModuleHandle(L"panorama.dll");
Sleep(1);
}
pParseFromBuffer = FindPattern(hPanorama, 0x2A86E0, "\x55\x8B\xEC\x56\x8D\x71\x04\x8D\x4E\x0C\xE8", "xxxxxxxxxxx");
if (!pParseFromBuffer)
{
printf("\t[-] Failed to find ParseFromBuffer by pattern\n");
goto exit;
}
printf("\t[?] ParseFromBuffer: 0x%p\n", pParseFromBuffer);
if (MH_Initialize() != MH_OK)
{
printf("\t[-] MinHook not initialized\n");
goto exit;
}
if (MH_CreateHook(pParseFromBuffer, &ParseFromBuffer_Hooked, (LPVOID*)&oParseFromBuffer) != MH_OK)
{
printf("\t[-] Failed to set hook\n");
goto exit;
}
if (MH_EnableHook(pParseFromBuffer) != MH_OK)
{
printf("\t[-] Failed to enable hook");
goto exit;
}
printf("\t[+] Hook established\n");
while (true)
{
if (GetAsyncKeyState(VK_DELETE) & 0x1)
break;
Sleep(1);
}
exit:
if (file)
{
printf("\t[?] Unloaded\n");
fclose(file);
}
FreeConsole();
FreeLibraryAndExitThread(hModule, 0);
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
{
CreateThread(nullptr, NULL, (LPTHREAD_START_ROUTINE)NewThread, hModule, NULL, nullptr);
}
return TRUE;
}