-
-
[求助]如何连续执行一条异常链的的每一个函数
-
发表于: 2014-4-23 11:10 2628
-
问题:_except_handlerA函数得不到执行,如何让异常链中的每一个回调函数都得到执行????
#include <windows.h> #include <stdio.h> EXCEPTION_DISPOSITION __cdecl _except_handlerA(struct _EXCEPTION_RECORD *ExceptionRecord, void * EstablisherFrame, struct _CONTEXT *ContextRecord, void * DispatcherContext) { static int time = 0; printf("A = %d\n", time++); Sleep(1000); return ExceptionContinueExecution; } EXCEPTION_DISPOSITION __cdecl _except_handlerB(struct _EXCEPTION_RECORD *ExceptionRecord, void * EstablisherFrame, struct _CONTEXT *ContextRecord, void * DispatcherContext) { static int time = 0; printf("B = %d\n", time++); int nFS; _asm { mov eax, FS:[0] mov nFS, eax } printf("FS:[0] = %x\n", nFS); Sleep(1000); return ExceptionContinueExecution; } int _tmain() { DWORD handlerFunA = (DWORD)_except_handlerA; DWORD handlerFunB = (DWORD)_except_handlerB; __asm { push handlerFunA // address of handlerFunA push FS:[0] // pre push handlerFunB // address of handlerFunB mov eax, esp add eax, 8 // point to pre handler(handlerFunA) push eax // pre mov FS:[0],ESP } __asm { mov eax,0 // Zero out EAX mov [eax], 1 // Write to EAX to deliberately cause a fault } printf( "After writing!\n" ); __asm { // Remove our EXECEPTION_REGISTRATION record mov eax,[ESP] // Get pointer to previous record mov FS:[0], EAX // Install previous record add esp, 8 // Clean our EXECEPTION_REGISTRATION off stack } return 0; }
赞赏
他的文章
看原图
赞赏
雪币:
留言: