Verr 指令在VMware下执行可能有异常,据此可以检测运行环境为VMWare
 
一、通过dx判断。
#include <windows.h>
#pragma comment(linker, “/entry:main”)
int main()
{
 __asm
 {
   mov    dx, 1
_l1:
   verr  dx        //其中的 dx, 可以为其他。只要 dx & 4 == TRUE, 那么就会在 vmware 中发生异常,而外部没有发现这种现象
   shl    dx, 1
   jmp    _l1
 }
 return 0;
}
以上的这个函数自在vm5.5及之前的版本有效!
bool VMWareTest()
{
 BYTE PortValue1,PortValue2;
 __try
 {
   __asm
   {
     pushad
     pushfd
     xor ebx,ebx
     mov ecx,0xa
     mov eax, ‘VMXh’      ; EAX=magic
     mov dx, ‘VX’      ; DX=magic
     in  eax, dx        ; specially processed io cmd
     cmp ebx, ‘VMXh’      ; also eax/ecx modified (maybe vmw/os ver?)
     jne local_001
     mov gInVMWARE,1
local_001:
     popfd
     popad
   }
 }
 __except(EXCEPTION_EXECUTE_HANDLER)
 {
   gInVMWARE=false;
 }
 return gInVMWARE;
}
bool VirtualPCTest()
{
 __try
 {
   __asm
   {
     pushad     
     mov  ebx, 0 // Flag
     mov  eax, 1 // VPC function number
     __emit 0Fh
     __emit 3Fh
     __emit 07h
     __emit 0Bh
     test ebx, ebx
     jnz local_001
     mov gInVirtualPC,1
local_001:
     popad
   }
 }
 __except(EXCEPTION_EXECUTE_HANDLER)
 {
   gInVirtualPC=false;
 }
 if(gInVirtualPC)
   DbgPrint(“Syser : Host machine is VirtualPC !\n”);
 return gInVirtualPC;
}
 
 
(文章今日已有 1 人访问,总访问量 18 ::>_<::)