首页 > IT职业 > IT生活 > iczelion Vxd tut7 (转)
VxDCall _SHELL_CallAtAppyTime, <, dwRefData, dwFlags, dwTimeout>
BeginProc OnAppyTime, CCALL, PUBLIC
ArgVar dwRefData,Dword ; declare argument name and type
ArgVar dwFlags, DWORD
EnterProc
LeaveProc
Return
EndProc OnAppyTimeCAAFL_RING0 Ring zero event.
Simply put, if you want to wait for the appy time event for some period only, use CAAFL_TIMEOUT flag. If you want to wait indefinitely for the appy time event, use NULL. I don't know what CAAFL_RING0 actually does. dwTimeout The period of time the VxD wants to wait for the appy time event to occur. I can't find any info about the time unit used with this argument.
CAAFL_TIMEOUT Time out the event after the duration specified by dwTimeout.
This service is asynchronous, meaning that it returns immediately after registering your callback function for the appy time event.
If this service call is successful, it returns the application time event handle in eax. If it fails, eax contains 0.
You can cancel the appy time registration by calling on _SHELL_CancelAppyTimeEvent which takes only one parameter, the appy time event handle returned by _SHELL_CallAtAppyTime.
To be on the safe side, prior to calling _SHELL_CallAtAppyTime, you should check the system if appy time event will be available. For example, what if you register for appy time event while the system is shutting down? Your VxD's callback will never be called! You can query the system wheter appy time event will be available by calling _SHELL_QueryAppyTimeAvailable. This service takes no parameter. It returns 0 in eax if appy time will not be available, i.e. the system is closing down or the message server got GP faults. This service doesn't tell you that now is the appy time: it only tells you that there may be appy time events. In short, if you want to play safe, call _SHELL_QueryAppyTimeAvailable first and if it returns a nonzero value in eax, you can proceed to call _SHELL_CallAtAppyTime.
VxDCall _SHELL_ShellExecute,It takes only one parameter, the flat address of a SHEXPACKET structure. It returns the value from ShellExecute in eax. Let's examine SHEXPACKET structure in detail next.
All members are DWORDs in size. Now where is that rgchBaggage member I promised I would describe? It's a little difficult to explain. rgchBaggage is a member of SHEXPACKET structure but it cannot be included into the structure definition because its size is arbitrary. Check shell.inc, you'd see that rgchBaggage is not defined in SHEXPACKET yet the Windows 9x DDK documentation asserts that it's a member of SHEXPACKET.
What's rgchBaggage? It's simply an array of ASCIIZ strings that follows SHEXPACKET structure. Within this array, you can put the name of the operation you want to perform on the file, the name of the file, the parameters you want to pass to the file and the working directory. SHELL VxD obtains the offset of the string in rgchBaggage by adding the relative distance between the SHEXPACKET structure to the first byte of the string to the flat offset of the SHEXPACKET. For example, if the SHEXPACKET structure begins at 60000h, and the string immediately follows the structure, the distance between the structure and the string is the size of the structure itself, 32 bytes (20h). So Shell VxD knows that the string is located at address 60020h.
;---------------------------------------------------------------------------------
; VxD source Code
;---------------------------------------------------------------------------------
.386p
include masmincludevmm.inc
include masmincludevwin32.inc
include masmincludeshell.incVxDName TEXTEQU
ControlName TEXTEQU
VxDMajorVersion TEXTEQU <1>
VxDMinorVersion TEXTEQU <0>VxD_STATIC_DATA_SEG
VxD_STATIC_DATA_ENDSVXD_LOCKED_CODE_SEG
;----------------------------------------------------------------------------
; Remember: The name of the vxd MUST be uppercase else it won't work/unload
;----------------------------------------------------------------------------
DECLARE_VIRTUAL_DEVICE %VxDName,%VxDMajorVersion,%VxDMinorVersion, %ControlName,UNDEFINED_DEVICE_ID,UNDEFINED_INIT_ORDERBegin_control_dispatch %VxDName
Control_Dispatch W32_DEVICEIOCONTROL, OnDeviceIoControl
End_control_dispatch %VxDName
BeginProc OnDeviceIoControl
assume esi:ptr DIOCParams
.if [esi].dwIoControlCode==1
VxDCall _SHELL_CallAtAppyTime,<,0,0,0>
.endif
xor eax,eax
ret
EndProc OnDeviceIoControl
VXD_LOCKED_CODE_ENDSVXD_PAGEABLE_CODE_SEG
BeginProc OnAppyTime, CCALL
ArgVar RefData,DWORD
ArgVar TheFlag,DWORD
EnterProc
mov File.shex_dwTotalSize,sizeof SHEXPACKET
add File.shex_dwTotalSize,sizeof EXEName
mov File.shex_dwSize,sizeof SHEXPACKET
mov File.shex_ibOp,0
mov File.shex_ibFile,sizeof SHEXPACKET
mov File.shex_ibParams,0
mov File.shex_ibDir,0
mov File.shex_dwReserved,0
mov File.shex_nCmdShow,1
VxDCall _SHELL_ShellExecute,
LeaveProc
Return
EndProc OnAppyTime
VXD_PAGEABLE_CODE_ENDSVXD_PAGEABLE_DATA_SEG
File SHEXPACKET <>
EXEName db "calc.exe",0
VXD_PAGEABLE_DATA_ENDSend
VxDCall _SHELL_CallAtAppyTime,<It passes the flat address of OnAppyTime function to _SHELL_CallAtAppyTime so that Shell VxD will call it when an appy time event occurs. We don't use any reference data and have no need for timeout so all three parameters following the flat address of OnAppyTime are zeroes.,0,0,0>
BeginProc OnAppyTime, CCALLWe declare a function with BeginProc. Since the Shell VxD will call OnAppyTime with C calling sequence, we need to specify CCALL attribute.
ArgVar RefData,DWORDSince the Shell VxD will call OnAppyTime with two parameters, we must setup the stack frame accordingly. ArgVar macro is for adjusting the stack frame for each of the argument passed to the function. Its syntax is as follows:
ArgVar TheFlag,DWORD
EnterProc
...
LeaveProc
Return
ArgVar varname, size, usedvarname is the name of the parameter. You can use any name you like. size is, of course, the size of the parameter in bytes. You can use BYTE, WORD, DWORD or 1,2,4. used is usually omitted.
mov File.shex_dwTotalSize,sizeof SHEXPACKETThe instructions inside the procedure is simple: initialize the SHEXPACKET structure and call _SHELL_ShellExecute service. Note that shex_dwTotalSize contains the combined size of the SHEXPACKET structure itself and the size of the string that follows it. This is the simple case. If the string doesn't immediately follow the structure, you must calculate the distance between the first byte of the structure and the last byte of the string yourself. shex_ibFile contains the size of the structure itself because the name of the program immediately follows the structure. shex_ibDir is zero meaning that we want to use the Windows directory as the working directory. Note that this doesn't mean the program must be in the windows directory. The program can be anywhere so long as Windows can find it. shex_nCmdShow is 1 which is the value SW_SHOWNORMAL.
add File.shex_dwTotalSize,sizeof EXEName
mov File.shex_dwSize,sizeof SHEXPACKET
mov File.shex_ibOp,0
mov File.shex_ibFile,sizeof SHEXPACKET
mov File.shex_ibParams,0
mov File.shex_ibDir,0
mov File.shex_dwReserved,0
mov File.shex_nCmdShow,1
VxDCall _SHELL_ShellExecute,
File SHEXPACKET <>We define a SHEXPACKET structure followed immediately by the name of the program that we want to execute.
EXEName db "calc.exe",0
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10790663/viewspace-956755/ ,如需转载,请注明出处,否则将追究法律责任。