News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

SEH

Started by ecube, July 06, 2010, 08:00:22 AM

Previous topic - Next topic

ecube


DATA SECTION
sSEH STRUCT
OrgEsp            DD ?
OrgEbp            DD ?
SaveEip           DD ?
sSEH ENDS

SEH    sSEH <>
Try(%ContinueAddr) MACRO
CODE SECTION
MOV  [SEH.SaveEip], %ContinueAddr
MOV  [SEH.OrgEbp], EBP
PUSH OFFSET SehHandler
FS PUSH [0]
MOV  [SEH.OrgEsp], ESP
FS MOV [0],ESP
ENDM

EndTry MACRO
FS POP [0]
ADD  ESP, 4
ENDM

CODE SECTION
Start:

Try(addr exception)
int 3                       ;code to test here
EndTry
invoke MessageBox,0,'didnt crash',NULL,MB_OK
jmp >
exception:
invoke MessageBox,0,'crashed',NULL,MB_OK
:

invoke ExitProcess,0

SehHandler FRAME pExcept,pFrame,pContext,pDispatch
mov eax,[pContext]

PUSH [SEH.SaveEip]
POP  [EAX+CONTEXT.Eip]
PUSH [SEH.OrgEsp]
POP  [EAX+CONTEXT.Esp]
PUSH [SEH.OrgEbp]
POP [EAX+CONTEXT.Ebp]

MOV  EAX, ExceptionContinueExecution

RET
ENDF


looking forward to SEH support being added to x64 Jeremy  :thumbu