[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 14:54:27 CET 2017



On Fri, Mar 10, 2017, at 02:52 PM, Steve Lhomme wrote:
> On Fri, Mar 10, 2017 at 2:49 PM, Hugo Beauzée-Luyssen <hugo at beauzee.fr>
> wrote:
> > ---
> >  bin/winvlc.c | 36 ++++++++++++++++++++++++++++++++++++
> >  1 file changed, 36 insertions(+)
> >
> > diff --git a/bin/winvlc.c b/bin/winvlc.c
> > index ce44f5dd29..085a908fed 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()
> > +{
> > +#if _WIN32_WINNT < _WIN32_WINNT_WIN10
> > +    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;
> 
> Are these the official names ? Because they may collide when it's
> added with mingw or when compiled with MS headers.
> 
> > +#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
> >  #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);
> > --
> > 2.11.0
> >
> > _______________________________________________
> > vlc-devel mailing list
> > To unsubscribe or modify your subscription options:
> > https://mailman.videolan.org/listinfo/vlc-devel
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
They are the real names indeed, however:
- The struct doesn't exist when building for <Win10
- The function doesn't exist when building for <Win8

So I don't think any collision can occur.

Regards,

-- 
  Hugo Beauzée-Luyssen
  hugo at beauzee.fr


More information about the vlc-devel mailing list