How to write a function that checks it runs or not on a virtual machine (64bit)

Hello all,

In 32 bit it wasn't problem to understand if the program runs on virtual or native machine using inline assembly. But in 64 bit inline assemblers is no longer avaible and MSDN site says use x64 intrinsics instead. Does anyone know how to cope with it?

bool IsInsideVMWare(void)
{
bool rc = true;

__try
{
__asm
{
push edx
push ecx
push ebx

mov eax, 'VMXh'
mov ebx, 0 // any value but not the MAGIC VALUE
mov ecx, 10 // get VMWare version
mov edx, 'VX' // port number

in eax, dx // read port
// on return EAX returns the VERSION
cmp ebx, 'VMXh' // is it a reply from VMWare?
setz [rc] // set return value

pop ebx
pop ecx
pop edx
}
}
__except(filter(GetExceptionCode()))
{
rc = false;
}

return rc;
}
Last edited on
Or if it can or not?
Wouldn't that defeat the whole idea of a virtual machine if it could be detected?
of course it is better if there is no differences between wm and native machine :) but it can be done in 32bit system with inline assembly but can't in 64bit because i can't use that. i need to detect it :)
Last edited on
Topic archived. No new replies allowed.