ReactOS  0.4.13-dev-66-gc714b7f
udmihelp.c File Reference
#include "precomp.h"
Include dependency graph for udmihelp.c:

Go to the source code of this file.

Functions

static UINT (WINAPI *pGetSystemFirmwareTable)(DWORD
 
static VOID InitializeAPI ()
 
PVOID LoadSMBiosData (_Inout_updates_(ID_STRINGS_MAX) PCHAR *Strings)
 
VOID TrimDmiStringW (_Inout_ PWSTR pStr)
 
SIZE_T GetSMBiosStringW (_In_ PCSTR DmiString, _Out_ PWSTR pBuf, _In_ DWORD cchBuf, _In_ BOOL bTrim)
 
VOID FreeSMBiosData (_In_ PVOID Buffer)
 

Variables

static DWORD
 
static PVOID
 
static BOOL bInitAPI = FALSE
 

Function Documentation

◆ FreeSMBiosData()

VOID FreeSMBiosData ( _In_ PVOID  Buffer)

Definition at line 177 of file udmihelp.c.

179 {
180  if (!Buffer)
181  return;
182 
184 }
Definition: bufpool.h:45
#define GetProcessHeap()
Definition: compat.h:395
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by AllSysInfo(), GetSystemName(), InitializeSystemPage(), and PrintSystemInfo().

◆ GetSMBiosStringW()

SIZE_T GetSMBiosStringW ( _In_ PCSTR  DmiString,
_Out_ PWSTR  pBuf,
_In_ DWORD  cchBuf,
_In_ BOOL  bTrim 
)

Definition at line 145 of file udmihelp.c.

150 {
151  SIZE_T cChars;
152 
153  if (!DmiString)
154  {
155  if (cchBuf >= 1)
156  {
157  *pBuf = 0;
158  }
159  return 0;
160  }
161 
162  cChars = MultiByteToWideChar(CP_OEMCP, 0, DmiString, -1, pBuf, cchBuf);
163 
164  /* NULL-terminate string */
165  pBuf[min(cchBuf-1, cChars)] = L'\0';
166 
167  if (bTrim)
168  {
169  TrimDmiStringW(pBuf);
170  }
171 
172  return wcslen(pBuf);
173 }
static SCRIPT_CACHE SCRIPT_ANALYSIS OPENTYPE_TAG OPENTYPE_TAG int TEXTRANGE_PROPERTIES int const WCHAR int cChars
Definition: usp10.c:64
static const WCHAR L[]
Definition: oid.c:1250
ULONG_PTR SIZE_T
Definition: typedefs.h:78
VOID TrimDmiStringW(_Inout_ PWSTR pStr)
Definition: udmihelp.c:110
#define min(a, b)
Definition: monoChain.cc:55
#define MultiByteToWideChar
Definition: compat.h:100
#define CP_OEMCP
Definition: winnls.h:228
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by AllSysInfo(), GetBIOSValue(), and GetSystemName().

◆ InitializeAPI()

static VOID InitializeAPI ( )
static

Definition at line 15 of file udmihelp.c.

16 {
17  HANDLE hKernel;
18 
19  pGetSystemFirmwareTable = NULL;
20 
21  hKernel = GetModuleHandleW(L"kernel32.dll");
22  if (!hKernel)
23  return;
24 
25  pGetSystemFirmwareTable = (void *)GetProcAddress(hKernel, "GetSystemFirmwareTable");
26 }
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR L[]
Definition: oid.c:1250
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:845
#define GetProcAddress(x, y)
Definition: compat.h:410

Referenced by LoadSMBiosData().

◆ LoadSMBiosData()

PVOID LoadSMBiosData ( _Inout_updates_(ID_STRINGS_MAX) PCHAR Strings)

Definition at line 30 of file udmihelp.c.

32 {
33  PVOID pBuffer = NULL;
34  HKEY hKey;
35  DWORD dwType, dwCheck, dwBytes = 0;
36 
37  if (!bInitAPI)
38  {
39  InitializeAPI();
40  bInitAPI = TRUE;
41  }
42 
43  /* Try using GetSystemFirmwareTable (works on NT 5.2 and higher) */
44  if (pGetSystemFirmwareTable)
45  {
46  dwBytes = pGetSystemFirmwareTable('RSMB', 0, NULL, 0);
47  if (dwBytes > 0)
48  {
49  pBuffer = HeapAlloc(GetProcessHeap(), 0, dwBytes);
50  if (!pBuffer)
51  {
52  return NULL;
53  }
54  dwCheck = pGetSystemFirmwareTable('RSMB', 0, pBuffer, dwBytes);
55  if (dwCheck != dwBytes)
56  {
58  return NULL;
59  }
60  }
61  }
62  if (dwBytes == 0)
63  {
64  /* Try using registry (works on NT 5.1) */
66  L"SYSTEM\\CurrentControlSet\\Services\\mssmbios\\Data",
67  &hKey) != ERROR_SUCCESS)
68  {
69  return NULL;
70  }
71 
72  if (RegQueryValueExW(hKey,
73  L"SMBiosData",
74  NULL,
75  &dwType,
76  NULL,
77  &dwBytes) != ERROR_SUCCESS || dwType != REG_BINARY)
78  {
79  RegCloseKey(hKey);
80  return NULL;
81  }
82 
83  pBuffer = HeapAlloc(GetProcessHeap(), 0, dwBytes);
84  if (!pBuffer)
85  {
86  RegCloseKey(hKey);
87  return NULL;
88  }
89 
90  if (RegQueryValueExW(hKey,
91  L"SMBiosData",
92  NULL,
93  &dwType,
94  pBuffer,
95  &dwBytes) != ERROR_SUCCESS || dwType != REG_BINARY)
96  {
98  RegCloseKey(hKey);
99  return NULL;
100  }
101 
102  RegCloseKey(hKey);
103  }
104  ParseSMBiosTables(pBuffer, dwBytes, Strings);
105  return pBuffer;
106 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define REG_BINARY
Definition: nt_native.h:1496
VOID ParseSMBiosTables(_In_reads_bytes_(TableSize) PVOID SMBiosTables, _In_ ULONG TableSize, _Inout_updates_(ID_STRINGS_MAX) PCHAR *Strings)
Definition: dmilib.c:41
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3311
smooth NULL
Definition: ftsmooth.c:416
PVOID pBuffer
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4134
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR Strings[]
Definition: reg.c:35
static const WCHAR L[]
Definition: oid.c:1250
static BOOL bInitAPI
Definition: udmihelp.c:11
#define HeapFree(x, y, z)
Definition: compat.h:394
static VOID InitializeAPI()
Definition: udmihelp.c:15
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by AllSysInfo(), GetSystemName(), InitializeSystemPage(), and PrintSystemInfo().

