ReactOS  0.4.12-dev-36-g472787f
sysinfo.cpp
Go to the documentation of this file.
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 
13 static const char* Exception2Str(DWORD code)
14 {
15  switch (code)
16  {
17  case EXCEPTION_ACCESS_VIOLATION: return "EXCEPTION_ACCESS_VIOLATION";
18  case EXCEPTION_DATATYPE_MISALIGNMENT: return "EXCEPTION_DATATYPE_MISALIGNMENT";
19  case EXCEPTION_BREAKPOINT: return "EXCEPTION_BREAKPOINT";
20  case EXCEPTION_SINGLE_STEP: return "EXCEPTION_SINGLE_STEP";
21  case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: return "EXCEPTION_ARRAY_BOUNDS_EXCEEDED";
22  case EXCEPTION_FLT_DENORMAL_OPERAND: return "EXCEPTION_FLT_DENORMAL_OPERAND";
23  case EXCEPTION_FLT_DIVIDE_BY_ZERO: return "EXCEPTION_FLT_DIVIDE_BY_ZERO";
24  case EXCEPTION_FLT_INEXACT_RESULT: return "EXCEPTION_FLT_INEXACT_RESULT";
25  case EXCEPTION_FLT_INVALID_OPERATION: return "EXCEPTION_FLT_INVALID_OPERATION";
26  case EXCEPTION_FLT_OVERFLOW: return "EXCEPTION_FLT_OVERFLOW";
27  case EXCEPTION_FLT_STACK_CHECK: return "EXCEPTION_FLT_STACK_CHECK";
28  case EXCEPTION_FLT_UNDERFLOW: return "EXCEPTION_FLT_UNDERFLOW";
29  case EXCEPTION_INT_DIVIDE_BY_ZERO: return "EXCEPTION_INT_DIVIDE_BY_ZERO";
30  case EXCEPTION_INT_OVERFLOW: return "EXCEPTION_INT_OVERFLOW";
31  case EXCEPTION_PRIV_INSTRUCTION: return "EXCEPTION_PRIV_INSTRUCTION";
32  case EXCEPTION_IN_PAGE_ERROR: return "EXCEPTION_IN_PAGE_ERROR";
33  case EXCEPTION_ILLEGAL_INSTRUCTION: return "EXCEPTION_ILLEGAL_INSTRUCTION";
34  case EXCEPTION_NONCONTINUABLE_EXCEPTION: return "EXCEPTION_NONCONTINUABLE_EXCEPTION";
35  case EXCEPTION_STACK_OVERFLOW: return "EXCEPTION_STACK_OVERFLOW";
36  case EXCEPTION_INVALID_DISPOSITION: return "EXCEPTION_INVALID_DISPOSITION";
37  case EXCEPTION_GUARD_PAGE: return "EXCEPTION_GUARD_PAGE";
38  case EXCEPTION_INVALID_HANDLE: return "EXCEPTION_INVALID_HANDLE";
39  }
40 
41  return "--";
42 }
43 
44 static void ReadKey(HKEY hKey, const char* ValueName, char* Buffer, DWORD size)
45 {
46  DWORD dwType;
47  LSTATUS ret = RegQueryValueExA(hKey, ValueName, NULL, &dwType, (LPBYTE)Buffer, &size);
48  if (ret != ERROR_SUCCESS || dwType != REG_SZ)
49  Buffer[0] = '\0';
50 }
51 
53 {
54  SYSTEMTIME LocalTime;
55  GetLocalTime(&LocalTime);
56  xfprintf(output, NEWLINE "ReactOS " KERNEL_VERSION_STR " DrWtsn32" NEWLINE NEWLINE);
57  xfprintf(output, "Application exception occurred:" NEWLINE);
58  xfprintf(output, " App: %ls (pid=%d, tid=0x%x)" NEWLINE, data.ProcessName.c_str(), data.ProcessID, data.ThreadID);
59  xfprintf(output, " When: %d/%d/%d @ %02d:%02d:%02d.%d" NEWLINE,
60  LocalTime.wDay, LocalTime.wMonth, LocalTime.wYear,
61  LocalTime.wHour, LocalTime.wMinute, LocalTime.wSecond, LocalTime.wMilliseconds);
63  xfprintf(output, " Exception number: 0x%8x (%s)" NEWLINE, ExceptionCode, Exception2Str(ExceptionCode));
64 
65  char Buffer[MAX_PATH];
66  DWORD count = sizeof(Buffer);
67  xfprintf(output, NEWLINE "*----> System Information <----*" NEWLINE NEWLINE);
68  if (GetComputerNameA(Buffer, &count))
69  xfprintf(output, " Computer Name: %s" NEWLINE, Buffer);
70  count = sizeof(Buffer);
71  if (GetUserNameA(Buffer, &count))
72  xfprintf(output, " User Name: %s" NEWLINE, Buffer);
73 
74 
75  PVOID SMBiosBuf;
76  PCHAR DmiStrings[ID_STRINGS_MAX] = { 0 };
77  SMBiosBuf = LoadSMBiosData(DmiStrings);
78  if (SMBiosBuf)
79  {
80  if (DmiStrings[BIOS_VENDOR])
81  xfprintf(output, " BIOS Vendor: %s" NEWLINE, DmiStrings[BIOS_VENDOR]);
82  if (DmiStrings[BIOS_VERSION])
83  xfprintf(output, " BIOS Version: %s" NEWLINE, DmiStrings[BIOS_VERSION]);
84  if (DmiStrings[BIOS_DATE])
85  xfprintf(output, " BIOS Date: %s" NEWLINE, DmiStrings[BIOS_DATE]);
86  if (DmiStrings[SYS_VENDOR])
87  xfprintf(output, " System Manufacturer: %s" NEWLINE, DmiStrings[SYS_VENDOR]);
88  if (DmiStrings[SYS_FAMILY])
89  xfprintf(output, " System Family: %s" NEWLINE, DmiStrings[SYS_FAMILY]);
90  if (DmiStrings[SYS_PRODUCT])
91  xfprintf(output, " System Model: %s" NEWLINE, DmiStrings[SYS_PRODUCT]);
92  if (DmiStrings[SYS_VERSION])
93  xfprintf(output, " System Version: %s" NEWLINE, DmiStrings[SYS_VERSION]);
94  if (DmiStrings[SYS_SKU])
95  xfprintf(output, " System SKU: %s" NEWLINE, DmiStrings[SYS_SKU]);
96  if (DmiStrings[BOARD_VENDOR])
97  xfprintf(output, " Baseboard Manufacturer: %s" NEWLINE, DmiStrings[BOARD_VENDOR]);
98  if (DmiStrings[BOARD_NAME])
99  xfprintf(output, " Baseboard Model: %s" NEWLINE, DmiStrings[BOARD_NAME]);
100  if (DmiStrings[BOARD_VERSION])
101  xfprintf(output, " Baseboard Version: %s" NEWLINE, DmiStrings[BOARD_VERSION]);
102  FreeSMBiosData(SMBiosBuf);
103  }
104 
106  GetSystemInfo(&info);
107  xfprintf(output, " Number of Processors: %d" NEWLINE, info.dwNumberOfProcessors);
108 
109  HKEY hKey;
110  LONG ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
111  0, KEY_READ, &hKey);
112  if (ret == ERROR_SUCCESS)
113  {
114  DWORD dwType;
115  count = sizeof(Buffer);
116  ret = RegQueryValueExA(hKey, "Identifier", NULL, &dwType, (LPBYTE)Buffer, &count);
117  if (ret == ERROR_SUCCESS && dwType == REG_SZ)
118  {
119  Buffer[count] = '\0';
120  xfprintf(output, " Processor Type: %s" NEWLINE, Buffer);
121  }
122  RegCloseKey(hKey);
123  }
124 
125  ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &hKey);
126  if (ret == ERROR_SUCCESS)
127  {
128  char Version[50];
129  ReadKey(hKey, "ProductName", Buffer, sizeof(Buffer));
130  ReadKey(hKey, "CurrentVersion", Version, sizeof(Version));
131  xfprintf(output, " %s Version: %s" NEWLINE, Buffer, Version);
132  ReadKey(hKey, "BuildLab", Buffer, sizeof(Buffer));
133  xfprintf(output, " BuildLab: %s" NEWLINE, Buffer);
134  ReadKey(hKey, "CSDVersion", Buffer, sizeof(Buffer));
135  if (Buffer[0])
136  xfprintf(output, " Service Pack: %s" NEWLINE, Buffer);
137  ReadKey(hKey, "CurrentType", Buffer, sizeof(Buffer));
138  xfprintf(output, " Current Type: %s" NEWLINE, Buffer);
139  ReadKey(hKey, "RegisteredOrganization", Buffer, sizeof(Buffer));
140  xfprintf(output, " Registered Organization: %s" NEWLINE, Buffer);
141  ReadKey(hKey, "RegisteredOwner", Buffer, sizeof(Buffer));
142  xfprintf(output, " Registered Owner: %s" NEWLINE, Buffer);
143 
144  RegCloseKey(hKey);
145  }
146 }
signed char * PCHAR
Definition: retypes.h:7
#define EXCEPTION_NONCONTINUABLE_EXCEPTION
Definition: winbase.h:325
_Inout_ PIRP _In_ NTSTATUS ExceptionCode
Definition: cdprocs.h:1782
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4041
#define EXCEPTION_FLT_UNDERFLOW
Definition: winbase.h:319
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
IN PVOID IN PVOID IN USHORT Version
Definition: pci.h:359
Definition: dmilib.h:22
void xfprintf(FILE *stream, const char *fmt,...)
Definition: main.cpp:34
#define ERROR_SUCCESS
Definition: deptool.c:10
std::wstring ProcessName
Definition: drwtsn32.h:40
WORD wMonth
Definition: winbase.h:871
#define EXCEPTION_INT_DIVIDE_BY_ZERO
Definition: winbase.h:320
#define KEY_READ
Definition: nt_native.h:1023
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define EXCEPTION_ACCESS_VIOLATION
Definition: winbase.h:308
#define EXCEPTION_INVALID_HANDLE
Definition: winbase.h:329
#define EXCEPTION_INT_OVERFLOW
Definition: winbase.h:321
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3346
#define EXCEPTION_FLT_INVALID_OPERATION
Definition: winbase.h:316
#define EXCEPTION_SINGLE_STEP
Definition: winbase.h:311
BOOL WINAPI GetComputerNameA(LPSTR lpBuffer, LPDWORD lpnSize)
Definition: compname.c:322
struct _test_info info[]
Definition: SetCursorPos.c:19
DWORD ExceptionCode
Definition: compat.h:196
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
WORD wYear
Definition: winbase.h:870
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
static void ReadKey(HKEY hKey, const char *ValueName, char *Buffer, DWORD size)
Definition: sysinfo.cpp:44
#define EXCEPTION_STACK_OVERFLOW
Definition: winbase.h:326
long LONG
Definition: pedump.c:60
WORD wMinute
Definition: winbase.h:875
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
VOID WINAPI GetLocalTime(OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:276
DWORD ThreadID
Definition: drwtsn32.h:42
GLsizeiptr size
Definition: glext.h:5919
#define EXCEPTION_FLT_DIVIDE_BY_ZERO
Definition: winbase.h:314
#define MAX_PATH
Definition: compat.h:26
#define EXCEPTION_ARRAY_BOUNDS_EXCEEDED
Definition: winbase.h:312
unsigned long DWORD
Definition: ntddk_ex.h:95
#define EXCEPTION_BREAKPOINT
Definition: winbase.h:310
DWORD ProcessID
Definition: drwtsn32.h:41
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
void PrintSystemInfo(FILE *output, DumpData &data)
Definition: sysinfo.cpp:52
WORD wSecond
Definition: winbase.h:876
WORD wMilliseconds
Definition: winbase.h:877
#define EXCEPTION_DATATYPE_MISALIGNMENT
Definition: winbase.h:309
static const char * Exception2Str(DWORD code)
Definition: sysinfo.cpp:13
int ret
#define EXCEPTION_FLT_DENORMAL_OPERAND
Definition: winbase.h:313
EXCEPTION_RECORD ExceptionRecord
Definition: winbase.h:729
BOOL WINAPI GetUserNameA(LPSTR lpszName, LPDWORD lpSize)
Definition: misc.c:246
WORD wDay
Definition: winbase.h:873
#define EXCEPTION_FLT_OVERFLOW
Definition: winbase.h:317
#define EXCEPTION_INVALID_DISPOSITION
Definition: winbase.h:327
VOID FreeSMBiosData(_In_ PVOID Buffer)
Definition: udmihelp.c:177
WORD wHour
Definition: winbase.h:874
#define EXCEPTION_FLT_STACK_CHECK
Definition: winbase.h:318
VOID WINAPI GetSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
Definition: sysinfo.c:142
#define EXCEPTION_IN_PAGE_ERROR
Definition: winbase.h:323
#define EXCEPTION_ILLEGAL_INSTRUCTION
Definition: winbase.h:324
DWORD dwNumberOfProcessors
Definition: winbase.h:1130
PVOID LoadSMBiosData(_Inout_updates_(ID_STRINGS_MAX) PCHAR *Strings)
Definition: udmihelp.c:30
#define EXCEPTION_GUARD_PAGE
Definition: winbase.h:328
#define NEWLINE
Definition: drwtsn32.h:53
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define EXCEPTION_PRIV_INSTRUCTION
Definition: winbase.h:322
#define EXCEPTION_FLT_INEXACT_RESULT
Definition: winbase.h:315
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22
EXCEPTION_DEBUG_INFO ExceptionInfo
Definition: drwtsn32.h:46