Execução em máquina virtual
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?
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
Curtidas 0
Respostas
Manoel Jr
25/07/2013
Tem algumas funções que você pode usar, segue abaixo cada uma delas e para qual ambiente virtual, VirtualPC, VMware, VirtualBox e Wine.
Espero ter ajudado.
// 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.
GOSTEI 0
Manoel Jr
25/07/2013
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.
Espero ter ajudado.
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.
GOSTEI 0
Marco Borges
25/07/2013
Hum sim, vou testar e te dou um feedback do resultado.
Muito obrigado ManoelJr
Muito obrigado ManoelJr
GOSTEI 0
Manoel Jr
25/07/2013
Ok fico no aguardo.
GOSTEI 0