diff options
author | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2016-07-29 12:08:48 +0200 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2016-07-29 22:40:43 +0200 |
commit | 2389561406cb9e498008f884bed36e6e9d78ea80 (patch) | |
tree | 6c4fc77c885ccd5284b61650f2bcea70ed7c8647 /src/Common/Dlgcode.c | |
parent | a7f1ba05b4917cd22319cba1b5fd0adc3bd69c31 (diff) | |
download | VeraCrypt-2389561406cb9e498008f884bed36e6e9d78ea80.tar.gz VeraCrypt-2389561406cb9e498008f884bed36e6e9d78ea80.zip |
Windows: Use new Windows API to mitigate dll hijacking attacks.
Diffstat (limited to 'src/Common/Dlgcode.c')
-rw-r--r-- | src/Common/Dlgcode.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c index 76e71ac8..c9955714 100644 --- a/src/Common/Dlgcode.c +++ b/src/Common/Dlgcode.c @@ -247,8 +247,13 @@ HMODULE hwinscarddll = NULL; #define BASE_SEARCH_PATH_PERMANENT 0x00008000 #endif +#ifndef LOAD_LIBRARY_SEARCH_SYSTEM32 +#define LOAD_LIBRARY_SEARCH_SYSTEM32 0x00000800 +#endif + typedef BOOL (WINAPI *SetDllDirectoryPtr)(LPCWSTR lpPathName); typedef BOOL (WINAPI *SetSearchPathModePtr)(DWORD Flags); +typedef BOOL (WINAPI *SetDefaultDllDirectoriesPtr)(DWORD DirectoryFlags); typedef void (WINAPI *InitCommonControlsPtr)(void); @@ -269,6 +274,7 @@ typedef BOOL (WINAPI *ChangeWindowMessageFilterPtr) (UINT, DWORD); SetDllDirectoryPtr SetDllDirectoryFn = NULL; SetSearchPathModePtr SetSearchPathModeFn = NULL; +SetDefaultDllDirectoriesPtr SetDefaultDllDirectoriesFn = NULL; ImageList_CreatePtr ImageList_CreateFn = NULL; ImageList_AddPtr ImageList_AddFn = NULL; @@ -2565,11 +2571,14 @@ void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine) /* remove current directory from dll search path */ SetDllDirectoryFn = (SetDllDirectoryPtr) GetProcAddress (GetModuleHandle(L"kernel32.dll"), "SetDllDirectoryW"); SetSearchPathModeFn = (SetSearchPathModePtr) GetProcAddress (GetModuleHandle(L"kernel32.dll"), "SetSearchPathMode"); + SetDefaultDllDirectoriesFn = (SetDefaultDllDirectoriesPtr) GetProcAddress (GetModuleHandle(L"kernel32.dll"), "SetDefaultDllDirectories"); if (SetDllDirectoryFn) SetDllDirectoryFn (L""); if (SetSearchPathModeFn) SetSearchPathModeFn (BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE | BASE_SEARCH_PATH_PERMANENT); + if (SetDefaultDllDirectoriesFn) + SetDefaultDllDirectoriesFn (LOAD_LIBRARY_SEARCH_SYSTEM32); InitOSVersionInfo(); @@ -2591,7 +2600,9 @@ void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine) LoadSystemDll (L"secur32.dll", &hsecur32dll, TRUE, SRC_POS); LoadSystemDll (L"msasn1.dll", &hmsasn1dll, TRUE, SRC_POS); LoadSystemDll (L"Usp10.DLL", &hUsp10Dll, TRUE, SRC_POS); - LoadSystemDll (L"UXTheme.dll", &hUXThemeDll, TRUE, SRC_POS); + if (IsOSAtLeast (WIN_7)) + LoadSystemDll (L"dwmapi.dll", &hdwmapidll, TRUE, SRC_POS); + LoadSystemDll (L"UXTheme.dll", &hUXThemeDll, TRUE, SRC_POS); LoadSystemDll (L"msls31.dll", &hMsls31, TRUE, SRC_POS); LoadSystemDll (L"SETUPAPI.DLL", &hSetupDll, FALSE, SRC_POS); @@ -2634,8 +2645,6 @@ void InitApp (HINSTANCE hInstance, wchar_t *lpszCommandLine) LoadSystemDll (L"devobj.dll", &hdevobjdll, TRUE, SRC_POS); LoadSystemDll (L"powrprof.dll", &hpowrprofdll, TRUE, SRC_POS); - LoadSystemDll (L"dwmapi.dll", &hdwmapidll, TRUE, SRC_POS); - LoadSystemDll (L"crypt32.dll", &hcrypt32dll, TRUE, SRC_POS); LoadSystemDll (L"bcrypt.dll", &hbcryptdll, TRUE, SRC_POS); |