test.asm

format PE console

entry start

include 'win32a.inc'


section '.code' code readable executable


zero    =0

vmx     =0x10

hyvi    =0x80000000


start:

getcpuid:

mov     EAX,0

cpuid

mov     dword ptr scpuid,EBX

mov     dword ptr scpuid+4,EDX

mov     dword ptr scpuid+8,ECX

ccall   [printf],scpuid

jmp     getvmx


getvmx:

mov     EAX,1

cpuid

and     ECX,vmx

mov     EAX,zero

cmp     ECX,EAX

ja      yesvmx


novmx:

ccall   [printf],snovmx

jmp     gethypervisor


yesvmx:

ccall   [printf],syesvmx

jmp     gethypervisor


gethypervisor:

mov     EAX,1

cpuid

and     ECX,hyvi

mov     EAX,zero

cmp     ECX,EAX

ja      yeshypervisor


nohypervisor:

ccall   [printf],snohypervisor

jmp     exit


yeshypervisor:

ccall   [printf],syeshypervisor

jmp     exit


exit:

stdcall [ExitProcess],0


section '.data' data readable writeable


scpuid:

db      '000000000000',10,0

syesvmx:

db      'Virtual Machine eXtensions detected',10,0

snovmx:

db      'No Virtual Machine eXtensions detected',10,0

syeshypervisor:

db      'Hypervisor detected',10,0

snohypervisor:

db      'No Hypervisor detected',10,0


section '.idata' import data readable


library kernel,'kernel32.dll',\

        msvcrt,'msvcrt.dll'


import  kernel,\

        ExitProcess,'ExitProcess'

import  msvcrt,\

        printf,'printf'

 © Andrew Brehm 2016