Fórum Execução em máquina virtual #449422

25/07/2013

0

Bom dia para todos!
Pessoal preciso fazer um procedimento na qual meu software não execute quando estiver instalado em uma máquina virtual.
Alguém já passou por este tipo de problema que possa me ajudar?
Marco Borges

Marco Borges

Responder

Posts

25/07/2013

Manoel Jr

Tem algumas funções que você pode usar, segue abaixo cada uma delas e para qual ambiente virtual, VirtualPC, VMware, VirtualBox e Wine.

// Virtual PC e VMM
function IsRunningVirtualPC: boolean;
asm
    push ebp;
    mov ebp, esp;

    mov ecx, offset @exception_handler;

    push ebx;
    push ecx;

    push dword ptr fs:[0];
    mov dword ptr fs:[0], esp;

    mov ebx, 0; // Flag
    mov eax, 1; // VPC function number

    // call VPC
    db $0F, $3F, $07, $0B

    mov eax, dword ptr ss:[esp];
    mov dword ptr fs:[0], eax;

    add esp, 8;

    test ebx, ebx;

    setz al;

    lea esp, dword ptr ss:[ebp-4];
    mov ebx, dword ptr ss:[esp];
    mov ebp, dword ptr ss:[esp+4];

    add esp, 8;

    jmp @ret1;

    @exception_handler:
    mov ecx, [esp+0Ch];
    mov dword ptr [ecx+0A4h], -1; // EBX = -1 -> not running, ebx = 0 -> running
    add dword ptr [ecx+0B8h], 4; // -> skip past the call to VPC
    xor eax, eax; // exception is handled

    @ret1:
end;


// VirtualBox
//Uses Necessária TlHelp32
function RunningInsideVirtualBox: Boolean;
var
  handle: THandle;
  procinfo: ProcessEntry32;
begin
  Result := False;
   try
     handle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
      try
        while(Process32Next(handle, procinfo)) do begin
        if POS('VBoxService.exe', procinfo.szExeFile) > 0 then begin
        Result := True;
        Break;
        end;
      end;
    finally
  CloseHandle(handle);
  end;
  except
  end;
end;


//Wine
function IsRunningWine: boolean;
var hnd:THandle;
  wine_get_version: function : pchar; {$IFDEF Win32} stdcall; {$ENDIF}
  wine_unix2fn: procedure (p1:pointer; p2:pointer); {$IFDEF Win32} stdcall; {$ENDIF}
begin
  result:=false;
  hnd:=LoadLibrary('ntdll.dll');
  if hnd>32 then
  begin
    wine_get_version:= GetProcAddress(hnd, 'wine_get_version');
    wine_unix2fn:= GetProcAddress(hnd, 'wine_nt_to_unix_file_name');
    if assigned(wine_get_version) or assigned(wine_unix2fn) then
    result:=true;
    FreeLibrary(hnd);
  end;
end;


Espero ter ajudado.
Responder

Gostei + 0

25/07/2013

Manoel Jr

O post anterior ficou confuso segue aqui mais bem formatado eu espero^^

Tem algumas funções que você pode usar, segue abaixo cada uma delas e para qual ambiente virtual, VirtualPC, VMware, VirtualBox e Wine.

//Virtual PC - VMWare//
function IsRunningVirtualPC: boolean;
asm
    push ebp;
    mov ebp, esp;

    mov ecx, offset @exception_handler;

    push ebx;
    push ecx;

    push dword ptr fs:[0];
    mov dword ptr fs:[0], esp;

    mov ebx, 0; // Flag
    mov eax, 1; // VPC function number

    // call VPC
    db $0F, $3F, $07, $0B

    mov eax, dword ptr ss:[esp];
    mov dword ptr fs:[0], eax;

    add esp, 8;

    test ebx, ebx;

    setz al;

    lea esp, dword ptr ss:[ebp-4];
    mov ebx, dword ptr ss:[esp];
    mov ebp, dword ptr ss:[esp+4];

    add esp, 8;

    jmp @ret1;

    @exception_handler:
    mov ecx, [esp+0Ch];
    mov dword ptr [ecx+0A4h], -1; // EBX = -1 -> not running, ebx = 0 -> running
    add dword ptr [ecx+0B8h], 4; // -> skip past the call to VPC
    xor eax, eax; // exception is handled

    @ret1:
end;
//VirtualBox//
function RunningInsideVirtualBox: Boolean; 
var
  handle: THandle;
  procinfo: ProcessEntry32; //Uses TlHelp32
begin
  Result := False;
   try
     handle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
      try
        while(Process32Next(handle, procinfo)) do begin
        if POS('VBoxService.exe', procinfo.szExeFile) > 0 then begin
        Result := True;
        Break;
        end;
      end;
    finally
  CloseHandle(handle);
  end;
  except
  end;
end;
//Wine//
function IsRunningWine: boolean;
var hnd:THandle;
  wine_get_version: function : pchar; {$IFDEF Win32} stdcall; {$ENDIF}
  wine_unix2fn: procedure (p1:pointer; p2:pointer); {$IFDEF Win32} stdcall; {$ENDIF}
begin
  result:=false;
  hnd:=LoadLibrary('ntdll.dll');
  if hnd>32 then
  begin
    wine_get_version:= GetProcAddress(hnd, 'wine_get_version');
    wine_unix2fn:= GetProcAddress(hnd, 'wine_nt_to_unix_file_name');
    if assigned(wine_get_version) or assigned(wine_unix2fn) then
    result:=true;
    FreeLibrary(hnd);
  end;
end;


Espero ter ajudado.
Responder

Gostei + 0

06/01/2014

Marco Borges

Hum sim, vou testar e te dou um feedback do resultado.
Muito obrigado ManoelJr
Responder

Gostei + 0

06/01/2014

Manoel Jr

Ok fico no aguardo.
Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar