forked from TeamTofuShop/segatools
Develop a new/better method to detect cpu using intrinsic functions (__cpuid and __cpuidex)
This commit is contained in:
@ -1,59 +1,26 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <intrin.h>
|
||||||
#include "util/dprintf.h"
|
#include "util/dprintf.h"
|
||||||
#include "platform/opensslpatch.h"
|
#include "platform/opensslpatch.h"
|
||||||
|
|
||||||
static char* get_cpu_name() {
|
int check_cpu() {
|
||||||
FILE* fp;
|
int cpui[4] = {0};
|
||||||
char buffer[128];
|
|
||||||
char* cpu_info = NULL;
|
|
||||||
|
|
||||||
fp = _popen("wmic cpu get Name", "r");
|
__cpuid(cpui, 0);
|
||||||
|
int nIds_ = cpui[0];
|
||||||
|
|
||||||
if (fp == NULL) {
|
char vendor[0x20] = {0};
|
||||||
return NULL;
|
*((int*)vendor) = cpui[1];
|
||||||
}
|
*((int*)(vendor + 4)) = cpui[3];
|
||||||
|
*((int*)(vendor + 8)) = cpui[2];
|
||||||
|
|
||||||
fgets(buffer, sizeof(buffer), fp);
|
int isIntel = (strcmp(vendor, "GenuineIntel") == 0);
|
||||||
|
|
||||||
if (fgets(buffer, sizeof(buffer), fp) != NULL) {
|
if (isIntel && nIds_ >= 7) {
|
||||||
cpu_info = (char*)malloc(strlen(buffer) + 1);
|
__cpuidex(cpui, 7, 0);
|
||||||
strcpy(cpu_info, buffer);
|
return (cpui[1] & (1 << 29)) != 0;
|
||||||
}
|
|
||||||
_pclose(fp);
|
|
||||||
|
|
||||||
if (cpu_info != NULL) {
|
|
||||||
cpu_info[strcspn(cpu_info, "\r\n")] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return cpu_info;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int check_cpu(char* cpuname) {
|
|
||||||
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) {
|
|
||||||
dprintf("OpenSSL Patch: Intel Gen 10+ CPU Detected: %s\n", cpuname);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
} else if (part[0] == 'G' && strlen(part) >= 4) {
|
|
||||||
int pentium = atoi(part + 1);
|
|
||||||
if (pentium / 1000 >= 6) {
|
|
||||||
dprintf("OpenSSL Patch: Intel Gen 10+ CPU Detected: %s\n", cpuname);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
part = strtok(NULL, " ");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -88,16 +55,9 @@ HRESULT openssl_patch_apply(const struct openssl_patch_config *cfg) {
|
|||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* cpuname = get_cpu_name();
|
if (check_cpu()) {
|
||||||
if (cpuname == NULL) {
|
openssl_patch();
|
||||||
dprintf("OpenSSL Patch: Error: Unable to detect CPU.\n");
|
|
||||||
return S_FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (check_cpu(cpuname)) {
|
|
||||||
openssl_patch();
|
|
||||||
}
|
|
||||||
|
|
||||||
free(cpuname);
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user