.386p
include VMM.inc
include shell.incDECLARE_VIRTUAL_DEVICE MESSAGE,1,0, MESSAGE_Control, UNDEFINED_DEVICE_ID, UNDEFINED_INIT_ORDER
Begin_control_dispatch MESSAGE
Control_Dispatch Create_VM, OnVMCreate
Control_Dispatch VM_Terminate2, OnVMClose
End_control_dispatch MESSAGEVxD_PAGEABLE_DATA_SEG
MsgTitle db "VxD MessageBox",0
VMCreated db "A VM is created",0
VMDestroyed db "A VM is destroyed",0
VxD_PAGEABLE_DATA_ENDSVxD_PAGEABLE_CODE_SEG
BeginProc OnVMCreate
mov ecx, OFFSET32 VMCreated
CommonCode:
VMMCall Get_sys_vm_handle
mov eax,MB_OK+MB_ICONEXCLAMATION
mov edi, OFFSET32 MsgTitle
xor esi,esi
xor edx,edx
VxDCall SHELL_Message
ret
EndProc OnVMCreateBeginProc OnVMClose
mov ecx,OFFSET32 VMDestroyed
jmp CommonCode
EndProc OnVMClose
VxD_PAGEABLE_CODE_ENDSend
Begin_control_dispatch MESSAGE此VxD程序处理两个控制消息,Create_VM和VM_Terminate2当收到Create_VM 控制消息时,它调用OnVMCreate函数。当收到VM_Terminate2 消息时,它调用OnVMClose 函数。
Control_Dispatch Create_VM, OnVMCreate
Control_Dispatch VM_Terminate2, OnVMClose
End_control_dispatch MESSAGE
VxD_PAGEABLE_DATA_SEG我们把这些数据放在可调页段里面。
MsgTitle db "VxD MessageBox",0
VMCreated db "A VM is created",0
VMDestroyed db "A VM is destroyed",0
VxD_PAGEABLE_DATA_ENDS
BeginProc OnVMCreate我们用BeginProc和 EndProc宏来创建OnVMCreate。OnVMCreate函数把调用SHELL_Message服务所需要的参数放到寄存器里面去。因为我们要在系统虚拟机上显示消息框,所以不能使用ebx中的值(ebx包含了在创建的虚拟机的句柄,而我们要的是系统虚拟机的句柄)。于是,我们用另一个VMM服务,Get_Sys_VM_Handle来得到系统虚拟机的虚拟机句柄。我们分别把消息的地址和消息框标题的地址放在ecx和edi里面。我们不需要知道客户的反应,所以我们把esi和edx置零。当每个参数都在相应的寄存器内后,我们就调用 SHELL_Message 来显示消息框。
mov ecx, OFFSET32 VMCreated
CommonCode:
VMMCall Get_sys_vm_handle
mov eax,MB_OK+MB_ICONEXCLAMATION
mov edi, OFFSET32 MsgTitle
xor esi,esi
xor edx,edx
VxDCall SHELL_Message
ret
EndProc OnVMCreate
BeginProc OnVMCloseOnVMCloseOnVMClose函数本身是很简单的。因为它要使用的代码和OnVMCreate相同,所以它在用另一个消息的地址初始化ecx后,就转到OnVMCreate中的代码去了。
mov ecx,OFFSET32 VMDestroyed
jmp CommonCode
EndProc OnVMClose
VxD MESSAGESEGMENTS
_LPTEXT CLASS ´LCODE´ PRELOAD NONDISCARDABLE
_LTEXT CLASS ´LCODE´ PRELOAD NONDISCARDABLE
_LDATA CLASS ´LCODE´ PRELOAD NONDISCARDABLE
_TEXT CLASS ´LCODE´ PRELOAD NONDISCARDABLE
_DATA CLASS ´LCODE´ PRELOAD NONDISCARDABLE
CONST CLASS ´LCODE´ PRELOAD NONDISCARDABLE
_TLS CLASS ´LCODE´ PRELOAD NONDISCARDABLE
_BSS CLASS ´LCODE´ PRELOAD NONDISCARDABLE
_LMGTABLE CLASS ´MCODE´ PRELOAD NONDISCARDABLE IOPL
_LMSGDATA CLASS ´MCODE´ PRELOAD NONDISCARDABLE IOPL
_IMSGTABLE CLASS ´MCODE´ PRELOAD DISCARDABLE IOPL
_IMSGDATA CLASS ´MCODE´ PRELOAD DISCARDABLE IOPL
_ITEXT CLASS ´ICODE´ DISCARDABLE
_IDATA CLASS ´ICODE´ DISCARDABLE
_PTEXT CLASS ´PCODE´ NONDISCARDABLE
_PMSGTABLE CLASS ´MCODE´ NONDISCARDABLE IOPL
_PMSGDATA CLASS ´MCODE´ NONDISCARDABLE IOPL
_PDATA CLASS ´PDATA´ NONDISCARDABLE SHARED
_STEXT CLASS ´SCODE´ RESIDENT
_SDATA CLASS ´SCODE´ RESIDENT
_DBOSTART CLASS ´DBOCODE´ PRELOAD NONDISCARDABLE CONFORMING
_DBOCODE CLASS ´DBOCODE´ PRELOAD NONDISCARDABLE CONFORMING
_DBODATA CLASS ´DBOCODE´ PRELOAD NONDISCARDABLE CONFORMING
_16ICODE CLASS ´16ICODE´ PRELOAD DISCARDABLE
_RCODE CLASS ´RCODE´EXPORTS
MESSAGE_DDB @1
link -VxD -def:message.def message.obj