Created
January 4, 2018 04:29
-
-
Save prodeveloper0/1d4357a433f60f4b6313d6051fd6c2c6 to your computer and use it in GitHub Desktop.
How to get x86 compatible processor vendor and brand string using cpuid instruction
This file contains hidden or 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
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| typedef char MSGBUF[64]; | |
| int GetCpuBrandString(MSGBUF dst) | |
| { | |
| unsigned long ul; | |
| unsigned long uls[12] = {0x00}; | |
| __asm | |
| { | |
| // Check Processor Support Getting Processor Brand String | |
| mov eax, 80000000h | |
| cpuid | |
| mov dword ptr [ul], eax | |
| }; | |
| if(ul < 0x80000004) | |
| return -1; | |
| __asm | |
| { | |
| // Get Processor Brand String | |
| mov eax, 80000002h | |
| cpuid | |
| mov uls, eax | |
| mov uls + 4, ebx | |
| mov uls + 8, ecx | |
| mov uls + 12, edx | |
| mov eax, 80000003h | |
| cpuid | |
| mov uls + 16, eax | |
| mov uls + 20, ebx | |
| mov uls + 24, ecx | |
| mov uls + 28, edx | |
| mov eax, 80000004h | |
| cpuid | |
| mov uls + 32, eax | |
| mov uls + 36, ebx | |
| mov uls + 40, ecx | |
| mov uls + 44, edx | |
| }; | |
| memcpy(dst, uls, sizeof(uls)); | |
| return 0; | |
| } | |
| void GetCpuVendor(MSGBUF dst) | |
| { | |
| unsigned long uls[4] = {0x00}; | |
| __asm | |
| { | |
| mov eax, 0 | |
| cpuid | |
| mov uls, ebx | |
| mov uls + 4, edx | |
| mov uls + 8, ecx | |
| }; | |
| memcpy(dst, uls, sizeof(uls)); | |
| } | |
| int main(int argc, char** argv) | |
| { | |
| MSGBUF b; | |
| GetCpuBrandString(b); | |
| GetCpuVendor(b); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment