All pastes #1008275 Raw Edit

Virtual Machine Detection ASM

public text v1 · immutable
#1008275 ·published 2008-05-05 15:37 UTC
rendered paste body
.586
.model flat, stdcall
option casemap:none
include C:\masm32\include\windows.inc
include C:\masm32\include\kernel32.inc
include C:\masm32\include\user32.inc
includelib C:\masm32\lib\user32.lib
includelib C:\masm32\lib\kernel32.lib
include C:\masm32\INCLUDE\advapi32.inc	; reg
includelib C:\masm32\LIB\advapi32.lib	; reg


.data
	MsgCaption     	 	db "Iczelion's tutorial no.2",0
	MsgBoxText      	db "Win32 Assembly is Great!",0
	VM			db "VM Detected",0
	szTestKey       	db "software\VMWare, Inc.\VMware tools",0
    	hKey  			db "InstallPath",0

.code
start:

  
FindVM:
	rdtsc            
	mov ebx,eax
	rdtsc
	sub eax,ebx
  push eax
	cmp eax,1      	; infrequent some CPUs return the value 1, 
	jz FindVM   	; which seems to be a bug! in this case we try again.

  pop eax
	cmp eax,0200h 	; time returned
	;jb Not_VM
		jb VM_Reg
			jmp ExitPrg ; inside VM
	
	
	
VM_Reg:
	invoke     RegOpenKeyEx, HKEY_LOCAL_MACHINE, addr szTestKey, 0, KEY_WRITE or KEY_READ, addr hKey
          .if eax == ERROR_SUCCESS
      		jmp ExitPrg 	;INSIDE VM
          .else
      		jmp RunMe	;NO VM
	.endif
	

RunMe:		;NO VM

	invoke MessageBox, NULL,addr MsgBoxText, addr MsgCaption, MB_OK
	invoke ExitProcess,NULL
ExitPrg:
	invoke ExitProcess,NULL
end start