/* * exceptShowException * * Purpose: * * Output exception information to the user. * */ VOID exceptShowException( EXCEPTION_POINTERS *ExceptionPointers ) { WCHAR szMessage[MAX_PATH * 2]; ULONGLONG IdFile; RtlSecureZeroMemory(&szMessage, sizeof(szMessage)); _strcpy(szMessage, L"Sorry, exception occurred at address: \n0x"); u64tohex((ULONG_PTR)ExceptionPointers->ExceptionRecord->ExceptionAddress, _strend(szMessage)); if (ExceptionPointers->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) { switch (ExceptionPointers->ExceptionRecord->ExceptionInformation[0]) { case 0: _strcat(szMessage, L"\n\nAttempt to read at address: \n0x"); break; case 1: _strcat(szMessage, L"\n\nAttempt to write at address: \n0x"); break; } u64tohex(ExceptionPointers->ExceptionRecord->ExceptionInformation[1], _strend(szMessage)); } IdFile = GetTickCount64(); if (exceptWriteDump(ExceptionPointers, IdFile)) { _strcat(szMessage, L"\n\nMinidump wobjex"); u64tostr(IdFile, _strend(szMessage)); _strcat(szMessage, L".dmp is in %TEMP% directory"); } _strcat(szMessage, L"\n\nPlease report this to the developers, thanks"); MessageBox(GetForegroundWindow(), szMessage, NULL, MB_ICONERROR); }
/* * exceptWriteDump * * Purpose: * * Writes minidump information to the specified file. * */ BOOL exceptWriteDump( EXCEPTION_POINTERS *ExceptionPointers, ULONGLONG IdFile ) { BOOL bResult; HANDLE hDbgHelp, hFile; DWORD dwRetVal; MINIDUMP_EXCEPTION_INFORMATION mdei; WCHAR szTemp[MAX_PATH * 2]; bResult = FALSE; hDbgHelp = GetModuleHandle(L"dbghelp.dll"); if (hDbgHelp == NULL) { RtlSecureZeroMemory(szTemp, sizeof(szTemp)); if (!GetSystemDirectory(szTemp, MAX_PATH)) { return bResult; } _strcat(szTemp, L"\\dbghelp.dll"); hDbgHelp = LoadLibraryEx(szTemp, 0, 0); if (hDbgHelp == NULL) { return bResult; } } pMiniDumpWriteDump = (pfnMiniDumpWriteDump)GetProcAddress(hDbgHelp, "MiniDumpWriteDump"); if (pMiniDumpWriteDump == NULL) { return bResult; } RtlSecureZeroMemory(szTemp, sizeof(szTemp)); dwRetVal = GetTempPath(MAX_PATH, szTemp); if (dwRetVal > MAX_PATH || (dwRetVal == 0)) { return bResult; } _strcat(szTemp, L"wobjex"); u64tostr(IdFile, _strend(szTemp)); _strcat(szTemp, L".dmp"); hFile = CreateFile(szTemp, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { mdei.ThreadId = GetCurrentThreadId(); mdei.ExceptionPointers = ExceptionPointers; mdei.ClientPointers = FALSE; bResult = pMiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &mdei, NULL, NULL); CloseHandle(hFile); } return bResult; }
/* * propSetDefaultInfo * * Purpose: * * Set information values for Basic page window, obtained from NtQueryObject calls * * ObjectBasicInformation and ObjectTypeInformation used * */ VOID propSetDefaultInfo( _In_ PROP_OBJECT_INFO *Context, _In_ HWND hwndDlg, _In_ HANDLE hObject ) { BOOL cond = FALSE; INT i; HWND hwndCB; NTSTATUS status; ULONG bytesNeeded; WCHAR szBuffer[100]; OBJECT_BASIC_INFORMATION obi; POBJECT_TYPE_INFORMATION TypeInfo = NULL; if ((hObject == NULL) || (Context == NULL)) { return; } // // Query object basic information. // RtlSecureZeroMemory(&obi, sizeof(obi)); status = NtQueryObject(hObject, ObjectBasicInformation, &obi, sizeof(OBJECT_BASIC_INFORMATION), &bytesNeeded); if (NT_SUCCESS(status)) { //Reference Count RtlSecureZeroMemory(szBuffer, sizeof(szBuffer)); u64tostr(obi.PointerCount, szBuffer); SetDlgItemText(hwndDlg, ID_OBJECT_REFC, szBuffer); //Handle Count RtlSecureZeroMemory(szBuffer, sizeof(szBuffer)); u64tostr(obi.HandleCount, szBuffer); SetDlgItemText(hwndDlg, ID_OBJECT_HANDLES, szBuffer); //NonPagedPoolCharge RtlSecureZeroMemory(szBuffer, sizeof(szBuffer)); u64tostr(obi.NonPagedPoolCharge, szBuffer); SetDlgItemText(hwndDlg, ID_OBJECT_NP_CHARGE, szBuffer); //PagedPoolCharge RtlSecureZeroMemory(szBuffer, sizeof(szBuffer)); u64tostr(obi.PagedPoolCharge, szBuffer); SetDlgItemText(hwndDlg, ID_OBJECT_PP_CHARGE, szBuffer); //Attributes hwndCB = GetDlgItem(hwndDlg, IDC_OBJECT_FLAGS); if (hwndCB) { SendMessage(hwndCB, CB_RESETCONTENT, (WPARAM)0, (LPARAM)0); EnableWindow(hwndCB, (obi.Attributes > 0) ? TRUE : FALSE); if (obi.Attributes != 0) { for (i = 0; i < 8; i++) { if (GET_BIT(obi.Attributes, i)) SendMessage(hwndCB, CB_ADDSTRING, (WPARAM)0, (LPARAM)T_ObjectFlags[i]); } SendMessage(hwndCB, CB_SETCURSEL, (WPARAM)0, (LPARAM)0); } } } // // Set flag bit for next usage on Type page. // do { bytesNeeded = 0; status = NtQueryObject(hObject, ObjectTypeInformation, NULL, 0, &bytesNeeded); if (bytesNeeded == 0) { SetLastError(RtlNtStatusToDosError(status)); break; } TypeInfo = supHeapAlloc(bytesNeeded + sizeof(ULONG_PTR)); if (TypeInfo == NULL) break; status = NtQueryObject(hObject, ObjectTypeInformation, TypeInfo, bytesNeeded, &bytesNeeded); if (NT_SUCCESS(status)) { if (TypeInfo->SecurityRequired) { SET_BIT(Context->ObjectFlags, 3); } if (TypeInfo->MaintainHandleCount) { SET_BIT(Context->ObjectFlags, 4); } } else { SetLastError(RtlNtStatusToDosError(status)); } } while (cond); if (TypeInfo) { supHeapFree(TypeInfo); } }