166{
172
173 if (!BootResources && RelativePath)
174 {
176
178 {
179 DPRINT(
"ZwOpenKey() failed with status 0x%08lx\n",
Status);
181 }
182 }
183 else
184 hDevicesKey = hBaseKey;
185
187 if (!pDeviceInformation)
188 {
189 DPRINT(
"ExAllocatePool() failed\n");
192 }
193
195 {
198 HANDLE hLevel1Key, hLevel2Key =
NULL, hLogConf;
205
208 ULONG DeviceIndex = 0;
209
210 Status = ZwEnumerateKey(hDevicesKey,
211 KeyIndex,
213 pDeviceInformation,
214 DeviceInfoLength,
216
218 break;
220 {
224
225 if (!pDeviceInformation)
226 {
227 DPRINT(
"ExAllocatePool() failed\n");
230 }
231
232 Status = ZwEnumerateKey(hDevicesKey,
233 KeyIndex,
235 pDeviceInformation,
236 DeviceInfoLength,
238 }
239
241 {
242 DPRINT(
"ZwEnumerateKey() failed with status 0x%08lx\n",
Status);
244 }
245 KeyIndex++;
246
247
250
252 {
254 hDevicesKey,
256 hRootKey,
259 0,
260 BootResources,
261 BootResourcesLength);
262
265
266 continue;
267 }
268
270 if (!pValueInformation)
271 {
272 DPRINT(
"ExAllocatePool() failed\n");
275 }
276
279
281 {
282 DPRINT(
"ZwOpenKey() failed with status 0x%08lx\n",
Status);
284 }
285
286
287 Status = ZwQueryValueKey(hDeviceKey,
290 pValueInformation,
291 ValueInfoLength,
293
295 {
299
300 if (!pValueInformation)
301 {
302 DPRINT(
"ExAllocatePool() failed\n");
303 ZwDeleteKey(hLevel2Key);
306 }
307
308 Status = ZwQueryValueKey(hDeviceKey,
311 pValueInformation,
312 ValueInfoLength,
314 }
315
317 {
318 BootResources = ParentBootResources;
319 BootResourcesLength = ParentBootResourcesLength;
320 }
322 {
323 DPRINT(
"ZwQueryValueKey() failed with status 0x%08lx\n",
Status);
324 goto nextdevice;
325 }
327 {
329 goto nextdevice;
330 }
331 else
332 {
334
335
336 if (ParentBootResourcesLength == 0)
337 BootResourcesLength = pValueInformation->
DataLength;
338 else
339 BootResourcesLength = ParentBootResourcesLength
342
344 if (!BootResources)
345 {
346 DPRINT(
"ExAllocatePool() failed\n");
347 goto nextdevice;
348 }
349
351 {
353 }
354 else if (ParentBootResources->PartialResourceList.PartialDescriptors[ParentBootResources->PartialResourceList.Count - 1].Type ==
CmResourceTypeDeviceSpecific)
355 {
360 ParentBootResourcesLength -
Header);
361 BootResources->PartialResourceList.Count += ParentBootResources->PartialResourceList.Count;
362 }
363 else
364 {
369 ParentBootResourcesLength -
Header);
374 BootResources->PartialResourceList.Count += ParentBootResources->PartialResourceList.Count;
375 }
376 }
377
378 if (EnumerateSubKeys)
379 {
381 hDeviceKey,
382 RelativePath,
383 hRootKey,
385 BootResources,
386 BootResourcesLength,
387 ParentBootResources,
388 ParentBootResourcesLength);
389
392 }
393
394
395 Status = ZwQueryValueKey(hDeviceKey,
398 pValueInformation,
399 ValueInfoLength,
401
403 {
407
408 if (!pValueInformation)
409 {
410 DPRINT(
"ExAllocatePool() failed\n");
413 }
414
415 Status = ZwQueryValueKey(hDeviceKey,
418 pValueInformation,
419 ValueInfoLength,
421 }
422
424 {
426 {
427 DPRINT(
"ZwQueryValueKey() failed with status 0x%08lx\n",
Status);
428 goto nextdevice;
429 }
431 }
433 {
434 DPRINT(
"Wrong registry type: got 0x%lx, expected 0x%lx\n", pValueInformation->
Type,
REG_SZ);
435 goto nextdevice;
436 }
437 else
438 {
439
444 }
445
447 if (!pHardwareId)
448 {
449
450 DPRINT(
"Unknown key path '%wZ' value '%wZ'\n", RelativePath, &
ValueName);
451 goto nextdevice;
452 }
453
454
457 HardwareIdKey.
Buffer = pHardwareId;
458
459
461
463 &hLevel1Key,
466 0,
470
472 {
473 DPRINT(
"ZwCreateKey() failed with status 0x%08lx\n",
Status);
474 goto nextdevice;
475 }
476
480
482 &hLevel2Key,
485 0,
489
492 {
493 DPRINT(
"ZwCreateKey() failed with status 0x%08lx\n",
Status);
494 goto nextdevice;
495 }
496
497 DPRINT(
"Found %wZ #%lu (%wZ)\n", &
ValueName, DeviceIndex, &HardwareIdKey);
499
501 {
502 DPRINT(
"ZwSetValueKey() failed with status 0x%08lx\n",
Status);
503 ZwDeleteKey(hLevel2Key);
504 goto nextdevice;
505 }
506
507
509
511 &hLogConf,
514 0,
518
520 {
521 DPRINT(
"ZwCreateKey() failed with status 0x%08lx\n",
Status);
522 ZwDeleteKey(hLevel2Key);
523 goto nextdevice;
524 }
525
527 {
530
532 if (!CmResourceList)
533 {
535 ZwDeleteKey(hLevel2Key);
536 goto nextdevice;
537 }
538
539
540 ListCount = 1;
542 &ListCount,
544
545
547 BootResources,
548 BootResourcesLength);
549
550
551 Status = ZwSetValueKey(hLogConf,
553 0,
555 CmResourceList,
556 BootResourcesLength +
sizeof(
ULONG));
557
559
561 {
562 DPRINT(
"ZwSetValueKey() failed with status 0x%08lx\n",
Status);
564 ZwDeleteKey(hLevel2Key);
565 goto nextdevice;
566 }
567 }
569
570nextdevice:
571 if (BootResources && BootResources != ParentBootResources)
572 {
574 BootResources =
NULL;
575 }
576 if (hLevel2Key)
577 {
580 }
581 if (hDeviceKey)
582 {
585 }
586 if (pValueInformation)
588 }
589
591
593 if (hDevicesKey && hDevicesKey != hBaseKey)
595 if (pDeviceInformation)
597
599}
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
#define NT_SUCCESS(StatCode)
static void cleanup(void)
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
#define ExAllocatePool(type, size)
#define _swprintf(buf, format,...)
#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 OBJ_KERNEL_HANDLE
#define CmResourceTypeDeviceSpecific
#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