首页
社区
课程
招聘
[求助]如何连续执行一条异常链的的每一个函数
发表于: 2014-4-23 11:10 2628

[求助]如何连续执行一条异常链的的每一个函数

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;
}

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (0)
游客
登录 | 注册 方可回帖
返回
//