blob: 67e4159c8ea29b57b5739da4609327c245bb7204 (
plain)
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
|
#include <Windows.h>
#include <delayimp.h>
#pragma comment(lib, "delayimp.lib")
static HANDLE hUcrtDll = nullptr;
EXTERN_C HANDLE WINAPI hook(unsigned mode, PDelayLoadInfo)
{
if (mode == dliNotePreLoadLibrary && hUcrtDll == nullptr) {
wchar_t wszPath[MAX_PATH];
GetModuleFileNameW(nullptr, wszPath, _countof(wszPath));
// if current dir isn't set
for (int i = lstrlenW(wszPath); i >= 0; i--)
if (wszPath[i] == '\\') {
wszPath[i] = 0;
break;
}
SetCurrentDirectoryW(wszPath);
lstrcatW(wszPath, L"\\libs");
SetDllDirectoryW(wszPath);
#ifdef _DEBUG
lstrcatW(wszPath, L"\\ucrtbased.dll");
#else
lstrcatW(wszPath, L"\\ucrtbase.dll");
#endif
hUcrtDll = LoadLibraryW(wszPath);
}
return 0;
}
EXTERN_C const PfnDliHook __pfnDliNotifyHook2 = (PfnDliHook)&hook;
|