能力值:
( LV4,RANK:50 )
|
-
-
8 楼
include wap32.inc
extrn _wsprintfA: proc
extrn MessageBoxA: proc
extrn ExitProcess: proc
.386
.model flat,stdcall
.data
Msg00 db '异常处理信息...',0
Msg01 db '函数原形:',0dh,0ah
db 'Exception PROC uses ebx esi edi,pRecord,pFrame,pContext,pDispatch',0dh,0ah,0ah
db '详细资料...',0dh,0ah,0ah
db '异常处理程序返回地址= %8.8x',0dh,0ah,0ah
db '<参数1>pRecord= [%8.8x] 异常部分记录',0dh,0ah
db ' ExceptionCode= %8.8x ExceptionFlags= %8.8x ',0dh,0ah,0ah
db '<参数2>pFrame= [%8.8x] 一些指针,本程序不关心',0dh,0ah,0ah
db '<参数3>pContext=[%8.8x] 发生异常时候的常用寄存器值',0dh,0ah,0ah
db ' EAX= %8.8x EBX= %8.8x ECX= %8.8x EDX= %8.8x',0dh,0ah
db ' ESI= %8.8x EDI= %8.8x EBP= %8.8x ESP= %8.8x',0dh,0ah
db ' DS= %4.4x ES= %4.4x FS= %4.4x GS= %4.4x',0dh,0ah
db ' SS: ESP=%4.4x: %8.8x CS: EIP=%4.4x: %8.8x',0dh,0ah,0ah
db '<参数4>pDispatch= [%8.8x] X86机器未使用',0dh,0ah,0ah
db '发生异常的代码 CS:[EIP] <按字节顺序显示>',0dh,0ah,0ah
db '%8.8x %8.8x %8.8x %8.8x %8.8x %8.8x %8.8x %8.8x',0dh,0ah,0ah
db '发生异常的堆栈 SS:[ESP] <按双字顺序显示>',0dh,0ah,0ah
db '%8.8x %8.8x %8.8x %8.8x %8.8x %8.8x %8.8x %8.8x',0dh,0ah,0ah,0
Msg02 db '程序正常终止',0
Msg03 db '应用程序提示',0
MsgBuff db 200h dup(0)
.code
Start:
mov eax,offset MyExceptionProc
push eax
mov eax,fs:[0]
push eax
mov fs:[0],esp ;//挂接异常处理链
CreateException:
int 3 ;//产生中断异常
;mov ds:[0],eax;//产生内存访问异常
;cli ;//特权指令异常
InstructionSize=$-OFF CreateException
call MessageBoxA,NULL,OFF Msg02,OFF Msg03,NULL
call ExitProcess,0
MyExceptionProc proc uses ebx esi edi,pRecord,pFrame,pContext,pDispatch
mov edi,esp
mov ebx,pContext
mov ebx,[ebx.cx_Esp]
mov ecx,8
LoopPushStack:
mov eax,[ebx+7*4] ;//不调整显示顺序
push eax
sub ebx,4
loop LoopPushStack
mov ebx,pContext
mov ebx,[ebx.cx_Eip]
mov ecx,8
LoopPushCode:
mov ax,[ebx+7*4] ;//调整显示顺序
xchg ah,al
shl eax,16
mov ax,[ebx+2]
xchg ah,al
push eax
sub ebx,4
loop LoopPushCode
mov ebx,pDispatch
push ebx
mov ebx,pContext
mov eax,[ebx.cx_Eip]
push eax
mov eax,[ebx.cx_SegCs]
and eax,0ffffh
push eax
mov eax,[ebx.cx_Esp]
push eax
mov eax,[ebx.cx_SegSs]
and eax,0ffffh
push eax
mov eax,[ebx.cx_SegGs]
and eax,0ffffh
push eax
mov eax,[ebx.cx_SegFs]
and eax,0ffffh
push eax
mov eax,[ebx.cx_SegEs]
and eax,0ffffh
push eax
mov eax,[ebx.cx_SegDs]
and eax,0ffffh
push eax
mov eax,[ebx.cx_Esp]
push eax
mov eax,[ebx.cx_Ebp]
push eax
mov eax,[ebx.cx_Edi]
push eax
mov eax,[ebx.cx_Esi]
push eax
mov eax,[ebx.cx_Edx]
push eax
mov eax,[ebx.cx_Ecx]
push eax
mov eax,[ebx.cx_Ebx]
push eax
mov eax,[ebx.cx_Eax]
push eax
push ebx
mov ebx,pFrame
push ebx
mov ebx,pRecord
mov eax,[ebx.ExceptionFlags]
push eax
mov eax,[ebx.ExceptionCode]
push eax
push ebx
mov ebx,[ebp+4]
push ebx
call _wsprintfA,OFF MsgBuff,OFF Msg01
call MessageBoxA,NULL,OFF MsgBuff,OFF Msg00,NULL
mov esp,edi
mov ebx,pContext
add [ebx.cx_Eip],InstructionSize
mov eax,ExceptionContinueExecution
ret
MyExceptionProc endp
end Start
这段代码好象对你有帮助
看这句是不是你想要的
call _wsprintfA,OFF MsgBuff,OFF Msg01
这个就有些类试c中printf
定义的时候好象要注意
|