From 537b1fa3840087963e53b1953f97f1fed5f3eeea Mon Sep 17 00:00:00 2001 From: Will Xyen Date: Thu, 19 May 2022 20:52:45 -0700 Subject: [PATCH] sdvxhook2: fix crash when using sdvxhook2 on certain OS versions --- src/main/sdvxhook2/nvapi.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/sdvxhook2/nvapi.c b/src/main/sdvxhook2/nvapi.c index ec1baf5..ec5f27e 100644 --- a/src/main/sdvxhook2/nvapi.c +++ b/src/main/sdvxhook2/nvapi.c @@ -1,4 +1,4 @@ -#define LOG_MODULE "power-hook" +#define LOG_MODULE "nvapi-hook" // clang-format off // Don't format because the order is important here @@ -33,10 +33,14 @@ static struct hook_symbol nvapihook_kernel_syms[] = { static void *my_GetProcAddress(HMODULE dll, const char *name) { - if (strcmp("nvapi_QueryInterface", name) == 0) { - log_info("Request for stub %s", name); - real_nvapi_QueryInterface = real_GetProcAddress(dll, name); - return &my_nvapi_QueryInterface; + if (name != NULL && ((intptr_t) name) > UINT16_MAX) { + // only strcmp is non-ordinal + // https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getprocaddress + if (strcmp("nvapi_QueryInterface", name) == 0) { + log_info("Request for stub %s", name); + real_nvapi_QueryInterface = real_GetProcAddress(dll, name); + return &my_nvapi_QueryInterface; + } } // log_warning("Request for unknown stub %s", name);