您好,欢迎来到伴沃教育。
搜索
您的当前位置:首页手动设置SEH

手动设置SEH

来源:伴沃教育

转载至   http://bbs.pediy.com/showthread.php?t=46690

一般情况下我们在 VS2005以上都不能手动设置SEH异常处理函数

因为有 SafeSEH  保护

如下:

#include "stdafx.h"
#include <Windows.h>

int    __stdcall CatchProc(EXCEPTION_RECORD* pExcept,void* pErr,void* pContext,void* p_Dis)
{
	if (pExcept->ExceptionCode == EXCEPTION_BREAKPOINT)
	{
		printf("catched");
		return 0;
	}
	printf("catched");
	return 1;
}


bool __stdcall SetCatchProc(void*    pCProc)
{
	char* p_ExpProcEntry;
	__asm
	{
		mov eax,fs:[0]
		add eax,4
		mov eax,dword ptr [eax]
		mov p_ExpProcEntry,eax
	}
	DWORD p_oldProtect = 0;
	if (VirtualProtect(p_ExpProcEntry,5,PAGE_EXECUTE_READWRITE,&p_oldProtect))
	{
		*(BYTE*)p_ExpProcEntry = 0xE9;
		*(DWORD*)(p_ExpProcEntry+1)=(char*)pCProc-p_ExpProcEntry-5;
		return true;
	}
	return false;
}
int _tmain(int argc, _TCHAR* argv[])
{
	SetCatchProc(CatchProc);
	int i=0;
	int sum = 5/i;
	char p1[255];
	gets(p1);
	return 0;
}


转载于:https://www.cnblogs.com/zcc1414/p/3982395.html

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- bangwoyixia.com 版权所有 湘ICP备2023022004号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务