-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.cpp
More file actions
150 lines (134 loc) · 4.02 KB
/
Copy pathproxy.cpp
File metadata and controls
150 lines (134 loc) · 4.02 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
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
#include <windows.h>
#include <cstdio>
#include <cstdarg>
#include <cstdint>
constexpr size_t PROC_TABLE_SIZE = 256;
extern "C" {
void* proc_table[PROC_TABLE_SIZE];
}
static void Log(const char* fmt, ...)
{
#ifndef NOLOG
FILE* f = fopen("GDDllLoader.log", "a");
if(!f)
return;
SYSTEMTIME st;
GetLocalTime(&st);
fprintf(f, "[%02u:%02u:%02u.%03u] ", st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
va_list args;
va_start(args, fmt);
vfprintf(f, fmt, args);
fprintf(f, "\n");
va_end(args);
fclose(f);
#endif
}
void ResolveExports()
{
Log("Resolving exports");
HMODULE realWinmm = LoadLibraryA("C:\\Windows\\System32\\winmm.dll");
if (realWinmm)
Log("Real winmm loaded");
else
{
Log("Real winmm failed to load");
return;
}
const char* names[] =
{
#include "export_names.inc"
};
constexpr size_t names_count = sizeof(names) / sizeof(names[0]);
static_assert(names_count <= PROC_TABLE_SIZE);
for (int i = 0; i < names_count; i++)
{
if(names[i])
{
proc_table[i] = (void*)GetProcAddress(realWinmm, names[i]);
if (!proc_table[i])
Log("Failed: %s", names[i]);
else
Log("%s = %p", names[i], proc_table[i]);
}
}
}
struct LoadDllParams
{
wchar_t name[MAX_PATH];
bool reqGameDlls;
uint32_t delay;
uint32_t tries;
};
void LoadDll(const wchar_t* name, bool reqGameDlls, uint32_t delay = 0, uint32_t tries = 1)
{
auto* params = static_cast<LoadDllParams*>(VirtualAlloc(nullptr, sizeof(LoadDllParams), MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE));
if (!params)
{
Log("Virtual alloc failed: %lu", GetLastError());
return;
}
wcsncpy(params->name, name, MAX_PATH - 1);
params->name[MAX_PATH - 1] = L'\0';
params->reqGameDlls = reqGameDlls;
params->delay = delay;
params->tries = tries;
HANDLE thread = CreateThread(nullptr, 0,
[](LPVOID arg) -> DWORD
{
auto* params = static_cast<LoadDllParams*>(arg);
if (params->reqGameDlls)
{
while (!GetModuleHandleW(L"d3d11.dll"))
Sleep(10);
while (!GetModuleHandleW(L"Game.dll"))
Sleep(10);
while (!GetModuleHandleW(L"Engine.dll"))
Sleep(10);
}
Sleep(params->delay);
Log("Loading %ls", params->name);
HMODULE mod = nullptr;
for (uint32_t i = 0; i < params->tries; ++i)
{
mod = LoadLibraryW(params->name);
if (!mod)
Log("Loading %ls failed %lu", params->name, GetLastError());
Sleep(500);
if (mod && GetModuleHandleW(params->name))
break;
if (mod)
FreeLibrary(mod);
mod = nullptr;
if (i + 1 < params->tries)
Log("Retrying to load %ls", params->name);
}
if (mod)
Log("%ls loaded OK", params->name);
else
Log("%ls failed", params->name);
VirtualFree(params, 0, MEM_RELEASE);
return 0;
}, params, 0, nullptr);
if (!thread)
{
Log("Thread creation failed: %lu", GetLastError());
VirtualFree(params, 0, MEM_RELEASE);
return;
}
CloseHandle(thread);
}
BOOL WINAPI DllMain(HINSTANCE hinstance, DWORD reason, LPVOID)
{
if (reason == DLL_PROCESS_ATTACH)
{
DisableThreadLibraryCalls(hinstance);
#ifndef NOLOG
remove("GDDllLoader.log");
#endif
LoadDll(L"dpyes.dll", false, 0, 4);
LoadDll(L"RiftgateCompanion.dll", false, 100, 1);
LoadDll(L"ItemAssistantHook_x64.dll", true, 500, 1);
ResolveExports();
}
return TRUE;
}