From e29a640ddd9efe90a7b2f89998e29b26c405b886 Mon Sep 17 00:00:00 2001 From: Richard Stanway Date: Thu, 28 Nov 2024 22:53:22 +0100 Subject: [PATCH] obs-ffmpeg, win-capture: Use better default DLL directory settings --- plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c | 7 +++++++ .../get-graphics-offsets/get-graphics-offsets.c | 7 +++++++ plugins/win-capture/inject-helper/inject-helper.c | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c b/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c index 7aefe7592..02b99b03b 100644 --- a/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c +++ b/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c @@ -1152,6 +1152,13 @@ int main(int argc, char *argv[]) char **argv; SetErrorMode(SEM_FAILCRITICALERRORS); + SetSearchPathMode(BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE | BASE_SEARCH_PATH_PERMANENT); + SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); + SetDllDirectoryW(L""); + + PROCESS_MITIGATION_IMAGE_LOAD_POLICY policy = {0}; + policy.PreferSystem32Images = 1; + SetProcessMitigationPolicy(ProcessImageLoadPolicy, &policy, sizeof(policy)); argv = malloc(argc * sizeof(char *)); for (int i = 0; i < argc; i++) { diff --git a/plugins/win-capture/get-graphics-offsets/get-graphics-offsets.c b/plugins/win-capture/get-graphics-offsets/get-graphics-offsets.c index a813617d9..a6ac6894c 100644 --- a/plugins/win-capture/get-graphics-offsets/get-graphics-offsets.c +++ b/plugins/win-capture/get-graphics-offsets/get-graphics-offsets.c @@ -17,6 +17,13 @@ int main(int argc, char *argv[]) wc.lpszClassName = DUMMY_WNDCLASS; SetErrorMode(SEM_FAILCRITICALERRORS); + SetSearchPathMode(BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE | BASE_SEARCH_PATH_PERMANENT); + SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); + SetDllDirectoryW(L""); + + PROCESS_MITIGATION_IMAGE_LOAD_POLICY policy = {0}; + policy.PreferSystem32Images = 1; + SetProcessMitigationPolicy(ProcessImageLoadPolicy, &policy, sizeof(policy)); if (!RegisterClassA(&wc)) { printf("failed to register '%s'\n", DUMMY_WNDCLASS); diff --git a/plugins/win-capture/inject-helper/inject-helper.c b/plugins/win-capture/inject-helper/inject-helper.c index ce21f2d70..c14fa9423 100644 --- a/plugins/win-capture/inject-helper/inject-helper.c +++ b/plugins/win-capture/inject-helper/inject-helper.c @@ -97,6 +97,14 @@ int main(void) int ret = INJECT_ERROR_INVALID_PARAMS; SetErrorMode(SEM_FAILCRITICALERRORS); + SetSearchPathMode(BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE | BASE_SEARCH_PATH_PERMANENT); + SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); + SetDllDirectoryW(L""); + + PROCESS_MITIGATION_IMAGE_LOAD_POLICY policy = {0}; + policy.PreferSystem32Images = 1; + SetProcessMitigationPolicy(ProcessImageLoadPolicy, &policy, sizeof(policy)); + load_debug_privilege(); pCommandLineW = GetCommandLineW();