From 8aef1cfa79f1f04bf2cf036ec20b45b5fb5ea1b7 Mon Sep 17 00:00:00 2001 From: KagamineHaku Date: Tue, 5 Nov 2024 00:48:21 +0700 Subject: [PATCH] Change method set environment variable to current process only using "SetEnvironmentVariableW" --- platform/opensslpatch.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/platform/opensslpatch.c b/platform/opensslpatch.c index 4db287c..2447a0a 100644 --- a/platform/opensslpatch.c +++ b/platform/opensslpatch.c @@ -26,23 +26,36 @@ int check_cpu() { return 0; } +//Set User's Environment variable via registry +// static void openssl_patch(void) { +// const char* variablename = "OPENSSL_ia32cap"; +// const char* variablevalue = "~0x20000000"; + +// HKEY hKey; +// if (RegOpenKeyExA(HKEY_CURRENT_USER, "Environment", 0, KEY_SET_VALUE, &hKey) == ERROR_SUCCESS) { +// if (RegSetValueExA(hKey, variablename, 0, REG_SZ, (const BYTE*)variablevalue, strlen(variablevalue) + 1) == ERROR_SUCCESS) { +// dprintf("OpenSSL Patch: Applied successfully, set the user environment variable %s to %s\n", variablename, variablevalue); +// } else { +// dprintf("OpenSSL Patch: Error: Failed to set the user environment variable.\n"); +// } + +// RegCloseKey(hKey); + +// SendMessageTimeoutA(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment", SMTO_ABORTIFHUNG, 5000, NULL); +// } else { +// dprintf("OpenSSL Patch: Error: Failed to open the user environment registry key.\n"); +// } +// } + +//Set environment variable for current process static void openssl_patch(void) { - const char* variablename = "OPENSSL_ia32cap"; - const char* variablevalue = "~0x20000000"; + const wchar_t* variablename = L"OPENSSL_ia32cap"; + const wchar_t* variablevalue = L"~0x20000000"; - HKEY hKey; - if (RegOpenKeyExA(HKEY_CURRENT_USER, "Environment", 0, KEY_SET_VALUE, &hKey) == ERROR_SUCCESS) { - if (RegSetValueExA(hKey, variablename, 0, REG_SZ, (const BYTE*)variablevalue, strlen(variablevalue) + 1) == ERROR_SUCCESS) { - dprintf("OpenSSL Patch: Applied successfully, set the user environment variable %s to %s\n", variablename, variablevalue); - } else { - dprintf("OpenSSL Patch: Error: Failed to set the user environment variable.\n"); - } - - RegCloseKey(hKey); - - SendMessageTimeoutA(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment", SMTO_ABORTIFHUNG, 5000, NULL); + if (SetEnvironmentVariableW(variablename, variablevalue)) { + dprintf("OpenSSL Patch: Applied successfully, set the environment variable %ls to %ls\n", variablename, variablevalue); } else { - dprintf("OpenSSL Patch: Error: Failed to open the user environment registry key.\n"); + dprintf("OpenSSL Patch: Error: Failed to set the environment variable.\n"); } }