vEcp1 proc USES esi edi ebx pExcetionPointersWORD
mov eax,pExcetionPointers
mov esi,[eax] ;pEXCEPTION_RECORD
mov edi,[eax+4] ;pCONTEXT
;call dP
xor eax,eax
test [esi].ExceptionFlags,4+2+1 ;Unwind or serious
JNE @NO_HANDLE
cmp [esi].ExceptionCode,80000004h ;Single step
JNE @NO_HANDLE
m2m [edi].regEip,offset @1
dec eax ;mov eax,EXCEPTION_CONTINUE_EXECUTION
@NO_HANDLE: ;mov eax,EXCEPTION_CONTINUE_SEARCH
ret
vEcp1 Endp
;-----------------------------------------
vEcp2 proc USES esi edi ebx pExcetionPointersWORD
mov eax,pExcetionPointers
mov esi,[eax] ;pEXCEPTION_RECORD
mov edi,[eax+4]
;call dP
xor eax,eax
test [esi].ExceptionFlags,4+2+1 ;Unwind or serious
JNE @NO_HANDLE
cmp [esi].ExceptionCode,80000003h ;STATUS_BREAKPOINT
JNE @NO_HANDLE
m2m [edi].regEip,offset @3
dec eax ;mov eax,EXCEPTION_CONTINUE_EXECUTION
@NO_HANDLE: ;mov eax,EXCEPTION_CONTINUE_SEARCH
ret
vEcp2 Endp
;-----------------------------------------
sEh1 proc USES esi edi ebx pExceptWORD,pFrameWORD,pContextWORD,pDispatchWORD
mov esi,pExcept
mov edi,pContext
;call dP
xor eax,eax
inc eax
test [esi].ExceptionFlags,6+1 ;Unwind & Serious
jne @F
cmp [esi].ExceptionCode,0C0000005h ;STATUS_ACCESS_VIOLATION
jne @F
m2m [edi].regEip,offset @2
dec eax
@@:
ret
sEh1 endp
;FOR debug purpose,Rubbish,....you can del it!
.data
fmt db "The Cur EIP IS: %08X Cur Excpt NUM is: %08X",0dh,0ah
db "The Ecpt FLAGS VALUE in HEX: %X",0dh,0ah
db "Common REG DUMP:",0dh,0ah
db "EAX: %08X EBX: %08X",0dh,0ah
db "ECX: %08X EDX: %08X",0dh,0ah
db "ESI: %08X EDI: %08X",0dh,0ah
.code
;DUMP THREAD CONTEXTS Need esit Excpt_Record
;edi: pt Context
dP proc
local buf[256]:byte
pushad
mov eax,(EXCEPTION_RECORD ptr [esi]).ExceptionFlags
INVOKE wsprintf,addr buf,offset fmt,(CONTEXT PTR [edi]).regEip,(dword ptr [esi]),eax,\
(CONTEXT PTR [edi]).regEax,(CONTEXT PTR [edi]).regEbx,\
(CONTEXT PTR [edi]).regEcx,(CONTEXT PTR [edi]).regEdx,\
(CONTEXT PTR [edi]).regEsi,(CONTEXT PTR [edi]).regEdi
INVOKE MessageBox,0,addr buf,CTEXT("VEH Detector...debug purpose...Hume",0
popad
ret
dP endp
END __Start
;==============================================================
下面附例子用到的几个宏:
CTEXT,相信诸位见过多次了,不多说.
sWin32:相当于push syntax call label
rd: 数据定义DWORD
m2m: 相当于push syn1 pop syn2
JEAXZ :eax=0,jmp des
$incoke():inline coding
sWin32 Macro label:REQ,args:VARARG ;Which allow no protos discalaiming
% FOR pxx, ;But you need to guarantee the
IFNB ;the syntax yourself
push pxx
ENDIF
ENDM
call label
ENDM
m2m MACRO M1, M2 ;mov is too boring!
push M2
pop M1
ENDM