使用cpuid获取虚拟机信息
#include <stdio.h>
#include <Windows.h>
int main()
{
unsigned int ueax = 0;
unsigned int uebx = 0;
unsigned int uecx = 0;
unsigned int uedx = 0;
__asm {
pushad
mov eax, 0x40000000
cpuid
mov ueax, eax
mov uebx, ebx
mov uecx, ecx
mov uedx, edx
popad
}
printf("%08X-%08X-%08X-%08X\n", ueax, uebx, uecx, uedx);
if (uebx && uecx && uedx) {
printf("Vm info: %4.4s%4.4s%4.4s\n", &uebx, &uecx, &uedx);
}
else {
printf("Not vm.\n");
}
return 0;
}
特别需要注意的是pushad和popad,用于保存寄存器值和恢复寄存器值,不使用的话,实际运行会产生崩溃
参考链接: https://www.cnblogs.com/oloroso/p/6182669.html
|