[vlc-devel] [PATCH 1/3] core: win32: only load system DLLs that are not known DLLs from System32

Steve Lhomme robux4 at videolabs.io
Fri Mar 10 09:52:30 CET 2017


* normaliz.dll
* Windows.Networking.dll

https://blogs.msdn.microsoft.com/larryosterman/2004/07/19/what-are-known-dlls-anyway/
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx
https://windowssucks.wordpress.com/knowndlls/
---
 src/modules/modules.h |  4 ++++
 src/network/udp.c     |  4 +++-
 src/text/url.c        |  2 +-
 src/win32/plugin.c    | 39 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/src/modules/modules.h b/src/modules/modules.h
index 60a36e7d49..f5f7cf1303 100644
--- a/src/modules/modules.h
+++ b/src/modules/modules.h
@@ -132,4 +132,8 @@ vlc_plugin_t *vlc_cache_lookup(vlc_plugin_t **, const char *relpath);
 
 void CacheSave(vlc_object_t *, const char *, vlc_plugin_t *const *, size_t);
 
+#ifdef _WIN32
+HMODULE win32_LoadSyslib(const TCHAR *libname);
+#endif
+
 #endif /* !LIBVLC_MODULES_H */
diff --git a/src/network/udp.c b/src/network/udp.c
index d098fb1425..e81fc5b9c5 100644
--- a/src/network/udp.c
+++ b/src/network/udp.c
@@ -36,6 +36,8 @@
 #include <errno.h>
 #include <assert.h>
 
+#include "modules/modules.h"
+
 #include <vlc_network.h>
 
 #ifdef _WIN32
@@ -105,7 +107,7 @@ static int net_SetupDgramSocket (vlc_object_t *p_obj, int fd,
      * receive buffer if that isn't present
      */
 #if (_WIN32_WINNT < _WIN32_WINNT_WIN8)
-    HINSTANCE h_Network = LoadLibrary(TEXT("Windows.Networking.dll"));
+    HMODULE h_Network = win32_LoadSyslib(TEXT("Windows.Networking.dll"));
     if( (h_Network == NULL) ||
         (GetProcAddress( h_Network, "SetSocketMediaStreamingMode" ) == NULL ) )
     {
diff --git a/src/text/url.c b/src/text/url.c
index 1b602b599e..05d1e66046 100644
--- a/src/text/url.c
+++ b/src/text/url.c
@@ -837,7 +837,7 @@ char *vlc_uri_fixup(const char *str)
 #  define IDN_ALLOW_UNASSIGNED 0x01
 static int IdnToAscii(DWORD flags, LPCWSTR str, int len, LPWSTR buf, int size)
 {
-    HMODULE h = LoadLibrary(_T("Normaliz.dll"));
+    HMODULE h = win32_LoadSyslib(TEXT("Normaliz.dll"));
     if (h == NULL)
     {
         errno = ENOSYS;
diff --git a/src/win32/plugin.c b/src/win32/plugin.c
index 1a65521fca..d02236c754 100644
--- a/src/win32/plugin.c
+++ b/src/win32/plugin.c
@@ -133,3 +133,42 @@ void *module_Lookup( module_handle_t handle, const char *psz_function )
 {
     return (void *)GetProcAddress( handle, (char *)psz_function );
 }
+
+HMODULE win32_LoadSyslib(const TCHAR *libname)
+{
+    HMODULE module;
+    bool has_KB2533623 = true;
+#if (_WIN32_WINNT < _WIN32_WINNT_WIN8)
+    /* check for KB2533623 */
+    if (GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")),
+                                       "SetDefaultDllDirectories") == NULL)
+        has_KB2533623 = false;
+#endif
+
+    if (has_KB2533623)
+        module = LoadLibraryEx(libname, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
+    else
+    {
+        /* force the path of the DLL inside system32 */
+        TCHAR *slibname = (TCHAR*)libname;
+        DWORD systemLen = GetSystemDirectory(NULL, 0);
+        if (systemLen) {
+            systemLen += 1 + _tcslen(libname);
+            slibname = malloc(systemLen * sizeof(*slibname));
+            if (likely(slibname != NULL))
+            {
+                if (GetSystemDirectory(slibname, systemLen))
+                {
+                    _tcsncat(slibname, _T("\\"), systemLen);
+                    _tcsncat(slibname, libname, systemLen);
+                }
+            }
+        }
+
+        module = LoadLibrary(slibname);
+
+        if (slibname != libname)
+            free(slibname);
+    }
+    return module;
+}
-- 
2.11.1



More information about the vlc-devel mailing list