Created
April 20, 2018 20:51
-
-
Save slayerlab/9693dab1c67accf9d8d6464f69de06dd to your computer and use it in GitHub Desktop.
[PoC, C] Get CPU hardware vendor.
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
#include <stdio.h> | |
static inline void | |
cpuid_vendor(char *vendor) __attribute__((always_inline)); | |
void cpuid_write(char *); | |
int main(void) | |
{ | |
char cpu_vendor[13]; | |
cpuid_write(cpu_vendor); | |
printf("[+] CPU: %s\n", cpu_vendor); | |
return 0; | |
} | |
void cpuid_write(char *vendor) | |
{ | |
cpuid_vendor(vendor); | |
} | |
static inline void cpuid_vendor(char *vendor) | |
{ | |
__uint32_t ebx = 0, ecx = 0, edx = 0; | |
__asm__ __volatile__("cpuid" \ | |
: "=b"(ebx), \ | |
"=c"(ecx), \ | |
"=d"(edx) \ | |
: "a"(0x00)); | |
sprintf(vendor, "%c%c%c%c", ebx, (ebx >> 0x08), (ebx >> 0x10), (ebx >> 0x18)); | |
sprintf(vendor+4, "%c%c%c%c", edx, (edx >> 0x08), (edx >> 0x10), (edx >> 0x18)); | |
sprintf(vendor+8, "%c%c%c%c", ecx, (ecx >> 0x08), (ecx >> 0x10), (ecx >> 0x18)); | |
vendor[12] = 0x00; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment