Skip to content

Instantly share code, notes, and snippets.

@tuket
Last active August 20, 2022 21:50
Show Gist options
  • Save tuket/ee706be4cd2f7513c587456074777277 to your computer and use it in GitHub Desktop.
Save tuket/ee706be4cd2f7513c587456074777277 to your computer and use it in GitHub Desktop.
windows cpuid shellcode
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <Windows.h>
static const char cpuidCode[] =
{
0x48, 0x89, 0xCE, // mov rsi, rcx
0x31, 0xC0, // xor eax, eax
0x0F, 0xA2, // cpuid
0x89, 0x1E, // mov [esi+0], bax
0x89, 0x56, 0x04, // mov [esi+4], edx
0x89, 0x4E, 0x08, // mov [esi+8], ecx
0xC3 // ret
};
typedef void(*CpuidFn)(char* id);
int main()
{
DWORD oldProtect;
VirtualProtect((void*)cpuidCode, sizeof(cpuidCode), PAGE_EXECUTE_READWRITE, &oldProtect);
auto cpuid = (CpuidFn)&cpuidCode[0];
char idStr[12+1];
cpuid(idStr);
idStr[12] = '\0';
printf("%s\n", idStr);
}
@tuket
Copy link
Author

tuket commented Aug 20, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment