Saber si nuestra aplicación se ejecuta dentro de una máquina virtual

unit VMWare; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm3 = class(TForm) Button1: TButton; Edit1: TEdit; Button2: TButton; Edit2: TEdit; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form3: TForm3; function IsInsideVMWare: Boolean; function IsVMwarePresent(): LongBool; stdcall; implementation {$R *.dfm} procedure TForm3.Button1Click(Sender: TObject); begin Edit1.text := 'No'; if IsVMwarePresent then Edit1.text := 'Yes'; end; procedure TForm3.Button2Click(Sender: TObject); begin Edit2.text := 'No'; if IsInsideVMWare then Edit2.text := 'Yes'; end; function IsVMwarePresent(): LongBool; stdcall; 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 IsInsideVMWare: Boolean; var rc: Boolean; begin rc := False; 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 end; except on EPrivilege do rc := False; end; Result := rc; end; end.
Si ejecutamos el programa y estamos dentro de una máquia virtual, podemos realizar el test:

- Enlaces de interés:
VMWare Torry's 1.
VMWare Torry's 2.
Detect if your program is running inside Virtual Machine.
Comments
Post a Comment