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

Hugo Beauzée-Luyssen git at videolan.org
Fri Mar 10 19:08:51 CET 2017


vlc/vlc-2.2 | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Fri Mar 10 14:48:51 2017 +0100| [054cf24557164f79045d773efe7da87c4fe357de] | committer: Jean-Baptiste Kempf

winvlc: Try to load DLLs from system32 before any other folder

(cherry picked from commit 99db47431b6b2063379dd88cab2b9d71ad24b3f9)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=054cf24557164f79045d773efe7da87c4fe357de
---

 bin/winvlc.c | 35 +++++++++++++++++++++++++++++++++++
 configure.ac |  8 ++++++++
 2 files changed, 43 insertions(+)

diff --git a/bin/winvlc.c b/bin/winvlc.c
index 6644ab3..001a286 100644
--- a/bin/winvlc.c
+++ b/bin/winvlc.c
@@ -78,7 +78,38 @@ static BOOL SetDefaultDllDirectories_(DWORD flags)
     return SetDefaultDllDirectoriesReal(flags);
 }
 # define SetDefaultDllDirectories SetDefaultDllDirectories_
+
+#endif
+
+static void PrioritizeSystem32(void)
+{
+#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 = { .Flags = 0 };
+    m.PreferSystem32Images = 1;
+    SetProcessMitigationPolicy( 10 /* ProcessImageLoadPolicy */, &m, sizeof( m ) );
+}
 
 int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
                     LPSTR lpCmdLine,
@@ -124,6 +155,10 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
     }
 
     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 8ad4a10..7b35401 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4183,6 +4183,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



More information about the vlc-commits mailing list