篩選器異常處理

.386
.model flat,stdcall
option casemap:none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;include
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;數據段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data
lpOldHandler dd ?
.const
szMsg db "異常發生位置:%08X,%08X,異常代碼:%08X,標誌:%08X",0
szSafe db "回到了安全的地方",0
szTitle db "篩選器異常處理的例子",0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;代碼段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
_Handler proc _lpExceptionPoint
LOCAL @szBuffer[256]:byte
pushad
mov esi,_lpExceptionPoint
assume esi:ptr EXCEPTION_POINTERS
mov edi,[esi].ContextRecord
mov esi,[esi].pExceptionRecord
assume esi:ptr EXCEPTION_RECORD,edi:ptr CONTEXT
mov eax,[esi].ExceptionFlags
;如果標誌被置位,說明異常是致命的,應該退出
and eax,00000001h
.if eax==1
mov eax,EXCEPTION_CONTINUE_SEARCH
ret
.endif
;ExceptionCode中包含了,異常的類型,嚴重性,觸發異常的設置,是內存
;還是網絡,還是CPU,還是接口卡,還是多媒體設置
;ExceptionFlag中指名了異常是否導致程序的終止
invoke wsprintf,addr @szBuffer,addr szMsg,\
[edi].regEip,[esi].ExceptionAddress,[esi].ExceptionCode,[esi].ExceptionFlags
invoke MessageBox,NULL,addr @szBuffer,NULL,MB_OK
mov [edi].regEip,offset _SafePlace
assume esi:nothing,edi:nothing
popad
;返回值,根據ExceptionFlag來決定是否應該讓程序進行下去
mov eax,EXCEPTION_CONTINUE_EXECUTION
ret
_Handler endp


start:
invoke SetUnhandledExceptionFilter,addr _Handler
mov lpOldHandler,eax
xor eax,eax
mov dword ptr [eax],0
_SafePlace:
invoke MessageBox,NULL,addr szSafe,addr szTitle,MB_OK
invoke ExitProcess,NULL
end start
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章