2024-10-16 04:08:54 +07:00
|
|
|
#include <windows.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "util/dprintf.h"
|
|
|
|
#include "platform/opensslpatch.h"
|
|
|
|
|
2024-10-16 15:53:52 +07:00
|
|
|
static char* get_cpu_name() {
|
2024-10-16 04:08:54 +07:00
|
|
|
FILE* fp;
|
|
|
|
char buffer[128];
|
|
|
|
char* cpu_info = NULL;
|
|
|
|
|
|
|
|
fp = _popen("wmic cpu get Name", "r");
|
|
|
|
|
|
|
|
if (fp == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
fgets(buffer, sizeof(buffer), fp);
|
|
|
|
|
|
|
|
if (fgets(buffer, sizeof(buffer), fp) != NULL) {
|
|
|
|
cpu_info = (char*)malloc(strlen(buffer) + 1);
|
|
|
|
strcpy(cpu_info, buffer);
|
|
|
|
}
|
|
|
|
_pclose(fp);
|
|
|
|
|
|
|
|
if (cpu_info != NULL) {
|
|
|
|
cpu_info[strcspn(cpu_info, "\r\n")] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cpu_info;
|
|
|
|
}
|
|
|
|
|
2024-10-16 15:53:52 +07:00
|
|
|
static int check_cpu(char* cpuname) {
|
2024-10-16 04:08:54 +07:00
|
|
|
if (strstr(cpuname, "Core 2 Duo") || strstr(cpuname, "Core 2 Quad") ||
|
|
|
|
(strstr(cpuname, "Pentium") && !strstr(cpuname, "G")) || strstr(cpuname, "Celeron")) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strstr(cpuname, "Intel")) {
|
|
|
|
char* part = strtok(cpuname, " ");
|
|
|
|
while (part != NULL) {
|
|
|
|
if (part[0] == 'i' && strlen(part) >= 4) {
|
|
|
|
int gen = atoi(part + 1);
|
|
|
|
if (gen >= 10) {
|
2024-10-16 15:01:39 +07:00
|
|
|
dprintf("OpenSSL Patch: Intel Gen 10+ CPU Detected: %s\n", cpuname);
|
2024-10-16 04:08:54 +07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} else if (part[0] == 'G' && strlen(part) >= 4) {
|
|
|
|
int pentium = atoi(part + 1);
|
|
|
|
if (pentium / 1000 >= 6) {
|
2024-10-16 15:01:39 +07:00
|
|
|
dprintf("OpenSSL Patch: Intel Gen 10+ CPU Detected: %s\n", cpuname);
|
2024-10-16 04:08:54 +07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
part = strtok(NULL, " ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-10-16 15:53:52 +07:00
|
|
|
static void openssl_patch(void) {
|
2024-10-16 04:08:54 +07:00
|
|
|
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) {
|
2024-10-16 15:53:52 +07:00
|
|
|
dprintf("OpenSSL Patch: Applied successfully, set the user environment variable %s to %s\n", variablename, variablevalue);
|
2024-10-16 04:08:54 +07:00
|
|
|
} else {
|
2024-10-16 15:01:39 +07:00
|
|
|
dprintf("OpenSSL Patch: Error: Failed to set the user environment variable.\n");
|
2024-10-16 04:08:54 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
|
|
|
SendMessageTimeoutA(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment", SMTO_ABORTIFHUNG, 5000, NULL);
|
|
|
|
} else {
|
2024-10-16 15:01:39 +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-10-16 15:53:52 +07:00
|
|
|
char* cpuname = get_cpu_name();
|
2024-10-16 15:01:39 +07:00
|
|
|
if (cpuname == NULL) {
|
|
|
|
dprintf("OpenSSL Patch: Error: Unable to detect CPU.\n");
|
2024-10-18 13:34:25 +07:00
|
|
|
return S_FALSE;
|
2024-10-16 15:01:39 +07:00
|
|
|
}
|
|
|
|
|
2024-10-16 15:53:52 +07:00
|
|
|
if (check_cpu(cpuname)) {
|
|
|
|
openssl_patch();
|
2024-10-16 15:01:39 +07:00
|
|
|
}
|
2024-10-18 13:34:25 +07:00
|
|
|
|
2024-10-16 15:01:39 +07:00
|
|
|
free(cpuname);
|
2024-10-18 13:34:25 +07:00
|
|
|
return S_OK;
|
2024-10-16 15:01:39 +07:00
|
|
|
}
|