+ FILE * fd = _wfopen ( crashdump_path, L"r, ccs=UTF-8" );
+ if( !fd )
+ return;
+ fclose( fd );
+
+ int answer = MessageBox( NULL, L"VLC media player just crashed." \
+ " Do you want to send a bug report to the developers team?",
+ L"VLC crash reporting", MB_YESNO);
+
+ if(answer == IDYES)
+ {
+ HINTERNET Hint = InternetOpen(L"VLC Crash Reporter", INTERNET_OPEN_TYPE_PRECONFIG, NULL,NULL,0);
+ if(Hint)
+ {
+ HINTERNET ftp = InternetConnect(Hint, L"crash.videolan.org", INTERNET_DEFAULT_FTP_PORT,
+ NULL, NULL, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
+ if(ftp)
+ {
+ SYSTEMTIME now;
+ GetSystemTime(&now);
+ wchar_t remote_file[MAX_PATH];
+ swprintf( remote_file, L"/crashes-win32/%04d%02d%02d%02d%02d%02d",
+ now.wYear, now.wMonth, now.wDay, now.wHour, now.wMinute, now.wSecond );
+
+ if( FtpPutFile( ftp, crashdump_path, remote_file, FTP_TRANSFER_TYPE_BINARY, 0) )
+ MessageBox( NULL, L"Report sent correctly. Thanks a lot for the help.",
+ L"Report sent", MB_OK);
+ else
+ MessageBox( NULL, L"There was an error while transferring to the FTP server. "\
+ "Thanks a lot for the help anyway.",
+ L"Report sending failed", MB_OK);
+ InternetCloseHandle(ftp);
+ }
+ else
+ {
+ MessageBox( NULL, L"There was an error while connecting to the FTP server. "\
+ "Thanks a lot for the help anyway.",
+ L"Report sending failed", MB_OK);
+ fprintf(stderr,"Can't connect to FTP server 0x%08lu\n",
+ (unsigned long)GetLastError());
+ }
+ InternetCloseHandle(Hint);
+ }
+ else
+ {
+ MessageBox( NULL, L"There was an error while connecting to Internet. "\
+ "Thanks a lot for the help anyway.",
+ L"Report sending failed", MB_OK);
+ }
+ }
+
+ _wremove(crashdump_path);
+}
+
+/*****************************************************************************
+ * vlc_exception_filter: handles unhandled exceptions, like segfaults
+ *****************************************************************************/
+LONG WINAPI vlc_exception_filter(struct _EXCEPTION_POINTERS *lpExceptionInfo)
+{
+ if(IsDebuggerPresent())
+ {
+ //If a debugger is present, pass the exception to the debugger with EXCEPTION_CONTINUE_SEARCH
+ return EXCEPTION_CONTINUE_SEARCH;
+ }
+ else
+ {
+ fprintf( stderr, "unhandled vlc exception\n" );
+
+ FILE * fd = _wfopen ( crashdump_path, L"w, ccs=UTF-8" );
+
+ if( !fd )
+ {
+ fprintf( stderr, "\nerror while opening file" );
+ exit( 1 );
+ }
+
+ OSVERSIONINFO osvi;
+ ZeroMemory( &osvi, sizeof(OSVERSIONINFO) );
+ osvi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
+ GetVersionEx( &osvi );
+
+ fwprintf( fd, L"[version]\nOS=%d.%d.%d.%d.%s\nVLC=" VERSION_MESSAGE, osvi.dwMajorVersion,
+ osvi.dwMinorVersion,
+ osvi.dwBuildNumber,
+ osvi.dwPlatformId,
+ osvi.szCSDVersion);
+
+ const CONTEXT *const pContext = (const CONTEXT *)lpExceptionInfo->ContextRecord;
+ const EXCEPTION_RECORD *const pException = (const EXCEPTION_RECORD *)lpExceptionInfo->ExceptionRecord;
+ /*No nested exceptions for now*/
+ fwprintf( fd, L"\n\n[exceptions]\n%08x at %px",pException->ExceptionCode,
+ pException->ExceptionAddress );
+
+ for( unsigned int i = 0; i < pException->NumberParameters; i++ )
+ fwprintf( fd, L" | %p", pException->ExceptionInformation[i] );
+
+#ifdef WIN64
+ fwprintf( fd, L"\n\n[context]\nRDI:%px\nRSI:%px\n" \
+ "RBX:%px\nRDX:%px\nRCX:%px\nRAX:%px\n" \
+ "RBP:%px\nRIP:%px\nRSP:%px\nR8:%px\n" \
+ "R9:%px\nR10:%px\nR11:%px\nR12:%px\n" \
+ "R13:%px\nR14:%px\nR15:%px\n",
+ pContext->Rdi,pContext->Rsi,pContext->Rbx,
+ pContext->Rdx,pContext->Rcx,pContext->Rax,
+ pContext->Rbp,pContext->Rip,pContext->Rsp,
+ pContext->R8,pContext->R9,pContext->R10,
+ pContext->R11,pContext->R12,pContext->R13,
+ pContext->R14,pContext->R15 );
+#else
+ fwprintf( fd, L"\n\n[context]\nEDI:%px\nESI:%px\n" \
+ "EBX:%px\nEDX:%px\nECX:%px\nEAX:%px\n" \
+ "EBP:%px\nEIP:%px\nESP:%px\n",
+ pContext->Edi,pContext->Esi,pContext->Ebx,
+ pContext->Edx,pContext->Ecx,pContext->Eax,
+ pContext->Ebp,pContext->Eip,pContext->Esp );
+#endif
+
+ HANDLE hpid = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
+ FALSE, GetCurrentProcessId());
+ if (hpid) {
+ HMODULE mods[1024];
+ DWORD size;
+ if (EnumProcessModules(hpid, mods, sizeof(mods), &size)) {
+ fwprintf( fd, L"\n\n[modules]\n" );
+ for (unsigned int i = 0; i < size / sizeof(HMODULE); i++) {
+ wchar_t module[ 256 ];
+ GetModuleFileName(mods[i], module, 256);
+ fwprintf( fd, L"%p|%s\n", mods[i], module);
+ }
+ }
+ CloseHandle(hpid);
+ }
+
+
+ fwprintf( fd, L"\n[stacktrace]\n#EIP|base|module\n" );
+
+#ifdef WIN64
+ LPCVOID caller = (LPCVOID)pContext->Rip;
+ LPVOID *pBase = (LPVOID*)pContext->Rbp;
+#else
+ LPVOID *pBase = (LPVOID*)pContext->Ebp;
+ LPCVOID caller = (LPCVOID)pContext->Eip;
+#endif
+ for( unsigned frame = 0; frame <= 100; frame++ )
+ {
+ MEMORY_BASIC_INFORMATION mbi;
+ wchar_t module[ 256 ];
+ VirtualQuery( caller, &mbi, sizeof( mbi ) ) ;
+ GetModuleFileName( mbi.AllocationBase, module, 256 );
+ fwprintf( fd, L"%p|%s\n", caller, module );
+
+ /*The last BP points to NULL!*/
+ caller = *(pBase + 1);
+ if( !caller )
+ break;
+ pBase = *pBase;
+ }
+
+ fclose( fd );
+ fflush( stderr );
+ exit( 1 );
+ }