Get CPU Maker and Model.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Written and Tested in VC++ (C++11 code) | |
// by @CodeAngry | |
// | |
// get the maker name | |
int vCpuBuffer[4]{}; | |
__cpuid(vCpuBuffer, 0); | |
unsigned int vHighestFeature((unsigned int)vCpuBuffer[0]); | |
char vCpuMaker[32]{}; // zero-fill | |
*(int*)&vCpuMaker[0] = vCpuBuffer[1]; | |
*(int*)&vCpuMaker[4] = vCpuBuffer[3]; | |
*(int*)&vCpuMaker[8] = vCpuBuffer[2]; | |
// get the model name | |
char vCpuModel[64]{}; | |
__cpuid(vCpuBuffer, 0x80000000); | |
unsigned int nHighestFeatureEx((unsigned int)vCpuBuffer[0]); | |
if(nHighestFeatureEx >= 0x80000004) { | |
__cpuid((int*)&vCpuModel[0], 0x80000002); | |
__cpuid((int*)&vCpuModel[16], 0x80000003); | |
__cpuid((int*)&vCpuModel[32], 0x80000004); | |
// trim the beggining of the model name | |
auto vCpuModelBegin(vCpuModel); | |
while(*vCpuModelBegin && ((*vCpuModelBegin == ' ') || (*vCpuModelBegin == '\t'))) { | |
++vCpuModelBegin; | |
} | |
// seek the end of the model name | |
auto vCpuModelEnd(vCpuModelBegin); | |
while(*vCpuModelEnd) { | |
++vCpuModelEnd; | |
} | |
--vCpuModelEnd; | |
// trim the end of the model name | |
while(vCpuModelEnd > vCpuModelBegin) { | |
if((*vCpuModelEnd != ' ') && (*vCpuModelEnd != '\t')) { | |
break; | |
} | |
--vCpuModelEnd; | |
} | |
*(vCpuModelEnd + 1) = 0; | |
// get rid of leading and trailing spaces | |
unsigned int vCpuModelLength((unsigned int)strlen(vCpuModelBegin)); | |
memmove(vCpuModel, vCpuModelBegin, vCpuModelLength); | |
memset(vCpuModel + vCpuModelLength, 0, sizeof(vCpuModel) - vCpuModelLength); | |
} | |
// we've got the data | |
printf("Maker: '%s'\r\n", vCpuMaker); | |
printf("Model: '%s'\r\n", vCpuModel); | |
bool vIsIntel(!strcmp(vCpuMaker, "GenuineIntel")); | |
bool vIsAMD(!vIsIntel && !strcmp(vCpuMaker, "AuthenticAMD")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment