Last active
August 20, 2022 21:50
-
-
Save tuket/ee706be4cd2f7513c587456074777277 to your computer and use it in GitHub Desktop.
windows cpuid shellcode
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> | |
#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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://godbolt.org/z/xWzeEdTGK