a7070eb33d14174bea366c41dda998148f1b7442
2 * PROJECT: ReactOS User-mode DMI/SMBIOS Helper Functions
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: SMBIOS table parsing functions
5 * COPYRIGHT: Copyright 2018 Stanislav Motylkov
10 static UINT (WINAPI
* pGetSystemFirmwareTable
)(DWORD
, DWORD
, PVOID
, DWORD
);
11 static BOOL bInitAPI
= FALSE
;
19 pGetSystemFirmwareTable
= NULL
;
21 hKernel
= GetModuleHandleW(L
"kernel32.dll");
25 pGetSystemFirmwareTable
= (void *)GetProcAddress(hKernel
, "GetSystemFirmwareTable");
28 /* Load SMBIOS Data */
31 _Inout_updates_(ID_STRINGS_MAX
) PCHAR
* Strings
)
35 DWORD dwType
, dwCheck
, dwBytes
= 0;
43 /* Try using GetSystemFirmwareTable (works on NT 5.2 and higher) */
44 if (pGetSystemFirmwareTable
)
46 dwBytes
= pGetSystemFirmwareTable('RSMB', 0, NULL
, 0);
49 pBuffer
= HeapAlloc(GetProcessHeap(), 0, dwBytes
);
54 dwCheck
= pGetSystemFirmwareTable('RSMB', 0, pBuffer
, dwBytes
);
55 if (dwCheck
!= dwBytes
)
57 HeapFree(GetProcessHeap(), 0, pBuffer
);
64 /* Try using registry (works on NT 5.1) */
65 if (RegOpenKeyW(HKEY_LOCAL_MACHINE
,
66 L
"SYSTEM\\CurrentControlSet\\Services\\mssmbios\\Data",
67 &hKey
) != ERROR_SUCCESS
)
72 if (RegQueryValueExW(hKey
,
77 &dwBytes
) != ERROR_SUCCESS
|| dwType
!= REG_BINARY
)
83 pBuffer
= HeapAlloc(GetProcessHeap(), 0, dwBytes
);
90 if (RegQueryValueExW(hKey
,
95 &dwBytes
) != ERROR_SUCCESS
|| dwType
!= REG_BINARY
)
97 HeapFree(GetProcessHeap(), 0, pBuffer
);
104 ParseSMBiosTables(pBuffer
, dwBytes
, Strings
);
108 /* Trim converted DMI string */
119 Length
= wcslen(pStr
);
123 /* Trim leading spaces */
124 while (i
< Length
&& pStr
[i
] <= L
' ')
132 memmove(pStr
, pStr
+ i
, (Length
+ 1) * sizeof(WCHAR
));
135 /* Trim trailing spaces */
136 while (Length
&& pStr
[Length
-1] <= L
' ')
138 pStr
[Length
-1] = L
'\0';
143 /* Convert string from SMBIOS */
146 _In_ PCSTR DmiString
,
156 cChars
= MultiByteToWideChar(CP_OEMCP
, 0, DmiString
, -1, pBuf
, cchBuf
);
158 /* NULL-terminate string */
159 pBuf
[min(cchBuf
-1, cChars
)] = L
'\0';
163 TrimDmiStringW(pBuf
);
169 /* Free SMBIOS Data */
177 HeapFree(GetProcessHeap(), 0, Buffer
);