Posted to tcl by stevel at Wed Feb 13 12:26:33 GMT 2008view raw

  1. /* Check whether we're running inside a VM, which is a potential risk for
  2. cryptovariables. It gets quite tricky to detect the various VMs so for
  3. now the only one that we detect is the most widespread one, VMware */
  4.  
  5. #if defined( __WIN32__ ) && !defined( NO_ASM )
  6.  
  7. BOOLEAN isRunningInVM( void )
  8. { unsigned int magicValue, version;
  9.  
  10. __try {
  11. __asm { push eax
  12. push ebx
  13. push ecx
  14. push edx
  15.  
  16. /* Check for VMware via the VMware guest-to-host communications
  17. channel */
  18. mov eax, 'VMXh' /* VMware magic value 0x564D5868 */
  19. xor ebx, ebx /* Clear parameters register */ mov ecx, 0Ah /* Get-version command */
  20. mov dx, 'VX' /* VMware I/O port 0x5658 */
  21. in eax, dx /* Perform VMware call */ mov magicValue, ebx /* VMware magic value */
  22. mov version, ecx /* VMware version */
  23. pop edx
  24. pop ecx
  25. pop ebx
  26. pop eax }
  27. } __except (EXCEPTION_EXECUTE_HANDLER) {}
  28. return( magicValue == 'VMXh' ) ? TRUE : FALSE );
  29. }
  30. #else
  31.  
  32. BOOLEAN isRunningInVM( void )
  33. {
  34. return( FALSE );
  35. }
  36. #endif /* __WIN32__ && !NO_ASM */