From d957b6bcd11a3d837498026277a3f42c711b613a Mon Sep 17 00:00:00 2001 From: Alberto Ortega Date: Sun, 31 May 2015 16:31:27 +0200 Subject: [PATCH] Handle registry keys redirection in x86_64 --- pafish/utils.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pafish/utils.c b/pafish/utils.c index 9b18c99..bd9c126 100644 --- a/pafish/utils.c +++ b/pafish/utils.c @@ -12,6 +12,9 @@ #include "utils.h" #include "types.h" +#define KEY_WOW64_32KEY 0x0200 +#define KEY_WOW64_64KEY 0x0100 + /** * Prototypes for the Wow64 API's since they aren't available in all Windows * versions, most notably Windows XP 32 bits. @@ -63,7 +66,12 @@ inline int pafish_exists_regkey(HKEY hKey, char * regkey_s) { HKEY regkey; LONG ret; - ret = RegOpenKeyEx(hKey, regkey_s, 0, KEY_READ, ®key); + if (pafish_iswow64()) { + ret = RegOpenKeyEx(hKey, regkey_s, 0, KEY_READ | KEY_WOW64_64KEY, ®key); + } + else { + ret = RegOpenKeyEx(hKey, regkey_s, 0, KEY_READ, ®key); + } if (ret == ERROR_SUCCESS) { RegCloseKey(regkey); return TRUE; @@ -84,7 +92,12 @@ inline int pafish_exists_regkey_value_str(HKEY hKey, char * regkey_s, char * val strncpy(lookup_str, lookup, lookup_size+sizeof(char)); size = sizeof(value); - ret = RegOpenKeyEx(hKey, regkey_s, 0, KEY_READ, ®key); + if (pafish_iswow64()) { + ret = RegOpenKeyEx(hKey, regkey_s, 0, KEY_READ | KEY_WOW64_64KEY, ®key); + } + else { + ret = RegOpenKeyEx(hKey, regkey_s, 0, KEY_READ, ®key); + } if (ret == ERROR_SUCCESS) { ret = RegQueryValueEx(regkey, value_s, NULL, NULL, (BYTE*)value, &size); RegCloseKey(regkey);