ReactOS 0.4.16-dev-1946-g52006dd
registry.c File Reference
#include "wdfloader.h"
Include dependency graph for registry.c:

Go to the source code of this file.

Functions

NTSTATUS NTAPI GetVersionRegistryHandle (_In_ PWDF_BIND_INFO BindInfo, _Out_ PHANDLE HandleRegKey)
 Open framework version registry key.
 
NTSTATUS NTAPI GetDefaultServiceName (_In_ PWDF_BIND_INFO BindInfo, _Out_ PUNICODE_STRING RegistryPath)
 Create default service path from bind info.
 
NTSTATUS GetVersionServicePath (_In_ PWDF_BIND_INFO BindInfo, _Out_ PUNICODE_STRING ServicePath)
 Get service path from bind info and registry.
 
BOOLEAN ServiceCheckBootStart (_In_ PUNICODE_STRING Service)
 
NTSTATUS FxLdrQueryUlong (_In_ HANDLE KeyHandle, _In_ PUNICODE_STRING ValueName, _Out_ PULONG Value)
 
NTSTATUS FxLdrQueryData (_In_ HANDLE KeyHandle, _In_ PUNICODE_STRING ValueName, _In_ ULONG Tag, _Out_ PKEY_VALUE_PARTIAL_INFORMATION *KeyValPartialInfo)
 
NTSTATUS BuildServicePath (_In_ PKEY_VALUE_PARTIAL_INFORMATION KeyValueInformation, _In_ PUNICODE_STRING ServicePath)
 

Function Documentation

◆ BuildServicePath()

NTSTATUS BuildServicePath ( _In_ PKEY_VALUE_PARTIAL_INFORMATION  KeyValueInformation,
_In_ PUNICODE_STRING  ServicePath 
)

Definition at line 338 of file registry.c.

