1 /* 2 * PROJECT: Dr. Watson crash reporter 3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) 4 * PURPOSE: Output system info 5 * COPYRIGHT: Copyright 2017 Mark Jansen (mark.jansen@reactos.org) 6 */ 7 8 #include "precomp.h" 9 #include <udmihelp.h> 10 #include <winreg.h> 11 #include <reactos/buildno.h> 12 #include <reactos/stubs.h> 13 14 static const char* Exception2Str(DWORD code) 15 { 16 switch (code) 17 { 18 case EXCEPTION_ACCESS_VIOLATION: return "EXCEPTION_ACCESS_VIOLATION"; 19 case EXCEPTION_DATATYPE_MISALIGNMENT: return "EXCEPTION_DATATYPE_MISALIGNMENT"; 20 case EXCEPTION_BREAKPOINT: return "EXCEPTION_BREAKPOINT"; 21 case EXCEPTION_SINGLE_STEP: return "EXCEPTION_SINGLE_STEP"; 22 case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: return "EXCEPTION_ARRAY_BOUNDS_EXCEEDED"; 23 case EXCEPTION_FLT_DENORMAL_OPERAND: return "EXCEPTION_FLT_DENORMAL_OPERAND"; 24 case EXCEPTION_FLT_DIVIDE_BY_ZERO: return "EXCEPTION_FLT_DIVIDE_BY_ZERO"; 25 case EXCEPTION_FLT_INEXACT_RESULT: return "EXCEPTION_FLT_INEXACT_RESULT"; 26 case EXCEPTION_FLT_INVALID_OPERATION: return "EXCEPTION_FLT_INVALID_OPERATION"; 27 case EXCEPTION_FLT_OVERFLOW: return "EXCEPTION_FLT_OVERFLOW"; 28 case EXCEPTION_FLT_STACK_CHECK: return "EXCEPTION_FLT_STACK_CHECK"; 29 case EXCEPTION_FLT_UNDERFLOW: return "EXCEPTION_FLT_UNDERFLOW"; 30 case EXCEPTION_INT_DIVIDE_BY_ZERO: return "EXCEPTION_INT_DIVIDE_BY_ZERO"; 31 case EXCEPTION_INT_OVERFLOW: return "EXCEPTION_INT_OVERFLOW"; 32 case EXCEPTION_PRIV_INSTRUCTION: return "EXCEPTION_PRIV_INSTRUCTION"; 33 case EXCEPTION_IN_PAGE_ERROR: return "EXCEPTION_IN_PAGE_ERROR"; 34 case EXCEPTION_ILLEGAL_INSTRUCTION: return "EXCEPTION_ILLEGAL_INSTRUCTION"; 35 case EXCEPTION_NONCONTINUABLE_EXCEPTION: return "EXCEPTION_NONCONTINUABLE_EXCEPTION"; 36 case EXCEPTION_STACK_OVERFLOW: return "EXCEPTION_STACK_OVERFLOW"; 37 case EXCEPTION_INVALID_DISPOSITION: return "EXCEPTION_INVALID_DISPOSITION"; 38 case EXCEPTION_GUARD_PAGE: return "EXCEPTION_GUARD_PAGE"; 39 case EXCEPTION_INVALID_HANDLE: return "EXCEPTION_INVALID_HANDLE"; 40 case EXCEPTION_WINE_STUB: return "EXCEPTION_WINE_STUB"; 41 } 42 43 return "--"; 44 } 45 46 static void ReadKey(HKEY hKey, const char* ValueName, char* Buffer, DWORD size) 47 { 48 DWORD dwType; 49 LSTATUS ret = RegQueryValueExA(hKey, ValueName, NULL, &dwType, (LPBYTE)Buffer, &size); 50 if (ret != ERROR_SUCCESS || dwType != REG_SZ) 51 Buffer[0] = '\0'; 52 } 53 54 void PrintSystemInfo(FILE* output, DumpData& data) 55 { 56 SYSTEMTIME LocalTime; 57 GetLocalTime(&LocalTime); 58 xfprintf(output, NEWLINE "ReactOS " KERNEL_VERSION_STR " DrWtsn32" NEWLINE NEWLINE); 59 xfprintf(output, "Application exception occurred:" NEWLINE); 60 xfprintf(output, " App: %ls (pid=%d, tid=0x%x)" NEWLINE, data.ProcessName.c_str(), data.ProcessID, data.ThreadID); 61 xfprintf(output, " When: %d/%d/%d @ %02d:%02d:%02d.%d" NEWLINE, 62 LocalTime.wDay, LocalTime.wMonth, LocalTime.wYear, 63 LocalTime.wHour, LocalTime.wMinute, LocalTime.wSecond, LocalTime.wMilliseconds); 64 65 xfprintf(output, " First chance: %u" NEWLINE, data.ExceptionInfo.dwFirstChance); 66 EXCEPTION_RECORD& Record = data.ExceptionInfo.ExceptionRecord; 67 xfprintf(output, " Exception number: 0x%08x (%s)" NEWLINE, Record.ExceptionCode, Exception2Str(Record.ExceptionCode)); 68 xfprintf(output, " Exception flags: 0x%08x" NEWLINE, Record.ExceptionFlags); 69 xfprintf(output, " Exception address: %p" NEWLINE, Record.ExceptionAddress); 70 if (Record.NumberParameters) 71 { 72 xfprintf(output, " Exception parameters: %u" NEWLINE, Record.NumberParameters); 73 for (DWORD n = 0; n < std::min<DWORD>(EXCEPTION_MAXIMUM_PARAMETERS, Record.NumberParameters); ++n) 74 { 75 xfprintf(output, " Parameter %u: 0x%p" NEWLINE, n, Record.ExceptionInformation[n]); 76 } 77 } 78 79 char Buffer[MAX_PATH]; 80 DWORD count = sizeof(Buffer); 81 xfprintf(output, NEWLINE "*----> System Information <----*" NEWLINE NEWLINE); 82 if (GetComputerNameA(Buffer, &count)) 83 xfprintf(output, " Computer Name: %s" NEWLINE, Buffer); 84 count = sizeof(Buffer); 85 if (GetUserNameA(Buffer, &count)) 86 xfprintf(output, " User Name: %s" NEWLINE, Buffer); 87 88 89 PVOID SMBiosBuf; 90 PCHAR DmiStrings[ID_STRINGS_MAX] = { 0 }; 91 SMBiosBuf = LoadSMBiosData(DmiStrings); 92 if (SMBiosBuf) 93 { 94 if (DmiStrings[BIOS_VENDOR]) 95 xfprintf(output, " BIOS Vendor: %s" NEWLINE, DmiStrings[BIOS_VENDOR]); 96 if (DmiStrings[BIOS_VERSION]) 97 xfprintf(output, " BIOS Version: %s" NEWLINE, DmiStrings[BIOS_VERSION]); 98 if (DmiStrings[BIOS_DATE]) 99 xfprintf(output, " BIOS Date: %s" NEWLINE, DmiStrings[BIOS_DATE]); 100 if (DmiStrings[SYS_VENDOR]) 101 xfprintf(output, " System Manufacturer: %s" NEWLINE, DmiStrings[SYS_VENDOR]); 102 if (DmiStrings[SYS_FAMILY]) 103 xfprintf(output, " System Family: %s" NEWLINE, DmiStrings[SYS_FAMILY]); 104 if (DmiStrings[SYS_PRODUCT]) 105 xfprintf(output, " System Model: %s" NEWLINE, DmiStrings[SYS_PRODUCT]); 106 if (DmiStrings[SYS_VERSION]) 107 xfprintf(output, " System Version: %s" NEWLINE, DmiStrings[SYS_VERSION]); 108 if (DmiStrings[SYS_SKU]) 109 xfprintf(output, " System SKU: %s" NEWLINE, DmiStrings[SYS_SKU]); 110 if (DmiStrings[BOARD_VENDOR]) 111 xfprintf(output, " Baseboard Manufacturer: %s" NEWLINE, DmiStrings[BOARD_VENDOR]); 112 if (DmiStrings[BOARD_NAME]) 113 xfprintf(output, " Baseboard Model: %s" NEWLINE, DmiStrings[BOARD_NAME]); 114 if (DmiStrings[BOARD_VERSION]) 115 xfprintf(output, " Baseboard Version: %s" NEWLINE, DmiStrings[BOARD_VERSION]); 116 FreeSMBiosData(SMBiosBuf); 117 } 118 119 SYSTEM_INFO info; 120 GetSystemInfo(&info); 121 xfprintf(output, " Number of Processors: %d" NEWLINE, info.dwNumberOfProcessors); 122 123 HKEY hKey; 124 LONG ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 125 0, KEY_READ, &hKey); 126 if (ret == ERROR_SUCCESS) 127 { 128 DWORD dwType; 129 count = sizeof(Buffer); 130 ret = RegQueryValueExA(hKey, "Identifier", NULL, &dwType, (LPBYTE)Buffer, &count); 131 if (ret == ERROR_SUCCESS && dwType == REG_SZ) 132 { 133 Buffer[count] = '\0'; 134 xfprintf(output, " Processor Type: %s" NEWLINE, Buffer); 135 } 136 RegCloseKey(hKey); 137 } 138 139 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &hKey); 140 if (ret == ERROR_SUCCESS) 141 { 142 char Version[50]; 143 ReadKey(hKey, "ProductName", Buffer, sizeof(Buffer)); 144 ReadKey(hKey, "CurrentVersion", Version, sizeof(Version)); 145 xfprintf(output, " %s Version: %s" NEWLINE, Buffer, Version); 146 ReadKey(hKey, "BuildLab", Buffer, sizeof(Buffer)); 147 xfprintf(output, " BuildLab: %s" NEWLINE, Buffer); 148 ReadKey(hKey, "CSDVersion", Buffer, sizeof(Buffer)); 149 if (Buffer[0]) 150 xfprintf(output, " Service Pack: %s" NEWLINE, Buffer); 151 ReadKey(hKey, "CurrentType", Buffer, sizeof(Buffer)); 152 xfprintf(output, " Current Type: %s" NEWLINE, Buffer); 153 ReadKey(hKey, "RegisteredOrganization", Buffer, sizeof(Buffer)); 154 xfprintf(output, " Registered Organization: %s" NEWLINE, Buffer); 155 ReadKey(hKey, "RegisteredOwner", Buffer, sizeof(Buffer)); 156 xfprintf(output, " Registered Owner: %s" NEWLINE, Buffer); 157 158 RegCloseKey(hKey); 159 } 160 } 161