1 /* DllSecur.c -- DLL loading security
2 2016-10-04 : Igor Pavlov : Public domain */
14 typedef BOOL (WINAPI
*Func_SetDefaultDllDirectories
)(DWORD DirectoryFlags
);
16 #define MY_LOAD_LIBRARY_SEARCH_USER_DIRS 0x400
17 #define MY_LOAD_LIBRARY_SEARCH_SYSTEM32 0x800
19 static const char * const g_Dlls
=
35 void LoadSecurityDlls()
39 wchar_t buf
[MAX_PATH
+ 100];
42 // at Vista (ver 6.0) : CoCreateInstance(CLSID_ShellLink, ...) doesn't work after SetDefaultDllDirectories() : Check it ???
44 vi
.dwOSVersionInfoSize
= sizeof(vi
);
45 if (!GetVersionEx(&vi
) || vi
.dwMajorVersion
!= 6 || vi
.dwMinorVersion
!= 0)
47 Func_SetDefaultDllDirectories setDllDirs
= (Func_SetDefaultDllDirectories
)
48 GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "SetDefaultDllDirectories");
50 if (setDllDirs(MY_LOAD_LIBRARY_SEARCH_SYSTEM32
| MY_LOAD_LIBRARY_SEARCH_USER_DIRS
))
56 unsigned len
= GetSystemDirectoryW(buf
, MAX_PATH
+ 2);
57 if (len
== 0 || len
> MAX_PATH
)
62 unsigned pos
= (unsigned)lstrlenW(buf
);
64 if (buf
[pos
- 1] != '\\')
67 for (dll
= g_Dlls
; dll
[0] != 0;)
79 lstrcatW(buf
, L
".dll");
80 LoadLibraryExW(buf
, NULL
, LOAD_WITH_ALTERED_SEARCH_PATH
);