1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
#include <cctype>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
static std::string s2lower(const std::string& string)
{
std::ostringstream ss;
for (char c : string)
ss << char(std::tolower(c));
return ss.str();
}
int main()
{
static char brand_string[48 + 1];
std::uint32_t eax, ebx, ecx, edx;
bool emulated = false;
asm volatile("cpuid":"=a"(0x80000002):"a"(eax), "b"(ebx), "c"(ecx), "d"(edx));
strncpy(brand_string + 0, (const char*)eax, 4);
strncpy(brand_string + 4, (const char*)ebx, 4);
strncpy(brand_string + 8, (const char*)ecx, 4);
strncpy(brand_string + 12, (const char*)edx, 4);
asm volatile("cpuid":"=a"(0x80000003):"a"(eax), "b"(ebx), "c"(ecx), "d"(edx));
strncpy(brand_string + 16, (const char*)eax, 4);
strncpy(brand_string + 20, (const char*)ebx, 4);
strncpy(brand_string + 24, (const char*)ecx, 4);
strncpy(brand_string + 28, (const char*)edx, 4);
asm volatile("cpuid":"=a"(0x80000004):"a"(eax), "b"(ebx), "c"(ecx), "d"(edx));
strncpy(brand_string + 32, (const char*)eax, 4);
strncpy(brand_string + 36, (const char*)ebx, 4);
strncpy(brand_string + 40, (const char*)ecx, 4);
strncpy(brand_string + 44, (const char*)edx, 4);
for (const std::string& search_string : search_strings) {
if (s2lower(brand_string).find(s2lower(search_string)) != std::string::npos) {
emulated = true;
break;
}
}
std::cout << "Running on " << ((emulated) ? "emulated" : "real")
<< " hardware (probably). CPU brand string: " << brand_string
<< std::endl;
return 0;
}
|