diff options
author | XhmikosR <xhmikosr@users.sourceforge.net> | 2010-04-09 18:12:59 +0400 |
---|---|---|
committer | XhmikosR <xhmikosr@users.sourceforge.net> | 2010-04-09 18:12:59 +0400 |
commit | efbc9d9043ff8ff92716ddd00a5f61412d535593 (patch) | |
tree | 8f3e621f756cf1f5b4d64d97964c7e7abd8aaf08 /src/apps/mplayerc/MiniDump.cpp | |
parent | df6b139a6d9027156f614b68687e039e3a5854db (diff) |
revert r1783
git-svn-id: https://mpc-hc.svn.sourceforge.net/svnroot/mpc-hc/trunk@1785 10f7b99b-c216-0410-bff0-8a66a9350fd8
Diffstat (limited to 'src/apps/mplayerc/MiniDump.cpp')
-rw-r--r-- | src/apps/mplayerc/MiniDump.cpp | 222 |
1 files changed, 111 insertions, 111 deletions
diff --git a/src/apps/mplayerc/MiniDump.cpp b/src/apps/mplayerc/MiniDump.cpp index f3ab75434..41272e9d3 100644 --- a/src/apps/mplayerc/MiniDump.cpp +++ b/src/apps/mplayerc/MiniDump.cpp @@ -32,136 +32,136 @@ CMiniDump _Singleton; bool CMiniDump::m_bMiniDumpEnabled = false;
-typedef BOOL (WINAPI *MINIDUMPWRITEDUMP)(HANDLE hProcess, DWORD dwPid, HANDLE hFile, MINIDUMP_TYPE DumpType,
- CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
- CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
- CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam
- );
+typedef BOOL (WINAPI *MINIDUMPWRITEDUMP)( HANDLE hProcess, DWORD dwPid, HANDLE hFile, MINIDUMP_TYPE DumpType,
+ CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
+ CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
+ CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam
+ );
CMiniDump::CMiniDump()
{
#ifndef _DEBUG
- SetUnhandledExceptionFilter(UnhandledExceptionFilter);
+ SetUnhandledExceptionFilter( UnhandledExceptionFilter );
#ifndef _WIN64
- // Enable catching in CRT (http://blog.kalmbachnet.de/?postid=75)
+ // Enable catching in CRT (http://blog.kalmbachnet.de/?postid=75)
// PreventSetUnhandledExceptionFilter();
#endif
#endif
}
-LPTOP_LEVEL_EXCEPTION_FILTER WINAPI MyDummySetUnhandledExceptionFilter(LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter)
+LPTOP_LEVEL_EXCEPTION_FILTER WINAPI MyDummySetUnhandledExceptionFilter( LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter )
{
- return NULL;
+ return NULL;
}
BOOL CMiniDump::PreventSetUnhandledExceptionFilter()
{
- HMODULE hKernel32 = LoadLibrary(_T("kernel32.dll"));
- if(hKernel32 == NULL)
- return FALSE;
-
- void *pOrgEntry = GetProcAddress(hKernel32, "SetUnhandledExceptionFilter");
- if(pOrgEntry == NULL)
- return FALSE;
-
- unsigned char newJump[ 100 ];
- DWORD dwOrgEntryAddr = (DWORD) pOrgEntry;
- dwOrgEntryAddr += 5; // add 5 for 5 op-codes for jmp far
- void *pNewFunc = &MyDummySetUnhandledExceptionFilter;
- DWORD dwNewEntryAddr = (DWORD) pNewFunc;
- DWORD dwRelativeAddr = dwNewEntryAddr - dwOrgEntryAddr;
-
- newJump[ 0 ] = 0xE9; // JMP absolute
- memcpy(&newJump[ 1 ], &dwRelativeAddr, sizeof(pNewFunc));
- SIZE_T bytesWritten;
- BOOL bRet = WriteProcessMemory(GetCurrentProcess(), pOrgEntry, newJump, sizeof(pNewFunc) + 1, &bytesWritten);
- FreeLibrary(hKernel32);
- return bRet;
+ HMODULE hKernel32 = LoadLibrary( _T("kernel32.dll") );
+ if ( hKernel32 == NULL )
+ return FALSE;
+
+ void *pOrgEntry = GetProcAddress( hKernel32, "SetUnhandledExceptionFilter" );
+ if ( pOrgEntry == NULL )
+ return FALSE;
+
+ unsigned char newJump[ 100 ];
+ DWORD dwOrgEntryAddr = (DWORD) pOrgEntry;
+ dwOrgEntryAddr += 5; // add 5 for 5 op-codes for jmp far
+ void *pNewFunc = &MyDummySetUnhandledExceptionFilter;
+ DWORD dwNewEntryAddr = (DWORD) pNewFunc;
+ DWORD dwRelativeAddr = dwNewEntryAddr - dwOrgEntryAddr;
+
+ newJump[ 0 ] = 0xE9; // JMP absolute
+ memcpy( &newJump[ 1 ], &dwRelativeAddr, sizeof(pNewFunc) );
+ SIZE_T bytesWritten;
+ BOOL bRet = WriteProcessMemory( GetCurrentProcess(), pOrgEntry, newJump, sizeof(pNewFunc) + 1, &bytesWritten );
+ FreeLibrary( hKernel32 );
+ return bRet;
}
-LONG WINAPI CMiniDump::UnhandledExceptionFilter(_EXCEPTION_POINTERS *lpTopLevelExceptionFilter)
+LONG WINAPI CMiniDump::UnhandledExceptionFilter( _EXCEPTION_POINTERS *lpTopLevelExceptionFilter )
{
- LONG retval = EXCEPTION_CONTINUE_SEARCH;
- HWND hParent = NULL;
- HMODULE hDll = NULL;
- _TCHAR szResult[ 800 ];
- _TCHAR szDbgHelpPath[ _MAX_PATH ];
-
- if(!m_bMiniDumpEnabled)
- return 0;
-
- // firstly see if dbghelp.dll is around and has the function we need
- // look next to the EXE first, as the one in System32 might be old
- // (e.g. Windows 2000)
-
- if(GetModuleFileName(NULL, szDbgHelpPath, _MAX_PATH))
- {
- _TCHAR *pSlash = _tcsrchr(szDbgHelpPath, _T('\\'));
- if(pSlash != NULL)
- {
- _tcscpy_s(pSlash + 1, _MAX_PATH + szDbgHelpPath - pSlash, _T("DBGHELP.DLL"));
- hDll = ::LoadLibrary(szDbgHelpPath);
- }
- }
-
- if(hDll == NULL)
- {
- // load any version we can
- hDll = ::LoadLibrary(_T("DBGHELP.DLL"));
- }
-
- if(hDll != NULL)
- {
- MINIDUMPWRITEDUMP pMiniDumpWriteDump = (MINIDUMPWRITEDUMP)::GetProcAddress(hDll, "MiniDumpWriteDump");
- if(pMiniDumpWriteDump != NULL)
- {
- _TCHAR szDumpPath[ _MAX_PATH ];
- _TCHAR szVersion[ 40 ];
-
- GetModuleFileName(NULL, szDumpPath, _MAX_PATH);
- _stprintf_s(szVersion, countof(szVersion), _T(".%d.%d.%d.%d"), VERSION_MAJOR, VERSION_MINOR, VERSION_REV, VERSION_PATCH);
- _tcscat_s(szDumpPath, _MAX_PATH, szVersion);
- _tcscat_s(szDumpPath, _MAX_PATH, _T(".dmp"));
-
- // create the file
- HANDLE hFile = ::CreateFile(szDumpPath, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
- FILE_ATTRIBUTE_NORMAL, NULL);
-
- if(hFile != INVALID_HANDLE_VALUE)
- {
- _MINIDUMP_EXCEPTION_INFORMATION ExInfo;
-
- ExInfo.ThreadId = ::GetCurrentThreadId();
- ExInfo.ExceptionPointers = lpTopLevelExceptionFilter;
- ExInfo.ClientPointers = NULL;
-
- // write the dump
- BOOL bOK = pMiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ExInfo, NULL, NULL);
- if(bOK)
- {
- _stprintf_s(szResult, countof(szResult), ResStr(IDS_MPC_CRASH), szDumpPath);
- retval = EXCEPTION_EXECUTE_HANDLER;
- }
- else
- {
- _stprintf_s(szResult, countof(szResult), ResStr(IDS_MPC_MINIDUMP_FAIL), szDumpPath, GetLastError());
- }
-
- ::CloseHandle(hFile);
- }
- else
- {
- _stprintf_s(szResult, countof(szResult), ResStr(IDS_MPC_MINIDUMP_FAIL), szDumpPath, GetLastError());
- }
- }
- FreeLibrary(hDll);
- }
-
- if(szResult)
- MessageBox(NULL, szResult, _T("MPC-HC Mini Dump"), MB_OK);
-
- return retval;
+ LONG retval = EXCEPTION_CONTINUE_SEARCH;
+ HWND hParent = NULL;
+ HMODULE hDll = NULL;
+ _TCHAR szResult[ 800 ];
+ _TCHAR szDbgHelpPath[ _MAX_PATH ];
+
+ if ( !m_bMiniDumpEnabled )
+ return 0;
+
+ // firstly see if dbghelp.dll is around and has the function we need
+ // look next to the EXE first, as the one in System32 might be old
+ // (e.g. Windows 2000)
+
+ if ( GetModuleFileName(NULL, szDbgHelpPath, _MAX_PATH) )
+ {
+ _TCHAR *pSlash = _tcsrchr( szDbgHelpPath, _T('\\') );
+ if ( pSlash != NULL )
+ {
+ _tcscpy_s( pSlash + 1, _MAX_PATH + szDbgHelpPath - pSlash, _T("DBGHELP.DLL") );
+ hDll = ::LoadLibrary( szDbgHelpPath );
+ }
+ }
+
+ if ( hDll == NULL )
+ {
+ // load any version we can
+ hDll = ::LoadLibrary( _T("DBGHELP.DLL") );
+ }
+
+ if ( hDll != NULL )
+ {
+ MINIDUMPWRITEDUMP pMiniDumpWriteDump = (MINIDUMPWRITEDUMP)::GetProcAddress( hDll, "MiniDumpWriteDump" );
+ if ( pMiniDumpWriteDump != NULL )
+ {
+ _TCHAR szDumpPath[ _MAX_PATH ];
+ _TCHAR szVersion[ 40 ];
+
+ GetModuleFileName( NULL, szDumpPath, _MAX_PATH );
+ _stprintf_s( szVersion, countof(szVersion), _T(".%d.%d.%d.%d"), VERSION_MAJOR, VERSION_MINOR, VERSION_REV, VERSION_PATCH );
+ _tcscat_s( szDumpPath, _MAX_PATH, szVersion );
+ _tcscat_s( szDumpPath, _MAX_PATH, _T(".dmp") );
+
+ // create the file
+ HANDLE hFile = ::CreateFile( szDumpPath, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL, NULL );
+
+ if ( hFile != INVALID_HANDLE_VALUE )
+ {
+ _MINIDUMP_EXCEPTION_INFORMATION ExInfo;
+
+ ExInfo.ThreadId = ::GetCurrentThreadId();
+ ExInfo.ExceptionPointers = lpTopLevelExceptionFilter;
+ ExInfo.ClientPointers = NULL;
+
+ // write the dump
+ BOOL bOK = pMiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ExInfo, NULL, NULL );
+ if ( bOK )
+ {
+ _stprintf_s( szResult, countof(szResult), ResStr(IDS_MPC_CRASH), szDumpPath );
+ retval = EXCEPTION_EXECUTE_HANDLER;
+ }
+ else
+ {
+ _stprintf_s( szResult, countof(szResult), ResStr(IDS_MPC_MINIDUMP_FAIL), szDumpPath, GetLastError() );
+ }
+
+ ::CloseHandle( hFile );
+ }
+ else
+ {
+ _stprintf_s( szResult, countof(szResult), ResStr(IDS_MPC_MINIDUMP_FAIL), szDumpPath, GetLastError() );
+ }
+ }
+ FreeLibrary( hDll );
+ }
+
+ if ( szResult )
+ MessageBox( NULL, szResult, _T("MPC-HC Mini Dump"), MB_OK );
+
+ return retval;
}
|