PDA

View Full Version : vectored exception handling


AttonRand
February 20th, 2010, 09:04
hi all

I am asking here because i know there are many good coders around.
I'd like to know something about vectored exception handling especially how to use it in masm.
I have searched in google but there are no example in masm and msdn, which is often very helpful, doesnt give so many info.

i understand that i need to call AddVectoredExceptionHandler but i am unsure about parameters:

FirstHandler: if i am correct this equals to a number (0=last handler)
VectoredHandler:here i get lost! is this the address where i must solve the exception like in seh? example:

Code:

push xxxxx <---- address where to solve exception
push dword ptr fs:[0]
mov dword ptr fs:[0],esp
...


can you make me an example in masm on how to use veh? like this:

Code:

.386
.model flat,stdcall
option casemap:none

include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
include windows.inc

.data
text db "Problem!",0
caption db "Help Me",0
.data?
hInstance HINSTANCE ?
.const
.code

start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke AddVectoredExceptionHandler,1,??? <--- here what does it go?
xor ecx,ecx
mov al,3
idiv ecx <-- exception
end start


when program comes accross exception i want it to show a msgbox and exit:

Code:

invoke MessageBox,hInstance,addr text,addr caption,MB_OK
invoke ExitProcess,0


Thanks in advance

EDIT: Oh, forgot to say that i am a newbie plz keep things simple

tofu-sensei
February 20th, 2010, 09:46
http://msdn.microsoft.com/en-us/library/ms679274(VS.85).aspx

AttonRand
February 20th, 2010, 12:47
hi tofu,
yes i already read msdn (i wrote that in my previous post). however i am a bit confused about parameters especially the vectoredhandler and ExceptionInfo.
An example would help me a lot.

I am very glad that you are here: on masm32 forum (http://www.masm32.com/board/?PHPSESSID=c773094fca1c273c20e2e36c4df7794a&action=printpage;topic=7436.0) you said that you were able to use veh, pheraps you can share something with us

disavowed
February 20th, 2010, 17:09
The second argument is a callback that you supply. It receives one argument from Windows, namely a pointer to an EXCEPTION_POINTERS ("http://msdn.microsoft.com/en-us/library/ms679331(VS.85).aspx") structure.

disavowed
February 20th, 2010, 17:09
And there's sample code here: http://msdn.microsoft.com/en-us/library/ms681411(VS.85).aspx

Indy
February 21st, 2010, 04:33
AttonRand
Information about the handlers stored in a linked list. Descriptor of each handler in the list contains the hash of the address of the handler. Manager expands the list of exceptions consistently, causing the hooks out of him. When you add a handler to the list, you can specify its position in the chain, namely the first or last to add to the list. The first parameter RtlAddVectoredExceptionHandler() is used for this and need.
Recently, the task of blocking the handler in the list, so it should always be at the beginning of the list (called first). If interested, here is the solution:
http://indy-vx.narod.ru/Bin/Barrier.zip

AttonRand
February 22nd, 2010, 15:08
Thank you all for the info! now i am studying what indy posted (thank you man for your example).
Well believe me or not before posting i checked msdn but didnt understand anything especially the Exception_Pointers structure.

I hope i can post here if i have future question about veh.