◆ TrimDmiStringW()

VOID TrimDmiStringW ( _Inout_ PWSTR  pStr)

Definition at line 110 of file udmihelp.c.

112 {
113  SIZE_T Length;
114  UINT i = 0;
115 
116  if (!pStr)
117  return;
118 
119  Length = wcslen(pStr);
120  if (Length == 0)
121  return;
122 
123  /* Trim leading spaces */
124  while (i < Length && pStr[i] <= L' ')
125  {
126  i++;
127  }
128 
129  if (i > 0)
130  {
131  Length -= i;
132  memmove(pStr, pStr + i, (Length + 1) * sizeof(WCHAR));
133  }
134 
135  /* Trim trailing spaces */
136  while (Length && pStr[Length-1] <= L' ')
137  {
138  pStr[Length-1] = L'\0';
139  --Length;
140  }
141 }
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
static const WCHAR L[]
Definition: oid.c:1250
ULONG_PTR SIZE_T
Definition: typedefs.h:78
unsigned int UINT
Definition: ndis.h:50
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by GetSMBiosStringW(), InitializeSystemPage(), and wcsrep().

◆ UINT()

static UINT ( WINAPI pGetSystemFirmwareTable)
static

Variable Documentation

◆ bInitAPI

BOOL bInitAPI = FALSE
static

Definition at line 11 of file udmihelp.c.

Referenced by LoadSMBiosData().

◆ DWORD

Definition at line 10 of file udmihelp.c.

◆ PVOID

Definition at line 10 of file udmihelp.c.