Skip to content

Instantly share code, notes, and snippets.

@hugsy
Last active January 10, 2020 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugsy/f5494e7ba282986964191b3309fcd383 to your computer and use it in GitHub Desktop.
Save hugsy/f5494e7ba282986964191b3309fcd383 to your computer and use it in GitHub Desktop.
/**
* QnD cpuid C script(tested win & lin)
*/
#include <stdio.h>
#include <stdint.h>
using namespace std;
#include <iostream>
#include <array>
#define __cpuid(id, mem) \
__asm__ ("cpuid\n\t" \
: "=a" (mem[0]), "=b" (mem[1]), "=c" (mem[2]), "=d" (mem[3]) \
: "0" (id))
int main(int argc, char** argv)
{
std::array<uint32_t, 4> regs;
__cpuid(0, regs.data());
char vendor[0x20] = {0};
*reinterpret_cast<uint32_t*>(vendor) = regs[1];
*reinterpret_cast<uint32_t*>(vendor + 4) = regs[3];
*reinterpret_cast<uint32_t*>(vendor + 8) = regs[2];
auto vendor_s = std::string(vendor, 0x20);
std::cout << "cpuid(0)=" << vendor_s.c_str() << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment