[vlc-devel] [PATCH] winvlc: Try to load DLLs from system32 before any other folder

Hugo Beauzée-Luyssen hugo at beauzee.fr
Fri Mar 10 15:35:23 CET 2017


---
 bin/winvlc.c | 36 ++++++++++++++++++++++++++++++++++++
 configure.ac |  8 ++++++++
 2 files changed, 44 insertions(+)

diff --git a/bin/winvlc.c b/bin/winvlc.c
index bc427d6b55..c5033e1925 100644
--- a/bin/winvlc.c
+++ b/bin/winvlc.c
@@ -78,7 +78,39 @@ static BOOL SetDefaultDllDirectories_(DWORD flags)
     return SetDefaultDllDirectoriesReal(flags);
 }
 # define SetDefaultDllDirectories SetDefaultDllDirectories_
+
+#endif
+
+static void PrioritizeSystem32()
+{
+#ifndef HAVE_PROCESS_MITIGATION_IMAGE_LOAD_POLICY
+    typedef struct _PROCESS_MITIGATION_IMAGE_LOAD_POLICY {
+      union {
+        DWORD  Flags;
+        struct {
+          DWORD NoRemoteImages  :1;
+          DWORD NoLowMandatoryLabelImages  :1;
+          DWORD PreferSystem32Images  :1;
+          DWORD ReservedFlags  :29;
+        };
+      };
+    } PROCESS_MITIGATION_IMAGE_LOAD_POLICY;
+#endif
+#if _WIN32_WINNT < _WIN32_WINNT_WIN8
+    BOOL WINAPI (*SetProcessMitigationPolicy)(PROCESS_MITIGATION_POLICY, PVOID, SIZE_T);
+    HINSTANCE h_Kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
+    if ( !h_Kernel32 )
+        return;
+    SetProcessMitigationPolicy = (BOOL (WINAPI *)(PROCESS_MITIGATION_POLICY, PVOID, SIZE_T))
+                                   GetProcAddress(h_Kernel32, "SetProcessMitigationPolicy");
+    if (SetProcessMitigationPolicy == NULL)
+        return;
 #endif
+    PROCESS_MITIGATION_IMAGE_LOAD_POLICY m;
+    m.Flags = 0;
+    m.PreferSystem32Images = 1;
+    SetProcessMitigationPolicy( 10 /* ProcessImageLoadPolicy */, &m, sizeof( m ) );
+}
 
 int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
                     LPSTR lpCmdLine,
@@ -126,6 +158,10 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
      * will search in SYSTEM32 only
      * */
     SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32);
+    /***
+     * Load DLLs from system32 before any other folder (when possible)
+     */
+    PrioritizeSystem32();
 
     /* Args */
     wchar_t **wargv = CommandLineToArgvW (GetCommandLine (), &argc);
diff --git a/configure.ac b/configure.ac
index 8471e3fdf6..71f19c43f9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4119,6 +4119,14 @@ AS_IF([test "${with_kde_solid}" != "no"], [
 AC_SUBST(soliddatadir)
 AM_CONDITIONAL(KDE_SOLID, [test "x${soliddatadir}" != "x"])
 
+dnl
+dnl Check wether we have the PROCESS_MITIGATION_IMAGE_LOAD_POLICY 
+dnl It should only be available when building for win10, but some SDKs define it unconditionnaly
+dnl
+if test "${SYS}" = "mingw32"; then
+    AC_CHECK_TYPES([PROCESS_MITIGATION_IMAGE_LOAD_POLICY],,,[#include <windows.h>])
+fi
+
 EXTEND_HELP_STRING([Components:])
 
 dnl
-- 
2.11.0



More information about the vlc-devel mailing list