Skip to content

Instantly share code, notes, and snippets.

@wirespecter
Created October 14, 2015 11:23
Show Gist options
  • Select an option

  • Save wirespecter/10f99ed0ccbd0d638054 to your computer and use it in GitHub Desktop.

Select an option

Save wirespecter/10f99ed0ccbd0d638054 to your computer and use it in GitHub Desktop.
[Delphi] Virtual Machine Detection
function IsVirtualPC: Boolean;
begin
Try
asm
mov eax,1
db $0F
db $3F
db $07
db $0B
db $C7
db $45
db $FC
db $FF
db $FF
db $FF
db $FF
end;
Except
Result := False;
Exit;
end;
Result := True;
end;
end.
Function AntiVMware():boolean;
begin
try
asm
push edx;
push ecx;
push ebx;
mov eax, 'VMXh';
mov ebx, 0;
mov ecx, 10;
mov edx, 'VX';
in eax, dx;
//On return EAX returns the VERSION
cmp ebx, 'VMXh'; // is it VMware
setz Result; //Set flag state
pop ebx;
pop ecx;
pop edx;
end;
except
Result:= False;
end;
end.
function InVMware: Boolean;
asm
XOR EAX, EAX
PUSH OFFSET @@Handler
PUSH DWORD PTR FS:[EAX]
MOV DWORD PTR FS:[EAX], ESP
MOV EAX, 564D5868h
MOV EBX, 3c6cf712h
MOV ECX, 0Ah
MOV DX, 5658h
IN EAX, DX
MOV EAX, True
JMP @@NotHandle
@@Handler:
MOV EAX, [ESP+$C]
MOV TContext(EAX).EIP, OFFSET @@Handled
XOR EAX, EAX
RET
@@Handled:
XOR EAX, EAX
@@NotHandle:
XOR EBX, EBX
POP DWORD PTR FS:[EBX]
ADD ESP, 4
end;
function running_inside_vpc: boolean; assembler;
asm
push ebp
mov ecx, offset @@exception_handler
mov ebp, esp
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
db 00Fh, 03Fh, 007h, 00Bh
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 @@ret
@@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 detection code
xor eax, eax // exception is handled
ret
@@ret:
end;
function DetectVirtualBox : Boolean;
begin
Result := False;
if CreateFile('\\\\.\\VBoxMiniRdrDN',GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0) <> INVALID_HANDLE_VALUE then Result := True;
If LoadLibrary('VBoxHook.dll') <> 0 then Result := True;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment