From 7e78c17ace4fd4d5ae58166af9fbfb45cb7123ad Mon Sep 17 00:00:00 2001 From: jp9000 Date: Fri, 28 Feb 2020 23:24:18 -0800 Subject: [PATCH] win-capture: Check hook version before capture init Checks the hook version to ensure compatibility with hook DLL. It's unlikely it'll ever be necessary to increment the hook version, but this is just a precautionary thing that allows a hook DLL to make sure it's rejected by an older OBS version if needed. Again however, very unlikely that the major version will ever be incremented. --- plugins/win-capture/game-capture.c | 12 ++++++++++++ plugins/win-capture/graphics-hook-info.h | 6 ++++++ plugins/win-capture/graphics-hook/graphics-hook.c | 5 +++++ 3 files changed, 23 insertions(+) diff --git a/plugins/win-capture/game-capture.c b/plugins/win-capture/game-capture.c index 6ca146d9d..5530e5629 100644 --- a/plugins/win-capture/game-capture.c +++ b/plugins/win-capture/game-capture.c @@ -10,6 +10,7 @@ #include "obfuscate.h" #include "inject-library.h" #include "graphics-hook-info.h" +#include "graphics-hook-ver.h" #include "window-helpers.h" #include "cursor-capture.h" #include "app-helpers.h" @@ -1610,6 +1611,17 @@ static bool start_capture(struct game_capture *gc) { debug("Starting capture"); + /* prevent from using a DLL version that's higher than current */ + if (gc->global_hook_info->hook_ver_major > HOOK_VER_MAJOR) { + warn("cannot initialize hook, DLL hook version is " + "%" PRIu32 ".%" PRIu32 + ", current plugin hook major version is %d.%d", + gc->global_hook_info->hook_ver_major, + gc->global_hook_info->hook_ver_minor, HOOK_VER_MAJOR, + HOOK_VER_MINOR); + return false; + } + if (gc->global_hook_info->type == CAPTURE_TYPE_MEMORY) { if (!init_shmem_capture(gc)) { return false; diff --git a/plugins/win-capture/graphics-hook-info.h b/plugins/win-capture/graphics-hook-info.h index 04546e489..17f93574b 100644 --- a/plugins/win-capture/graphics-hook-info.h +++ b/plugins/win-capture/graphics-hook-info.h @@ -80,6 +80,10 @@ struct graphics_offsets { }; struct hook_info { + /* hook version */ + uint32_t hook_ver_major; + uint32_t hook_ver_minor; + /* capture info */ enum capture_type type; uint32_t window; @@ -101,6 +105,8 @@ struct hook_info { /* hook addresses */ struct graphics_offsets offsets; + + uint32_t reserved[128]; }; #pragma pack(pop) diff --git a/plugins/win-capture/graphics-hook/graphics-hook.c b/plugins/win-capture/graphics-hook/graphics-hook.c index abe789131..2dc83a80c 100644 --- a/plugins/win-capture/graphics-hook/graphics-hook.c +++ b/plugins/win-capture/graphics-hook/graphics-hook.c @@ -1,6 +1,7 @@ #include #include #include "graphics-hook.h" +#include "../graphics-hook-ver.h" #include "../obfuscate.h" #include "../funchook.h" @@ -539,6 +540,8 @@ bool capture_init_shtex(struct shtex_data **data, HWND window, uint32_t base_cx, *data = shmem_info; (*data)->tex_handle = (uint32_t)handle; + global_hook_info->hook_ver_major = HOOK_VER_MAJOR; + global_hook_info->hook_ver_minor = HOOK_VER_MINOR; global_hook_info->window = (uint32_t)(uintptr_t)window; global_hook_info->type = CAPTURE_TYPE_TEXTURE; global_hook_info->format = format; @@ -732,6 +735,8 @@ bool capture_init_shmem(struct shmem_data **data, HWND window, uint32_t base_cx, (*data)->tex1_offset = (uint32_t)align_pos; (*data)->tex2_offset = (*data)->tex1_offset + aligned_tex; + global_hook_info->hook_ver_major = HOOK_VER_MAJOR; + global_hook_info->hook_ver_minor = HOOK_VER_MINOR; global_hook_info->window = (uint32_t)(uintptr_t)window; global_hook_info->type = CAPTURE_TYPE_MEMORY; global_hook_info->format = format;