2009-12-11 92 views
1

我想检查我的应用程序是否在VMWare上运行。 有没有一种可靠的方法在C++中做到这一点?以编程方式检测VMWare

+1

你为什么要这么做?我想不出很多理由,在哪里简单的“你在一个虚拟机下运行?”对话框是不够的(如果真的需要) – viraptor 2009-12-11 23:24:12

+0

Duplicaet http://stackoverflow.com/questions/154163/detect-virtualized-os-from-an-application – saschabeaumont 2009-12-14 01:28:59

+0

@viraptor这不是因为你不能想想没有的情况。例如,我正在识别计算机上的许可证和类似的东西,而且我需要知道我是否在虚拟机中,因为这将决定我要使用哪个硬件信息,并知道如果我在虚拟机中,我必须检查所有可能的虚拟机,包括VM Ware。 – Virus721 2014-08-04 09:19:47

回答

1

我想this link也许能帮助你。它在组装,而不是C++,但你总是在你的C++创建装配块...

//////////////////////////////////////////////////////////////////////////////// 
// 
// Simple VMware check on i386 
// 
// Note: There are plenty ways to detect VMware. This short version bases 
// on the fact that VMware intercepts IN instructions to port 0x5658 with 
// an magic value of 0x564D5868 in EAX. However, this is *NOT* officially 
// documented (used by VMware tools to communicate with the host via VM). 
// 
// Because this might change in future versions - you should look out for 
// additional checks (e.g. hardware device IDs, BIOS informations, etc.). 
// Newer VMware BIOS has valid SMBIOS informations (you might use my BIOS 
// Helper unit to dump the ROM-BIOS (http://www.bendlins.de/nico/delphi). 
// 
function IsVMwarePresent(): LongBool; stdcall; // platform; 
begin 
    Result := False; 
{$IFDEF CPU386} 
    try 
    asm 
      mov  eax, 564D5868h 
      mov  ebx, 00000000h 
      mov  ecx, 0000000Ah 
      mov  edx, 00005658h 
      in  eax, dx 
      cmp  ebx, 564D5868h 
      jne  @@exit 
      mov  Result, True 
    @@exit: 
    end; 
    except 
    Result := False; 
    end; 
{$ENDIF} 
end; 

与从互联网上的任何代码,请注意,只复制&粘贴它,期待它完美地工作。

+0

这似乎会导致Win2k8服务器崩溃,并可能导致Windows 7 32bit操作系统不幸 – 2009-12-11 23:37:57

+1

您可能需要将其包装在Win32“结构化”异常处理程序中。如果您获得了无效的指令异常或类似情况,那么您不在VMware中。 http://msdn.microsoft.com/en-us/library/s58ftw19%28VS.80%29.aspx – 2009-12-12 00:21:51

相关问题