Posted to tcl by stevel at Wed Feb 13 12:26:33 GMT 2008view pretty
/* Check whether we're running inside a VM, which is a potential risk for cryptovariables. It gets quite tricky to detect the various VMs so for now the only one that we detect is the most widespread one, VMware */ #if defined( __WIN32__ ) && !defined( NO_ASM ) BOOLEAN isRunningInVM( void ) { unsigned int magicValue, version; __try { __asm { push eax push ebx push ecx push edx /* Check for VMware via the VMware guest-to-host communications channel */ mov eax, 'VMXh' /* VMware magic value 0x564D5868 */ xor ebx, ebx /* Clear parameters register */ mov ecx, 0Ah /* Get-version command */ mov dx, 'VX' /* VMware I/O port 0x5658 */ in eax, dx /* Perform VMware call */ mov magicValue, ebx /* VMware magic value */ mov version, ecx /* VMware version */ pop edx pop ecx pop ebx pop eax } } __except (EXCEPTION_EXECUTE_HANDLER) {} return( magicValue == 'VMXh' ) ? TRUE : FALSE ); } #else BOOLEAN isRunningInVM( void ) { return( FALSE ); } #endif /* __WIN32__ && !NO_ASM */