162{
168
169 if (!BootResources && RelativePath)
170 {
172
174 {
175 DPRINT(
"ZwOpenKey() failed with status 0x%08lx\n",
Status);
177 }
178 }
179 else
180 hDevicesKey = hBaseKey;
181
183 if (!pDeviceInformation)
184 {
185 DPRINT(
"ExAllocatePool() failed\n");
188 }
189
191 {
194 HANDLE hLevel1Key, hLevel2Key =
NULL, hLogConf;
201
204 ULONG DeviceIndex = 0;
205
206 Status = ZwEnumerateKey(hDevicesKey,
207 KeyIndex,
209 pDeviceInformation,
210 DeviceInfoLength,
212
214 break;
216 {
220
221 if (!pDeviceInformation)
222 {
223 DPRINT(
"ExAllocatePool() failed\n");
226 }
227
228 Status = ZwEnumerateKey(hDevicesKey,
229 KeyIndex,
231 pDeviceInformation,
232 DeviceInfoLength,
234 }
235
237 {
238 DPRINT(
"ZwEnumerateKey() failed with status 0x%08lx\n",
Status);
240 }
241 KeyIndex++;
242
243
246
248 {
250 hDevicesKey,
252 hRootKey,
255 0,
256 BootResources,
257 BootResourcesLength);
258
261
262 continue;
263 }
264
266 if (!pValueInformation)
267 {
268 DPRINT(
"ExAllocatePool() failed\n");
271 }
272
275
277 {
278 DPRINT(
"ZwOpenKey() failed with status 0x%08lx\n",
Status);
280 }
281
282
283 Status = ZwQueryValueKey(hDeviceKey,
286 pValueInformation,
287 ValueInfoLength,
289
291 {
295
296 if (!pValueInformation)
297 {
298 DPRINT(
"ExAllocatePool() failed\n");
299 ZwDeleteKey(hLevel2Key);
302 }
303
304 Status = ZwQueryValueKey(hDeviceKey,
307 pValueInformation,
308 ValueInfoLength,
310 }
311
313 {
314 BootResources = ParentBootResources;
315 BootResourcesLength = ParentBootResourcesLength;
316 }
318 {
319 DPRINT(
"ZwQueryValueKey() failed with status 0x%08lx\n",
Status);
320 goto nextdevice;
321 }
323 {
325 goto nextdevice;
326 }
327 else
328 {
330
331
332 if (ParentBootResourcesLength == 0)
333 BootResourcesLength = pValueInformation->
DataLength;
334 else
335 BootResourcesLength = ParentBootResourcesLength
338
340 if (!BootResources)
341 {
342 DPRINT(
"ExAllocatePool() failed\n");
343 goto nextdevice;
344 }
345
347 {
349 }
350 else if (ParentBootResources->PartialResourceList.PartialDescriptors[ParentBootResources->PartialResourceList.Count - 1].Type ==
CmResourceTypeDeviceSpecific)
351 {
356 ParentBootResourcesLength -
Header);
357 BootResources->PartialResourceList.Count += ParentBootResources->PartialResourceList.Count;
358 }
359 else
360 {
365 ParentBootResourcesLength -
Header);
370 BootResources->PartialResourceList.Count += ParentBootResources->PartialResourceList.Count;
371 }
372 }
373
374 if (EnumerateSubKeys)
375 {
377 hDeviceKey,
378 RelativePath,
379 hRootKey,
381 BootResources,
382 BootResourcesLength,
383 ParentBootResources,
384 ParentBootResourcesLength);
385
388 }
389
390
391 Status = ZwQueryValueKey(hDeviceKey,
394 pValueInformation,
395 ValueInfoLength,
397
399 {
403
404 if (!pValueInformation)
405 {
406 DPRINT(
"ExAllocatePool() failed\n");
409 }
410
411 Status = ZwQueryValueKey(hDeviceKey,
414 pValueInformation,
415 ValueInfoLength,
417 }
418
420 {
422 {
423 DPRINT(
"ZwQueryValueKey() failed with status 0x%08lx\n",
Status);
424 goto nextdevice;
425 }
427 }
429 {
430 DPRINT(
"Wrong registry type: got 0x%lx, expected 0x%lx\n", pValueInformation->
Type,
REG_SZ);
431 goto nextdevice;
432 }
433 else
434 {
435
440 }
441
443 if (!pHardwareId)
444 {
445
446 DPRINT(
"Unknown key path '%wZ' value '%wZ'\n", RelativePath, &
ValueName);
447 goto nextdevice;
448 }
449
450
453 HardwareIdKey.
Buffer = pHardwareId;
454
455
457
459 &hLevel1Key,
462 0,
466
468 {
469 DPRINT(
"ZwCreateKey() failed with status 0x%08lx\n",
Status);
470 goto nextdevice;
471 }
472
473 swprintf(Level2Name,
L"%04lu", DeviceIndex);
476
478 &hLevel2Key,
481 0,
485
488 {
489 DPRINT(
"ZwCreateKey() failed with status 0x%08lx\n",
Status);
490 goto nextdevice;
491 }
492
493 DPRINT(
"Found %wZ #%lu (%wZ)\n", &
ValueName, DeviceIndex, &HardwareIdKey);
495
497 {
498 DPRINT(
"ZwSetValueKey() failed with status 0x%08lx\n",
Status);
499 ZwDeleteKey(hLevel2Key);
500 goto nextdevice;
501 }
502
503
505
507 &hLogConf,
510 0,
514
516 {
517 DPRINT(
"ZwCreateKey() failed with status 0x%08lx\n",
Status);
518 ZwDeleteKey(hLevel2Key);
519 goto nextdevice;
520 }
521
523 {
526
528 if (!CmResourceList)
529 {
531 ZwDeleteKey(hLevel2Key);
532 goto nextdevice;
533 }
534
535
536 ListCount = 1;
538 &ListCount,
540
541
543 BootResources,
544 BootResourcesLength);
545
546
547 Status = ZwSetValueKey(hLogConf,
549 0,
551 CmResourceList,
552 BootResourcesLength +
sizeof(
ULONG));
553
555
557 {
558 DPRINT(
"ZwSetValueKey() failed with status 0x%08lx\n",
Status);
560 ZwDeleteKey(hLevel2Key);
561 goto nextdevice;
562 }
563 }
565
566nextdevice:
567 if (BootResources && BootResources != ParentBootResources)
568 {
570 BootResources =
NULL;
571 }
572 if (hLevel2Key)
573 {
576 }
577 if (hDeviceKey)
578 {
581 }
582 if (pValueInformation)
584 }
585
587
589 if (hDevicesKey && hDevicesKey != hBaseKey)
591 if (pDeviceInformation)
593
595}
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
#define NT_SUCCESS(StatCode)
static void cleanup(void)
#define ExAllocatePool(type, size)
#define CmResourceTypeDeviceSpecific
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define OBJ_KERNEL_HANDLE
#define InitializeObjectAttributes(p, n, a, r, s)
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
@ KeyValuePartialInformation
struct _KEY_BASIC_INFORMATION KEY_BASIC_INFORMATION
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define KEY_CREATE_SUB_KEY
#define REG_OPTION_NON_VOLATILE
#define REG_RESOURCE_LIST
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
#define KEY_ENUMERATE_SUB_KEYS
#define REG_OPTION_VOLATILE
#define REG_FULL_RESOURCE_DESCRIPTOR
NTSTATUS NTAPI IopOpenRegistryKeyEx(PHANDLE KeyHandle, HANDLE ParentKey, PUNICODE_STRING Name, ACCESS_MASK DesiredAccess)
#define STATUS_NO_MORE_ENTRIES
static UNICODE_STRING ConfigurationDataU
static NTSTATUS IopEnumerateDetectedDevices(_In_ HANDLE hBaseKey, _In_opt_ PUNICODE_STRING RelativePath, _In_ HANDLE hRootKey, _In_ BOOLEAN EnumerateSubKeys, _In_opt_ PCM_FULL_RESOURCE_DESCRIPTOR BootResources, _In_opt_ ULONG BootResourcesLength, _In_ PCM_FULL_RESOURCE_DESCRIPTOR ParentBootResources, _In_ ULONG ParentBootResourcesLength)
static UNICODE_STRING LogConfU
static UNICODE_STRING BootConfigU
static UNICODE_STRING IdentifierU
static PWSTR IopMapDetectedDeviceId(_In_ PUNICODE_STRING DetectId, _In_ PUNICODE_STRING Value, _Out_ PULONG DeviceIndex)
static UNICODE_STRING HardwareIDU
#define STATUS_BUFFER_TOO_SMALL
#define STATUS_BUFFER_OVERFLOW
#define FIELD_OFFSET(t, f)
#define RtlCopyMemory(Destination, Source, Length)
#define STATUS_OBJECT_NAME_NOT_FOUND
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ ULONG _Out_ PVOID _Out_ PULONG RequiredSize
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName