暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Dump生成

原创 哦豁 2021-08-09
412

/////////////////////////////////////////////////////////////
//
// File: BRExceptionFilter.cpp
// Author: Blood’s Rust
// Date: 2012.03.20
// Version: 1.0.0.0
//
/////////////////////////////////////////////////////////////
//#include “stdafx.h”
#include “windows.h”
#include “windef.h”
#include “stdio.h”
#include “tchar.h”
#include “BRExceptionFilter.h”

#include “RXLogCommon.h”
#include “DataCenter.h”

// Declarations
#ifndef _UNICODE
extern “C” int WinMainCRTStartup(void);
#else
extern “C” int wWinMainCRTStartup(void);
#endif

void DisableSetUnhandledExceptionFilter()
{

HINSTANCE hDll = LoadLibrary(_T("kernel32.dll"));
if(hDll)
{
	void *addr = (void*)GetProcAddress(hDll, "SetUnhandledExceptionFilter");
	if (addr)  
	{
		unsigned char code[16];
		int size = 0;
		code[size++] = 0x33;
		code[size++] = 0xC0;
		code[size++] = 0xC2;
		code[size++] = 0x04;
		code[size++] = 0x00;

		DWORD dwOldFlag, dwTempFlag;
		VirtualProtect(addr, size, PAGE_READWRITE, &dwOldFlag);
		WriteProcessMemory(GetCurrentProcess(), addr, code, size, NULL);
		VirtualProtect(addr, size, dwOldFlag, &dwTempFlag);
	}
}

}

long __stdcall BRExceptionFilterWindows(_EXCEPTION_POINTERS* pExceptionInfo)
{
return BRExceptionFilter(pExceptionInfo);
}

long BRExceptionFilter(_EXCEPTION_POINTERS* pExceptionInfo)
{
HINSTANCE hDll = LoadLibrary(_T(“Dbghelp.dll”));
if(hDll)
{
FNDUMPWRITEDUMP pfnMiniDumpWriteDump = NULL;
pfnMiniDumpWriteDump = (FNDUMPWRITEDUMP)GetProcAddress(hDll, “MiniDumpWriteDump”);

	if(pfnMiniDumpWriteDump)
	{
		TCHAR szFile[MAX_PATH] = {0};
		::GetModuleFileName(NULL, szFile, MAX_PATH);
		TCHAR tmp[64] ={0};
		sprintf(tmp, "_%s_%d.dmp", __argv[1], GetTickCount());
		_tcscat(szFile, tmp);

		HANDLE hFile = ::CreateFile(szFile, FILE_ALL_ACCESS, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 
		if(hFile)
		{
			MINIDUMP_EXCEPTION_INFORMATION mei; 
			ZeroMemory(&mei, sizeof(mei));
			mei.ExceptionPointers	= pExceptionInfo;
			mei.ThreadId			= GetCurrentThreadId();
			mei.ClientPointers		= TRUE;

			if(pfnMiniDumpWriteDump) pfnMiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &mei, NULL, NULL);
		}

		::CloseHandle(hFile);
	}
}

ExitProcess(0);
return EXCEPTION_CONTINUE_SEARCH;

}

extern long __stdcall BRExceptionFilterWindows(_EXCEPTION_POINTERS* pExceptionInfo);

// Definitions
int BRWinMainCRTStartup()
{
SetUnhandledExceptionFilter(BRExceptionFilterWindows);
//DisableSetUnhandledExceptionFilter();

/*
#ifndef _UNICODE
return WinMainCRTStartup();
#else
return wWinMainCRTStartup();
#endif*/
return 0;
}

/////////////////////////////////////////////////////////////

1
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论