-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshim.c
54 lines (43 loc) · 1.38 KB
/
shim.c
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
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <windows.h>
#define ARRAY_LEN(arr) sizeof(arr) / sizeof(arr[0])
bool (*InitialiseRonin)() = NULL;
__declspec(dllexport) bool InitialiseNorthstar()
{
FARPROC InitialiseRonin = NULL;
wchar_t exe_path[4096];
wchar_t buffer[8192];
HMODULE current_module = NULL;
if (GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
(LPCWSTR)&InitialiseNorthstar, ¤t_module) == 0)
{
int ret = GetLastError();
fprintf(stderr, "GetModuleHandleExW failed, error = %d\n", ret);
return false;
}
if (GetModuleFileNameW(current_module, exe_path, sizeof(exe_path)) == 0)
{
int ret = GetLastError();
fprintf(stderr, "GetModuleFileNameW failed, error = %d\n", ret);
return false;
}
{
wchar_t* path_end = exe_path + wcslen(exe_path);
while (*path_end != '\\') --path_end;
*path_end = '\0';
}
swprintf_s(buffer, ARRAY_LEN(buffer), L"%s\\Ronin.dll", exe_path);
HMODULE dll = LoadLibraryExW(buffer, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
if (dll)
{
InitialiseRonin = GetProcAddress(dll, "InitialiseRonin");
}
if (!dll || InitialiseRonin == NULL)
{
return false;
}
return ((bool (*)())InitialiseRonin)();
}