ReactOS  0.4.15-dev-3440-g915569a
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 #include <reactos/stubs.h>
13 
14 static const char* Exception2Str(DWORD code)
15 {
16  switch (code)
17  {
18 #define EX_TO_STR(name) case (DWORD)(name): return #name
43  }
44 
45  return "--";
46 }
47 
48 static void ReadKey(HKEY hKey, const char* ValueName, char* Buffer, DWORD size)
49 {
50  DWORD dwType;
52  if (ret != ERROR_SUCCESS || dwType != REG_SZ)
53  Buffer[0] = '\0';
54 }
55 
57 {
58  SYSTEMTIME LocalTime;
59  GetLocalTime(&LocalTime);
60  xfprintf(output, NEWLINE "ReactOS " KERNEL_VERSION_STR " DrWtsn32" NEWLINE NEWLINE);
61  xfprintf(output, "Application exception occurred:" NEWLINE);
62  xfprintf(output, " App: %ls (pid=%d, tid=0x%x)" NEWLINE, data.ProcessName.c_str(), data.ProcessID, data.ThreadID);
63  xfprintf(output, " When: %d/%d/%d @ %02d:%02d:%02d.%d" NEWLINE,
64  LocalTime.wDay, LocalTime.wMonth, LocalTime.wYear,
65  LocalTime.wHour, LocalTime.wMinute, LocalTime.wSecond, LocalTime.wMilliseconds);
66 
67  xfprintf(output, " First chance: %u" NEWLINE, data.ExceptionInfo.dwFirstChance);
68  EXCEPTION_RECORD& Record = data.ExceptionInfo.ExceptionRecord;
69  xfprintf(output, " Exception number: 0x%08x (%s)" NEWLINE, Record.ExceptionCode, Exception2Str(Record.ExceptionCode));
70  xfprintf(output, " Exception flags: 0x%08x" NEWLINE, Record.ExceptionFlags);
71  xfprintf(output, " Exception address: %p" NEWLINE, Record.ExceptionAddress);
72  if (Record.NumberParameters)
73  {
74  xfprintf(output, " Exception parameters: %u" NEWLINE, Record.NumberParameters);
75  for (DWORD n = 0; n < std::min<DWORD>(EXCEPTION_MAXIMUM_PARAMETERS, Record.NumberParameters); ++n)
76  {
77  xfprintf(output, " Parameter %u: 0x%p" NEWLINE, n, Record.ExceptionInformation[n]);
78  }
79  }
80 
81  char Buffer[MAX_PATH];
82  DWORD count = sizeof(Buffer);
83  xfprintf(output, NEWLINE "*----> System Information <----*" NEWLINE NEWLINE);
85  xfprintf(output, " Computer Name: %s" NEWLINE, Buffer);
86  count = sizeof(Buffer);
87  if (GetUserNameA(Buffer, &count))
88  xfprintf(output, " User Name: %s" NEWLINE, Buffer);
89 
90 
91  PVOID SMBiosBuf;
92  PCHAR DmiStrings[ID_STRINGS_MAX] = { 0 };
93  SMBiosBuf = LoadSMBiosData(DmiStrings);
94  if (SMBiosBuf)
95  {
96  if (DmiStrings[BIOS_VENDOR])
97  xfprintf(output, " BIOS Vendor: %s" NEWLINE, DmiStrings[BIOS_VENDOR]);
98  if (DmiStrings[BIOS_VERSION])
99  xfprintf(output, " BIOS Version: %s" NEWLINE, DmiStrings[BIOS_VERSION]);
100  if (DmiStrings[BIOS_DATE])
101  xfprintf(output, " BIOS Date: %s" NEWLINE, DmiStrings[BIOS_DATE]);
102  if (DmiStrings[SYS_VENDOR])
103  xfprintf(output, " System Manufacturer: %s" NEWLINE, DmiStrings[SYS_VENDOR]);
104  if (DmiStrings[SYS_FAMILY])
105  xfprintf(output, " System Family: %s" NEWLINE, DmiStrings[SYS_FAMILY]);
106  if (DmiStrings[SYS_PRODUCT])
107  xfprintf(output, " System Model: %s" NEWLINE, DmiStrings[SYS_PRODUCT]);
108  if (DmiStrings[SYS_VERSION])
109  xfprintf(output, " System Version: %s" NEWLINE, DmiStrings[SYS_VERSION]);
110  if (DmiStrings[SYS_SKU])
111  xfprintf(output, " System SKU: %s" NEWLINE, DmiStrings[SYS_SKU]);
112  if (DmiStrings[BOARD_VENDOR])
113  xfprintf(output, " Baseboard Manufacturer: %s" NEWLINE, DmiStrings[BOARD_VENDOR]);
114  if (DmiStrings[BOARD_NAME])
115  xfprintf(output, " Baseboard Model: %s" NEWLINE, DmiStrings[BOARD_NAME]);
116  if (DmiStrings[BOARD_VERSION])
117  xfprintf(output, " Baseboard Version: %s" NEWLINE, DmiStrings[BOARD_VERSION]);
118  FreeSMBiosData(SMBiosBuf);
119  }
120 
123  xfprintf(output, " Number of Processors: %d" NEWLINE, info.dwNumberOfProcessors);
124 
125  HKEY hKey;
126  LONG ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
127  0, KEY_READ, &hKey);
128  if (ret == ERROR_SUCCESS)
129  {
130  DWORD dwType;
131  count = sizeof(Buffer);
132  ret = RegQueryValueExA(hKey, "Identifier", NULL, &dwType, (LPBYTE)Buffer, &count);
133  if (ret == ERROR_SUCCESS && dwType == REG_SZ)
134  {
135  Buffer[count] = '\0';
136  xfprintf(output, " Processor Type: %s" NEWLINE, Buffer);
137  }
138  RegCloseKey(hKey);
139  }
140 
141  ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &hKey);
142  if (ret == ERROR_SUCCESS)
143  {
144  char Version[50];
145  ReadKey(hKey, "ProductName", Buffer, sizeof(Buffer));
146  ReadKey(hKey, "CurrentVersion", Version, sizeof(Version));
147  xfprintf(output, " %s Version: %s" NEWLINE, Buffer, Version);
148  ReadKey(hKey, "BuildLab", Buffer, sizeof(Buffer));
149  xfprintf(output, " BuildLab: %s" NEWLINE, Buffer);
150  ReadKey(hKey, "CSDVersion", Buffer, sizeof(Buffer));
151  if (Buffer[0])
152  xfprintf(output, " Service Pack: %s" NEWLINE, Buffer);
153  ReadKey(hKey, "CurrentType", Buffer, sizeof(Buffer));
154  xfprintf(output, " Current Type: %s" NEWLINE, Buffer);
155  ReadKey(hKey, "RegisteredOrganization", Buffer, sizeof(Buffer));
156  xfprintf(output, " Registered Organization: %s" NEWLINE, Buffer);
157  ReadKey(hKey, "RegisteredOwner", Buffer, sizeof(Buffer));
158  xfprintf(output, " Registered Owner: %s" NEWLINE, Buffer);
159 
160  RegCloseKey(hKey);
161  }
162 }
BOOL WINAPI SHIM_OBJ_NAME() GetComputerNameA(LPSTR lpBuffer, LPDWORD lpnSize)
Definition: shimtest.c:21
signed char * PCHAR
Definition: retypes.h:7
#define EXCEPTION_NONCONTINUABLE_EXCEPTION
Definition: winbase.h:325
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:4027
#define EXCEPTION_FLT_UNDERFLOW
Definition: winbase.h:319
static UCHAR ULONG UCHAR ULONG UCHAR * output
Definition: bcrypt.c:29
Definition: dmilib.h:22
void xfprintf(FILE *stream, const char *fmt,...)
Definition: main.cpp:34
#define ERROR_SUCCESS
Definition: deptool.c:10
WORD wMonth
Definition: winbase.h:900
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define EXCEPTION_INT_DIVIDE_BY_ZERO
Definition: winbase.h:320
#define KEY_READ
Definition: nt_native.h:1023
#define EX_TO_STR(name)
#define EXCEPTION_ACCESS_VIOLATION
Definition: winbase.h:308
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define EXCEPTION_INVALID_HANDLE
Definition: winbase.h:329
#define EXCEPTION_INT_OVERFLOW
Definition: winbase.h:321
GLdouble n
Definition: glext.h:7729
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3321
#define EXCEPTION_FLT_INVALID_OPERATION
Definition: winbase.h:316
#define EXCEPTION_MAXIMUM_PARAMETERS
Definition: compat.h:206
#define EXCEPTION_SINGLE_STEP
Definition: winbase.h:311
_In_ struct _KBUGCHECK_REASON_CALLBACK_RECORD * Record
Definition: ketypes.h:256
WORD wYear
Definition: winbase.h:899
unsigned char * LPBYTE
Definition: typedefs.h:53
static void ReadKey(HKEY hKey, const char *ValueName, char *Buffer, DWORD size)
Definition: sysinfo.cpp:48
#define EXCEPTION_STACK_OVERFLOW
Definition: winbase.h:326
long LONG
Definition: pedump.c:60
WORD wMinute
Definition: winbase.h:904
Definition: bufpool.h:45
VOID WINAPI GetLocalTime(OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:286
#define STATUS_ASSERTION_FAILURE
Definition: ntstatus.h:960
GLsizeiptr size
Definition: glext.h:5919
#define EXCEPTION_FLT_DIVIDE_BY_ZERO
Definition: winbase.h:314
#define MAX_PATH
Definition: compat.h:34
#define EXCEPTION_ARRAY_BOUNDS_EXCEEDED
Definition: winbase.h:312
unsigned long DWORD
Definition: ntddk_ex.h:95
#define EXCEPTION_BREAKPOINT
Definition: winbase.h:310
IN PVOID IN PVOID IN USHORT Version
Definition: pci.h:361
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:56
WORD wSecond
Definition: winbase.h:905
struct _test_info info[]
Definition: SetCursorPos.c:19
WORD wMilliseconds
Definition: winbase.h:906
#define EXCEPTION_DATATYPE_MISALIGNMENT
Definition: winbase.h:309
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:240
static const char * Exception2Str(DWORD code)
Definition: sysinfo.cpp:14
int ret
#define EXCEPTION_FLT_DENORMAL_OPERAND
Definition: winbase.h:313
#define EXCEPTION_WINE_STUB
Definition: stubs.h:8
BOOL WINAPI GetUserNameA(LPSTR lpszName, LPDWORD lpSize)
Definition: misc.c:246
Definition: inflate.c:139
WORD wDay
Definition: winbase.h:902
FxAutoRegKey hKey
#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:903
#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 NULL
Definition: types.h:112
#define EXCEPTION_ILLEGAL_INSTRUCTION
Definition: winbase.h:324
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
#define RegCloseKey(hKey)
Definition: registry.h:40
#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