function isruninvm: Boolean;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;
function IsRunInVMWare: Boolean;begin  Result := False;{$IFDEF CPU386}  try    asm      push     edx      push     ecx      push     ebx      mov      eax, 'VMXh'      mov      ecx, $0A      mov      edx, 'VX'      in       eax, dx      cmp      ebx, 'VMXh'      setz     [Result]      pop      ebx      pop      ecx      pop      edx    end;  except   end;{$ENDIF}end;

解决方案 »

  1.   

    这是Delphi里的嵌入式汇编,而C#是不支持这样的方式的。这段汇编象是查找某个地址的串,然后与VMxh比较,从而判断是否是在虚拟机状态下。
      

  2.   


    那您能帮我把这段C++语言整理并教我怎么编译成DLL,让C#调用吗?谢谢!
      

  3.   


    #include   "windows.h " 
    DWORD   __forceinline   IsInsideVPC_exceptionFilter(LPEXCEPTION_POINTERS   ep); 
    bool   IsInsideVPC(); 
    bool   IsInsideVMWare(); 
    int   CheckVPC(); //   发布版本使用MiniPE   (3.5KB) 
    #ifndef   _DEBUG #pragma   comment(linker,   "/ENTRY:EntryPoint ") 
    #pragma   comment(linker,   "/SECTION:VPC, ") 
    #pragma   comment(linker,   "/MERGE:.data=VPC ") int   EntryPoint() 

      CheckVPC(); 
      ExitProcess(0); 

    #else 
    int   WINAPI   WinMain(IN   HINSTANCE   hInstance,   IN   HINSTANCE   hPrevInstance,   IN   LPSTR   lpCmdLine,   IN   int   nShowCmd   ) 

      return   CheckVPC(); 

    #endif   //   _DEBUG int   CheckVPC() 

      if(IsInsideVPC()) 
        MessageBox(NULL, "你在虚拟机电脑MicroSoft   Virtual   PC中 ", "提示 ",   MB_OK|MB_ICONINFORMATION); 
      else   if(IsInsideVMWare()) 
        MessageBox(NULL,   "你在虚拟电脑VMWare中! ",   "提示 ",   MB_OK|MB_ICONINFORMATION); 
      else 
        MessageBox(NULL,   "你在真实的电脑中! ",   "提示 ",   MB_OK|MB_ICONINFORMATION);   return   0; 
    } DWORD   __forceinline   IsInsideVPC_exceptionFilter(LPEXCEPTION_POINTERS   ep) 

      PCONTEXT   ctx   =   ep-> ContextRecord; 
      ctx-> Ebx   =   -1; 
      ctx-> Eip   +=   4; 
      return   EXCEPTION_CONTINUE_EXECUTION; 
    } bool   IsInsideVPC() 

      bool   rc   =   false; 
      __try 
      { 
        _asm   push   ebx 
        _asm   mov   ebx,   0   //   It   will   stay   ZERO   if   VPC   is   running 
        _asm   mov   eax,   1   //   VPC   function   number 
        _asm   __emit   0Fh 
        _asm   __emit   3Fh 
        _asm   __emit   07h 
        _asm   __emit   0Bh 
        _asm   test   ebx,   ebx 
        _asm   setz   [rc] 
        _asm   pop   ebx 
      } 
      //   The   except   block   shouldn 't   get   triggered   if   VPC   is   running!! 
      __except(IsInsideVPC_exceptionFilter(GetExceptionInformation())) 
      { 
      }   return   rc; 
    } bool   IsInsideVMWare() 

      bool   rc   =   true;   __try 
      { 
        __asm 
        { 
          push   edx 
          push   ecx 
          push   ebx 
          mov   eax,   'VMXh ' 
          mov   ebx,   0 
          mov   ecx,   10 
          mov   edx,   'VX ' 
          in   eax,   dx 
          cmp   ebx,   'VMXh ' 
          setz   [rc] 
          pop   ebx 
          pop   ecx 
          pop   edx 
        } 
      } 
      __except(EXCEPTION_EXECUTE_HANDLER) 
      { 
        rc   =   false; 
      }   return   rc; 
    } 就是这段
      

  4.   

    直接用Delphi将以上代码封装为DLL即可......
      

  5.   


    请问如何封装呢?
    我需要在这些代码上加些什么才可以被编译成DLL进行方便的调用吗?
      

  6.   

    http://blog.csdn.net/zzflover/article/details/2529429
      

  7.   


    Delphi教程中有专门的这样课程,你可以查阅相关书籍。