Add OsRtlGetVersion.
#6318
Sean Hall committed
Feb 7, 2021 at 17:38 UTC
69567aaa95f41812a49afa7454b69a3d79c5010d
2 files changed
+44
src/dutil/inc/osutil.h
+3
@@ -33,6 +33,9 @@ HRESULT DAPI OsIsRunningPrivileged(
33
HRESULT DAPI OsIsUacEnabled(
34
__out BOOL* pfUacEnabled
35
);
36
+HRESULT DAPI OsRtlGetVersion(
37
+ __inout RTL_OSVERSIONINFOEXW* pOvix
38
+ );
39
40
#ifdef __cplusplus
41
}
src/dutil/osutil.cpp
+41
@@ -2,8 +2,11 @@
2
3
#include "precomp.h"
4
5
+typedef NTSTATUS(NTAPI* PFN_RTL_GET_VERSION)(_Out_ PRTL_OSVERSIONINFOEXW lpVersionInformation);
6
+
7
OS_VERSION vOsVersion = OS_VERSION_UNKNOWN;
8
DWORD vdwOsServicePack = 0;
9
+RTL_OSVERSIONINFOEXW vovix = { };
10
11
/********************************************************************
12
OsGetVersion
@@ -186,3 +189,41 @@ LExit:
189
190
return hr;
191
}
192
+
193
+HRESULT DAPI OsRtlGetVersion(
194
+ __inout RTL_OSVERSIONINFOEXW* pOvix
195
+ )
196
+{
197
+ HRESULT hr = S_OK;
198
+ HMODULE hNtdll = NULL;
199
+ PFN_RTL_GET_VERSION pfnRtlGetVersion = NULL;
200
+
201
+ if (vovix.dwOSVersionInfoSize)
202
+ {
203
+ ExitFunction();
204
+ }
205
+
206
+ vovix.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);
207
+
208
+ hr = LoadSystemLibrary(L"ntdll.dll", &hNtdll);
209
+ if (E_MODNOTFOUND == hr)
210
+ {
211
+ ExitOnRootFailure(hr = E_NOTIMPL, "Failed to load ntdll.dll");
212
+ }
213
+ ExitOnFailure(hr, "Failed to load ntdll.dll.");
214
+
215
+ pfnRtlGetVersion = reinterpret_cast<PFN_RTL_GET_VERSION>(::GetProcAddress(hNtdll, "RtlGetVersion"));
216
+ ExitOnNullWithLastError(pfnRtlGetVersion, hr, "Failed to locate RtlGetVersion.");
217
+
218
+ hr = static_cast<HRESULT>(pfnRtlGetVersion(&vovix));
219
+
220
+LExit:
221
+ memcpy(pOvix, &vovix, sizeof(RTL_OSVERSIONINFOEXW));
222
+
223
+ if (hNtdll)
224
+ {
225
+ ::FreeLibrary(hNtdll);
226
+ }
227
+
228
+ return hr;
229
+}