From e58bc447426408a421932b236d9fdebdf123aa14 Mon Sep 17 00:00:00 2001 From: Madcow Date: Tue, 2 Jun 2026 18:56:14 +0200 Subject: [PATCH] Fix redundant literals and handle basepaths for RegOpenKeyExW calls --- src/main.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/main.c b/src/main.c index d51167f..6b2c857 100644 --- a/src/main.c +++ b/src/main.c @@ -3,24 +3,32 @@ #define WIN32_LEAN_AND_MEAN #include +// Configure suffix for registry subkey +#define SUBKEY_SUFFIX L"Vanilla" + +// No need to change these internal values +#define SUBKEY_ORIGINAL_SUBDIR L"Client" +#define SUBKEY_ORIGINAL_BASEPATH L"Software\\Blizzard Entertainment\\World of Warcraft" +#define SUBKEY_ORIGINAL_FULL SUBKEY_ORIGINAL_BASEPATH L"\\" SUBKEY_ORIGINAL_SUBDIR +#define SUBKEY_REPLACEMENT_BASEPATH SUBKEY_ORIGINAL_BASEPATH L" " SUBKEY_SUFFIX +#define SUBKEY_REPLACEMENT_FULL SUBKEY_REPLACEMENT_BASEPATH L"\\" SUBKEY_ORIGINAL_SUBDIR + // Original RegOpenKeyExW function pointer typedef LSTATUS (WINAPI *RegOpenKeyExW_t) (HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult); - RegOpenKeyExW_t OriginalRegOpenKeyExW = NULL; // Original RegCreateKeyExW function pointer -typedef LSTATUS (WINAPI *RegCreateKeyExW_t) (HKEY hKey, LPCWSTR lpSubKey, DWORD Reserved, LPWSTR lpClass, - DWORD dwOptions, REGSAM samDesired, const LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult, - LPDWORD lpdwDisposition); - +typedef LSTATUS (WINAPI *RegCreateKeyExW_t) (HKEY hKey, LPCWSTR lpSubKey, DWORD Reserved, LPWSTR lpClass, DWORD dwOptions, + REGSAM samDesired, const LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult, LPDWORD lpdwDisposition); RegCreateKeyExW_t OriginalRegCreateKeyExW = NULL; // Custom RegOpenKeyExW: Intercept registry calls and rewrite relevant subkeys LSTATUS WINAPI CustomRegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult) { - if (lstrcmpW(lpSubKey, L"Software\\Blizzard Entertainment\\World of Warcraft\\Client") == 0) { - LPCWSTR lpNewKey = L"Software\\Blizzard Entertainment\\World of Warcraft Vanilla\\Client"; - return OriginalRegOpenKeyExW(hKey, lpNewKey, ulOptions, samDesired, phkResult); + if (lstrcmpW(lpSubKey, SUBKEY_ORIGINAL_BASEPATH) == 0) { + lpSubKey = SUBKEY_REPLACEMENT_BASEPATH; + } else if (lstrcmpW(lpSubKey, SUBKEY_ORIGINAL_FULL) == 0) { + lpSubKey = SUBKEY_REPLACEMENT_FULL; } return OriginalRegOpenKeyExW(hKey, lpSubKey, ulOptions, samDesired, phkResult); @@ -30,16 +38,10 @@ LSTATUS WINAPI CustomRegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, LSTATUS WINAPI CustomRegCreateKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD Reserved, LPWSTR lpClass, DWORD dwOptions, REGSAM samDesired, const LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult, LPDWORD lpdwDisposition) { - if (lstrcmpW(lpSubKey, L"Software\\Blizzard Entertainment\\World of Warcraft") == 0) { - LPCWSTR lpNewKey = L"Software\\Blizzard Entertainment\\World of Warcraft Vanilla"; - return OriginalRegCreateKeyExW(hKey, lpNewKey, Reserved, lpClass, dwOptions, - samDesired, lpSecurityAttributes, phkResult, lpdwDisposition); - } - - if (lstrcmpW(lpSubKey, L"Software\\Blizzard Entertainment\\World of Warcraft\\Client") == 0) { - LPCWSTR lpNewKey = L"Software\\Blizzard Entertainment\\World of Warcraft Vanilla\\Client"; - return OriginalRegCreateKeyExW(hKey, lpNewKey, Reserved, lpClass, dwOptions, - samDesired, lpSecurityAttributes, phkResult, lpdwDisposition); + if (lstrcmpW(lpSubKey, SUBKEY_ORIGINAL_BASEPATH) == 0) { + lpSubKey = SUBKEY_REPLACEMENT_BASEPATH; + } else if (lstrcmpW(lpSubKey, SUBKEY_ORIGINAL_FULL) == 0) { + lpSubKey = SUBKEY_REPLACEMENT_FULL; } return OriginalRegCreateKeyExW(hKey, lpSubKey, Reserved, lpClass, dwOptions,