您的位置:首页 > 其它

__try异常处理

2015-06-22 22:12 295 查看
#ifdef __cplusplus
extern "C" 
{

#endif
#include <ntddk.h>
#ifdef __cplusplus
}
#endif

void helloxpUnload(IN PDRIVER_OBJECT DriverObject);
void Test(void);

#ifdef __cplusplus
extern "C" NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING  RegistryPath);
#endif

NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING  RegistryPath)
{

	DbgPrint("Hello from hello2003!\n");
	DriverObject->DriverUnload = helloxpUnload;

	PEPROCESS pEprocess=PsGetCurrentProcess();
	PTSTR ProcessName=(PTSTR)((ULONG)pEprocess+0x174);
	DbgPrint(TEXT("%s"),ProcessName);

	int* P=NULL;
	__try
	{
		//判断指针是否可读
		ProbeForRead(P,100,4);
		*P=1234;

	}
	__except(EXCEPTION_EXECUTE_HANDLER)
	{
		DbgPrint(TEXT("异常产生\n"));
	}

	Test();

	return STATUS_SUCCESS;
}

void helloxpUnload(IN PDRIVER_OBJECT DriverObject)
{
	DbgPrint("Goodbye from hello2003!\n");
}

void Test(void)
{
	__try
	{
		//做一些事哈
		DbgPrint(TEXT("我是你的大皇冠\n"));
		return;
	}
	__finally
	{
		//程序退出前必须执行到这里,比如释放资源等等
		DbgPrint(TEXT("打我PG我不乖\n"));

	}

	return;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: