2024-10-16 04:08:54 +07:00
|
|
|
#include <windows.h>
|
2024-12-23 21:03:35 +01:00
|
|
|
|
|
|
|
#include <assert.h>
|
2024-10-16 04:08:54 +07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2024-11-02 00:26:31 +07:00
|
|
|
#include <intrin.h>
|
2024-12-23 21:03:35 +01:00
|
|
|
|
2024-10-16 04:08:54 +07:00
|
|
|
#include "util/dprintf.h"
|
|
|
|
#include "platform/opensslpatch.h"
|
|
|
|
|
2024-11-02 00:26:31 +07:00
|
|
|
int check_cpu() {
|
|
|
|
int cpui[4] = {0};
|
2024-10-16 04:08:54 +07:00
|
|
|
|
2024-11-02 00:26:31 +07:00
|
|
|
__cpuid(cpui, 0);
|
|
|
|
int nIds_ = cpui[0];
|
2024-10-16 04:08:54 +07:00
|
|
|
|
2024-11-02 00:26:31 +07:00
|
|
|
char vendor[0x20] = {0};
|
|
|
|
*((int*)vendor) = cpui[1];
|
|
|
|
*((int*)(vendor + 4)) = cpui[3];
|
|
|
|
*((int*)(vendor + 8)) = cpui[2];
|
2024-10-16 04:08:54 +07:00
|
|
|
|
2024-11-02 00:26:31 +07:00
|
|
|
int isIntel = (strcmp(vendor, "GenuineIntel") == 0);
|
2024-10-16 04:08:54 +07:00
|
|
|
|
2024-11-02 00:26:31 +07:00
|
|
|
if (isIntel && nIds_ >= 7) {
|
|
|
|
__cpuidex(cpui, 7, 0);
|
|
|
|
return (cpui[1] & (1 << 29)) != 0;
|
2024-10-16 04:08:54 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-11-26 01:40:57 +07:00
|
|
|
static int is_env_variable_set(const char* variablename, const char* expectedvalue) {
|
|
|
|
char currentvalue[256];
|
|
|
|
DWORD length = GetEnvironmentVariableA(variablename, currentvalue, sizeof(currentvalue));
|
2024-10-16 04:08:54 +07:00
|
|
|
|
2024-11-26 01:40:57 +07:00
|
|
|
if (length > 0 && length < sizeof(currentvalue)) {
|
|
|
|
return strcmp(currentvalue, expectedvalue) == 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2024-11-05 00:48:21 +07:00
|
|
|
|
|
|
|
static void openssl_patch(void) {
|
2024-11-26 01:40:57 +07:00
|
|
|
const char* variablename = "OPENSSL_ia32cap";
|
|
|
|
const char* variablevalue = "~0x20000000";
|
|
|
|
|
|
|
|
if (is_env_variable_set(variablename, variablevalue)) {
|
|
|
|
return;
|
|
|
|
}
|
2024-10-16 04:08:54 +07:00
|
|
|
|
2024-11-26 01:40:57 +07:00
|
|
|
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. User environment variable %s set to %s\n", variablename, variablevalue);
|
|
|
|
SendMessageTimeoutA(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment", SMTO_ABORTIFHUNG, 5000, NULL);
|
|
|
|
dprintf(
|
|
|
|
"Please close this windows and reopen the game to enjoy.\n"
|
|
|
|
);
|
|
|
|
ExitProcess(0);
|
|
|
|
} else {
|
|
|
|
dprintf("OpenSSL Patch: Error: Failed to set the user environment variable.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
2024-10-16 04:08:54 +07:00
|
|
|
} else {
|
2024-11-26 01:40:57 +07:00
|
|
|
dprintf("OpenSSL Patch: Error: Failed to open the user environment registry key.\n");
|
2024-10-16 04:08:54 +07:00
|
|
|
}
|
|
|
|
}
|
2024-10-16 15:01:39 +07:00
|
|
|
|
2024-10-18 13:34:25 +07:00
|
|
|
HRESULT openssl_patch_apply(const struct openssl_patch_config *cfg) {
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
assert(cfg != NULL);
|
|
|
|
|
|
|
|
if (!cfg->enable) {
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
2024-11-02 00:26:31 +07:00
|
|
|
if (check_cpu()) {
|
|
|
|
openssl_patch();
|
2024-10-16 15:01:39 +07:00
|
|
|
}
|
|
|
|
|
2024-10-18 13:34:25 +07:00
|
|
|
return S_OK;
|
2024-11-02 00:26:31 +07:00
|
|
|
}
|