341{
344 PWCHAR lastChar;
346 CONST WCHAR regPath[] = L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\%wZ";
347
348 if (KeyValueInformation->Type != REG_SZ &&
349 KeyValueInformation->Type != REG_EXPAND_SZ)
350 {
352 __DBGPRINT(("ERROR: BuildServicePath failed with status 0x%x\n", status));
353 return status;
354 }
355
356 if (KeyValueInformation->DataLength == 0 ||
357 KeyValueInformation->DataLength > 0xFFFF)
358 {
360 __DBGPRINT(("ERROR: BuildServicePath failed with status 0x%x\n", status));
361 return status;
362 }
363
364 name.Buffer = (PWCH)KeyValueInformation->Data;
365 name.Length = (USHORT)KeyValueInformation->DataLength;
366 name.MaximumLength = (USHORT)KeyValueInformation->DataLength;
367
368 lastChar = (PWCHAR)KeyValueInformation->Data + KeyValueInformation->DataLength / sizeof(WCHAR);
369 if (KeyValueInformation->DataLength >= sizeof(WCHAR) && *lastChar == UNICODE_NULL)
370 {
371 name.Length = (USHORT)KeyValueInformation->DataLength - sizeof(WCHAR);
372 }
373
374 buffer = ExAllocatePoolZero(PagedPool, name.Length + sizeof(regPath), WDFLDR_TAG);
375 if (buffer != NULL)
376 {
377 ServicePath->Length = 0;
378 ServicePath->MaximumLength = name.Length + sizeof(L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\");//106;
381
382 if (!NT_SUCCESS(status))
383 {
385 ServicePath->Length = 0;
387 }
388 }
389 else
390 {
392 __DBGPRINT(("ERROR: ExAllocatePoolWithTag failed with Status 0x%x\n", status));
393 }
394
395 return status;
396}
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_OBJECT_TYPE_MISMATCH
Definition: d3dkmdt.h:46
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define L(x)
Definition: resources.c:13
#define PagedPool
Definition: env_spec_w32.h:308
GLuint buffer
Definition: glext.h:5915
#define REG_SZ
Definition: layer.c:22
_In_ PCUNICODE_STRING ServicePath
Definition: library.c:55
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
FORCEINLINE PVOID ExAllocatePoolZero(ULONG PoolType, SIZE_T NumberOfBytes, ULONG Tag)
Definition: precomp.h:45
#define REG_EXPAND_SZ
Definition: nt_native.h:1497
WCHAR * PWCH
Definition: ntbasedef.h:422
#define UNICODE_NULL
NTSTRSAFEVAPI RtlUnicodeStringPrintf(_In_ PUNICODE_STRING DestinationString, _In_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:3241
#define CONST
Definition: pedump.c:81
unsigned short USHORT
Definition: pedump.c:61
USHORT MaximumLength
Definition: env_spec_w32.h:370
Definition: name.c:39
Definition: ps.c:97
uint16_t * PWCHAR
Definition: typedefs.h:56
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define WDFLDR_TAG
Definition: wdfloader.h:17
#define __DBGPRINT(_x_)
Definition: wdfloader.h:62
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by GetClassServicePath(), and GetVersionServicePath().

◆ FxLdrQueryData()

NTSTATUS FxLdrQueryData ( _In_ HANDLE  KeyHandle,
_In_ PUNICODE_STRING  ValueName,
_In_ ULONG  Tag,
_Out_ PKEY_VALUE_PARTIAL_INFORMATION KeyValPartialInfo 
)

Definition at line 267 of file registry.c.

272{
275 ULONG resultLength;
276
277 *KeyValPartialInfo = NULL;
278 for (;;)
279 {
280 status = ZwQueryValueKey(KeyHandle, ValueName, KeyValuePartialInformation, NULL, 0, &resultLength);
282 {
283 if (!NT_SUCCESS(status))
284 {
285 __DBGPRINT(("ERROR: ZwQueryValueKey failed with status 0x%x\n", status));
286 }
287
288 return status;
289 }
290
291 status = RtlULongAdd(resultLength, 0xCu, &resultLength);
292 if (!NT_SUCCESS(status))
293 {
294 __DBGPRINT(("ERROR: Computing length of data under %wZ failed with status 0x%x\n", ValueName, status));
295
296 return status;
297 }
298
299 pKeyInfo = ExAllocatePoolWithTag(PagedPool, resultLength, Tag);
300
301 if (pKeyInfo == NULL)
302 {
303 break;
304 }
305
306 RtlZeroMemory(pKeyInfo, resultLength);
307 status = ZwQueryValueKey(
308 KeyHandle,
309 ValueName,
311 pKeyInfo,
312 resultLength,
313 &resultLength);
314
315 if (NT_SUCCESS(status))
316 {
317 *KeyValPartialInfo = pKeyInfo;
318 return status;
319 }
320
321 ExFreePoolWithTag(pKeyInfo, WDFLDR_TAG);
322
324 {
325 __DBGPRINT(("ERROR: ZwQueryValueKey (%wZ) failed with Status 0x%x\n", ValueName, status));
326
327 return status;
328 }
329 }
330
331 __DBGPRINT(("ERROR: ExAllocatePoolWithTag failed with Status 0x%x\n", STATUS_INSUFFICIENT_RESOURCES));
332
334}
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
@ KeyValuePartialInformation
Definition: nt_native.h:1185
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4071
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243

Referenced by GetClassServicePath(), GetImageName(), and GetVersionServicePath().

◆ FxLdrQueryUlong()

NTSTATUS FxLdrQueryUlong ( _In_ HANDLE  KeyHandle,
_In_ PUNICODE_STRING  ValueName,
_Out_ PULONG  Value 
)

Definition at line 231 of file registry.c.

235{
237 ULONG resultLength;
239
240 keyValue.DataLength = 0;
241 keyValue.TitleIndex = 0;
242 keyValue.Type = 0;
243 keyValue.Data[0] = 0;
244 status = ZwQueryValueKey(KeyHandle, ValueName, KeyValuePartialInformation, &keyValue, sizeof(keyValue), &resultLength);
245 if (NT_SUCCESS(status))
246 {
247 if (keyValue.Type != REG_DWORD || keyValue.DataLength != sizeof(*Value))
248 {
250 }
251 else
252 {
253 *Value = keyValue.Data[0];
255 }
256 }
257 else
258 {
259 __DBGPRINT(("ERROR: ZwQueryValueKey failed with Status 0x%x\n", status));
260 }
261
262 return status;
263}
#define STATUS_INVALID_BUFFER_SIZE
Definition: ntstatus.h:772
#define REG_DWORD
Definition: sdbapi.c:615
#define STATUS_SUCCESS
Definition: shellext.h:65
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Referenced by ServiceCheckBootStart(), and WdfLdrDiagnosticsValueByNameAsULONG().

◆ GetDefaultServiceName()

NTSTATUS NTAPI GetDefaultServiceName ( _In_ PWDF_BIND_INFO  BindInfo,
_Out_ PUNICODE_STRING  RegistryPath 
)

Create default service path from bind info.

Parameters
BindInfoBind information
RegistryPathCreated service path
Returns
STATUS_SUCCESS on success, error code otherwise

Definition at line 88 of file registry.c.

91{
93 static const SIZE_T regPathLength = sizeof(L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Wdf01000") - sizeof(WCHAR);
94
95 if (RegistryPath == NULL)
96 {
98 }
99
101
102 if (RegistryPath->Buffer == NULL)
103 {
105 __DBGPRINT(("ERROR: ExAllocatePoolWithTag failed with status 0x%x\n", status));
107 }
108
109 RegistryPath->Length = 0;
110 RegistryPath->MaximumLength = regPathLength;
111
113 L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Wdf%02d000",
115
116 if (NT_SUCCESS(status))
117 {
118 __DBGPRINT(("Couldn't find control Key -- using default service name %wZ\n", RegistryPath));
120 }
121 else
122 {
123 __DBGPRINT(("ERROR: RtlUnicodeStringCopyString failed with Status 0x%x\n", status));
124
126 RegistryPath->Length = 0;
127 RegistryPath->Buffer = NULL;
128 }
129
130 return status;
131}
WDF_VERSION Version
Definition: fxldr.h:133
WDF_MAJOR_VERSION Major
Definition: fxldr.h:122
ULONG_PTR SIZE_T
Definition: typedefs.h:80
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
WDF_BIND_INFO BindInfo

Referenced by GetVersionServicePath().

◆ GetVersionRegistryHandle()

NTSTATUS NTAPI GetVersionRegistryHandle ( _In_ PWDF_BIND_INFO  BindInfo,
_Out_ PHANDLE  HandleRegKey 
)

Open framework version registry key.

Parameters
BindInfoBind information
HandleRegKeyOpened key handle
Returns
STATUS_SUCCESS on success, error code otherwise

Definition at line 21 of file registry.c.

24{
26 OBJECT_ATTRIBUTES objectAttributes;
29 DECLARE_UNICODE_STRING_SIZE(string, 256);
30
32 L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Wdf\\Kmdf\\%s\\Versions",
33 BindInfo->Component); // Component name for kmdf driver - 'KmdfLibrary'
34
35 if (!NT_SUCCESS(status))
36 {
37 __DBGPRINT(("ERROR: RtlUnicodeStringPrintf failed with Status 0x%x\n", status));
38 goto end;
39 }
40
41 __DBGPRINT(("Component path %wZ\n", &string));
42
44 status = ZwOpenKey(&keyHandle, KEY_QUERY_VALUE, &objectAttributes);
45
46 if (!NT_SUCCESS(status))
47 {
48 __DBGPRINT(("ERROR: ZwOpenKey (%wZ) failed with Status 0x%x\n", &string, status));
49 goto end;
50 }
51
53
54 if (!NT_SUCCESS(status))
55 {
56 __DBGPRINT(("ERROR: ConvertUlongToWString failed with Status 0x%x\n", status));
57 goto end;
58 }
59
61 status = ZwOpenKey(&handle, KEY_READ, &objectAttributes);
62
63 if (!NT_SUCCESS(status))
64 {
65 __DBGPRINT(("ERROR: ZwOpenKey (%wZ) failed with Status 0x%x\n", string, status));
66 }
67
68end:
69 *HandleRegKey = handle;
70
71 if (keyHandle != NULL)
72 {
74 }
75
76 return status;
77}
#define DECLARE_UNICODE_STRING_SIZE(_var, _size)
Definition: reactos.c:2885
WDFKEY keyHandle
GLuint GLuint end
Definition: gl.h:1545
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define KEY_READ
Definition: nt_native.h:1026
#define KEY_QUERY_VALUE
Definition: nt_native.h:1019
NTSYSAPI NTSTATUS NTAPI RtlIntegerToUnicodeString(ULONG Value, ULONG Base, PUNICODE_STRING String)
PWCHAR Component
Definition: fxldr.h:132

Referenced by GetVersionServicePath().

◆ GetVersionServicePath()

NTSTATUS GetVersionServicePath ( _In_ PWDF_BIND_INFO  BindInfo,
_Out_ PUNICODE_STRING  ServicePath 
)

Get service path from bind info and registry.

Parameters
BindInfoBind information
ServicePathService path in registry
Returns
STATUS_SUCCESS on success, error code otherwise

Definition at line 141 of file registry.c.

144{
147 HANDLE handleRegKey = NULL;
149
150 status = GetVersionRegistryHandle(BindInfo, &handleRegKey);
151
152 if (!NT_SUCCESS(status))
153 {
154 __DBGPRINT(("ERROR: GetVersionRegistryHandle failed with Status 0x%x\n", status));
155 }
156 else
157 {
158 // get service name
159 status = FxLdrQueryData(handleRegKey, &ValueName, WDFLDR_TAG, &pKeyVal);
160
161 if (!NT_SUCCESS(status))
162 {
163 __DBGPRINT(("ERROR: QueryData failed with status 0x%x\n", status));
164 }
165 else
166 {
168 }
169 }
170
171 if (!NT_SUCCESS(status))
172 {
174
175 if (!NT_SUCCESS(status))
176 {
177 __DBGPRINT(("ERROR: GetVersionServicePath failed with Status 0x%x\n", status));
178 }
179 }
180 else
181 {
182 __DBGPRINT(("(%wZ)\n", ServicePath));
183 }
184
185 if (handleRegKey != NULL)
186 ZwClose(handleRegKey);
187 if (pKeyVal != NULL)
189
190 return status;
191}
NTSTATUS FxLdrQueryData(_In_ HANDLE KeyHandle, _In_ PUNICODE_STRING ValueName, _In_ ULONG Tag, _Out_ PKEY_VALUE_PARTIAL_INFORMATION *KeyValPartialInfo)
Definition: registry.c:267
NTSTATUS NTAPI GetDefaultServiceName(_In_ PWDF_BIND_INFO BindInfo, _Out_ PUNICODE_STRING RegistryPath)
Create default service path from bind info.
Definition: registry.c:88
NTSTATUS BuildServicePath(_In_ PKEY_VALUE_PARTIAL_INFORMATION KeyValueInformation, _In_ PUNICODE_STRING ServicePath)
Definition: registry.c:338
NTSTATUS NTAPI GetVersionRegistryHandle(_In_ PWDF_BIND_INFO BindInfo, _Out_ PHANDLE HandleRegKey)
Open framework version registry key.
Definition: registry.c:21
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by ReferenceVersion().

◆ ServiceCheckBootStart()

BOOLEAN ServiceCheckBootStart ( _In_ PUNICODE_STRING  Service)

Definition at line 194 of file registry.c.

196{
198 OBJECT_ATTRIBUTES objectAttributes;
201 ULONG value;
202 UNICODE_STRING valueName = RTL_CONSTANT_STRING(L"Start");
203
205 status = ZwOpenKey(&keyHandle, KEY_READ, &objectAttributes);
206
208 {
209 if (NT_SUCCESS(status))
210 {
211 status = FxLdrQueryUlong(keyHandle, &valueName, &value);
212 if (NT_SUCCESS(status))
213 {
214 result = value == 0;
215 }
216 }
217 else
218 {
219 __DBGPRINT(("ZwOpenKey(%wZ) failed: %08X\n", Service, status));
220 }
221 }
222
223 if (keyHandle)
225
226 return result;
227}
unsigned char BOOLEAN
#define FALSE
Definition: types.h:117
GLuint64EXT * result
Definition: glext.h:11304
@ Service
Definition: ntsecapi.h:292
NTSTATUS FxLdrQueryUlong(_In_ HANDLE KeyHandle, _In_ PUNICODE_STRING ValueName, _Out_ PULONG Value)
Definition: registry.c:231
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
Definition: pdh_main.c:96

Referenced by ClassCreate().