ReactOS 0.4.16-dev-1946-g52006dd
registry.c File Reference
#include "videoprt.h"
#include <ndk/obfuncs.h>
#include <stdio.h>
#include <debug.h>
Include dependency graph for registry.c:

Go to the source code of this file.

Macros

#define CONST_STR_SIZE(x)   (sizeof(x) - sizeof(x[0]))
 
#define CONST_STR_LEN(x)   (sizeof(x)/sizeof(x[0]) - 1)
 
#define NDEBUG
 

Functions

NTSTATUS NTAPI IntCopyRegistryKey (_In_ HANDLE SourceKeyHandle, _In_ HANDLE DestKeyHandle)
 
NTSTATUS NTAPI IntCopyRegistryValue (HANDLE SourceKeyHandle, HANDLE DestKeyHandle, PWSTR ValueName)
 
NTSTATUS NTAPI IntSetupDeviceSettingsKey (PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS IntDuplicateUnicodeString (IN ULONG Flags, IN PCUNICODE_STRING SourceString, OUT PUNICODE_STRING DestinationString)
 
NTSTATUS NTAPI IntCreateNewRegistryPath (PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI IntCreateRegistryPath (IN PCUNICODE_STRING DriverRegistryPath, IN ULONG DeviceNumber, OUT PUNICODE_STRING DeviceRegistryPath)
 

Macro Definition Documentation

◆ CONST_STR_LEN

#define CONST_STR_LEN (   x)    (sizeof(x)/sizeof(x[0]) - 1)

Definition at line 27 of file registry.c.

◆ CONST_STR_SIZE

#define CONST_STR_SIZE (   x)    (sizeof(x) - sizeof(x[0]))

Definition at line 26 of file registry.c.

◆ NDEBUG

#define NDEBUG

Definition at line 29 of file registry.c.

Function Documentation

◆ IntCopyRegistryKey()

NTSTATUS NTAPI IntCopyRegistryKey ( _In_ HANDLE  SourceKeyHandle,
_In_ HANDLE  DestKeyHandle 
)

Definition at line 34 of file registry.c.

37{
38 PVOID InfoBuffer;
39 PKEY_BASIC_INFORMATION KeyInformation;
40 PKEY_VALUE_FULL_INFORMATION KeyValueInformation;
42 ULONG Index, InformationLength, RequiredLength;
43 UNICODE_STRING NameString;
45 HANDLE SourceSubKeyHandle, DestSubKeyHandle;
46
47 /* Start with no buffer, set initial size */
48 InfoBuffer = NULL;
49 InformationLength = 256;
50
51 /* Start looping with key index 0 */
52 Index = 0;
53 while (TRUE)
54 {
55 /* Check if we have no buffer */
56 if (InfoBuffer == NULL)
57 {
58 /* Allocate a new buffer */
60 InformationLength,
62 if (InfoBuffer == NULL)
63 {
64 ERR_(VIDEOPRT, "Could not allocate buffer for key info\n");
66 }
67 }
68
69 /* Enumerate the next sub-key */
70 KeyInformation = InfoBuffer;
71 Status = ZwEnumerateKey(SourceKeyHandle,
72 Index,
74 KeyInformation,
75 InformationLength,
79 {
80 /* Free the buffer and remember the required size */
82 InfoBuffer = NULL;
83 InformationLength = RequiredLength;
84
85 /* Try again */
86 continue;
87 }
89 {
90 /* We are done with the sub-keys */
91 break;
92 }
93 else if (!NT_SUCCESS(Status))
94 {
95 ERR_(VIDEOPRT, "ZwEnumerateKey failed, status 0x%lx\n", Status);
96 goto Cleanup;
97 }
98
99 /* Initialize a unicode string from the key name */
100 NameString.Buffer = KeyInformation->Name;
101 NameString.Length = (USHORT)KeyInformation->NameLength;
102 NameString.MaximumLength = NameString.Length;
103
104 /* Initialize object attributes and open the source sub-key */
106 &NameString,
108 SourceKeyHandle,
109 NULL);
110 Status = ZwOpenKey(&SourceSubKeyHandle, KEY_READ, &ObjectAttributes);
111 if (!NT_SUCCESS(Status))
112 {
113 ERR_(VIDEOPRT, "Failed to open the source key\n");
114 goto Cleanup;
115 }
116
117 /* Initialize object attributes and create the dest sub-key */
119 &NameString,
121 DestKeyHandle,
122 NULL);
123 Status = ZwCreateKey(&DestSubKeyHandle,
124 KEY_WRITE,
126 0,
127 NULL,
129 NULL);
130 if (!NT_SUCCESS(Status))
131 {
132 ERR_(VIDEOPRT, "Failed to create the destination key\n");
133 ObCloseHandle(SourceSubKeyHandle, KernelMode);
134 goto Cleanup;
135 }
136
137 /* Recursively copy the sub-key */
138 Status = IntCopyRegistryKey(SourceSubKeyHandle, DestSubKeyHandle);
139 if (!NT_SUCCESS(Status))
140 {
141 /* Just warn, but continue with the remaining sub-keys */
142 WARN_(VIDEOPRT, "Failed to copy subkey '%wZ'\n", &NameString);
143 }
144
145 /* Close the sub-key handles */
146 ObCloseHandle(SourceSubKeyHandle, KernelMode);
147 ObCloseHandle(DestSubKeyHandle, KernelMode);
148
149 /* Next sub-key */
150 Index++;
151 }
152
153 /* Start looping with value index 0 */
154 Index = 0;
155 while (TRUE)
156 {
157 /* Check if we have no buffer */
158 if (InfoBuffer == NULL)
159 {
160 /* Allocate a new buffer */
161 InfoBuffer = ExAllocatePoolWithTag(PagedPool,
162 InformationLength,
164 if (InfoBuffer == NULL)
165 {
166 ERR_(VIDEOPRT, "Could not allocate buffer for key values\n");
167 return Status;
168 }
169 }
170
171 /* Enumerate the next value */
172 KeyValueInformation = InfoBuffer;
173 Status = ZwEnumerateValueKey(SourceKeyHandle,
174 Index,
176 KeyValueInformation,
177 InformationLength,
181 {
182 /* Free the buffer and remember the required size */
184 InfoBuffer = NULL;
185 InformationLength = RequiredLength;
186
187 /* Try again */
188 continue;
189 }
190 else if (Status == STATUS_NO_MORE_ENTRIES)
191 {
192 /* We are done with the values */
194 break;
195 }
196 else if (!NT_SUCCESS(Status))
197 {
198 ERR_(VIDEOPRT, "ZwEnumerateValueKey failed, status 0x%lx\n", Status);
199 goto Cleanup;
200 }
201
202 /* Initialize a unicode string from the value name */
203 NameString.Buffer = KeyValueInformation->Name;
204 NameString.Length = (USHORT)KeyValueInformation->NameLength;
205 NameString.MaximumLength = NameString.Length;
206
207 /* Create the key value in the destination key */
208 Status = ZwSetValueKey(DestKeyHandle,
209 &NameString,
210 KeyValueInformation->TitleIndex,
211 KeyValueInformation->Type,
212 (PUCHAR)KeyValueInformation + KeyValueInformation->DataOffset,
213 KeyValueInformation->DataLength);
214 if (!NT_SUCCESS(Status))
215 {
216 /* Just warn, but continue with the remaining sub-keys */
217 WARN_(VIDEOPRT, "Failed to set value '%wZ'\n", &NameString);
218 }
219
220 /* Next subkey */
221 Index++;
222 }
223
224Cleanup:
225 /* Free the buffer and return the failure code */
226 if (InfoBuffer != NULL)
228 return Status;
229}
LONG NTSTATUS
Definition: precomp.h:26
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
static const WCHAR Cleanup[]
Definition: register.c:80
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
Status
Definition: gdiplustypes.h:25
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define KernelMode
Definition: asm.h:38
@ KeyBasicInformation
Definition: nt_native.h:1134
@ KeyValueFullInformation
Definition: nt_native.h:1184
#define KEY_READ
Definition: nt_native.h:1026
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1060
#define KEY_WRITE
Definition: nt_native.h:1034
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:285
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3379
unsigned short USHORT
Definition: pedump.c:61
#define ERR_(ch,...)
Definition: debug.h:156
#define WARN_(ch,...)
Definition: debug.h:157
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
USHORT MaximumLength
Definition: env_spec_w32.h:370
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define TAG_VIDEO_PORT_BUFFER
Definition: videoprt.h:39
_In_ WDFCOLLECTION _In_ ULONG Index
NTSTATUS NTAPI IntCopyRegistryKey(_In_ HANDLE SourceKeyHandle, _In_ HANDLE DestKeyHandle)
Definition: registry.c:34
_In_ ULONG _Out_opt_ PULONG RequiredLength
Definition: wmifuncs.h:30

Referenced by IntCopyRegistryKey(), and IntCreateNewRegistryPath().

◆ IntCopyRegistryValue()

NTSTATUS NTAPI IntCopyRegistryValue ( HANDLE  SourceKeyHandle,
HANDLE  DestKeyHandle,
PWSTR  ValueName 
)

Definition at line 233 of file registry.c.

237{
238 PKEY_VALUE_PARTIAL_INFORMATION ValueInformation;
239 UNICODE_STRING ValueNameString;
242
243 RtlInitUnicodeString(&ValueNameString, ValueName);
244
245 /* Query the value length */
246 Status = ZwQueryValueKey(SourceKeyHandle,
247 &ValueNameString,
249 NULL,
250 0,
251 &Length);
254 {
255 /* The key seems not present */
257 return Status;
258 }
259
260 /* Allocate a buffer */
262 if (ValueInformation == NULL)
263 {
264 return Status;
265 }
266
267 /* Query the value */
268 Status = ZwQueryValueKey(SourceKeyHandle,
269 &ValueNameString,
271 ValueInformation,
272 Length,
273 &Length);
274 if (!NT_SUCCESS(Status))
275 {
276 ExFreePoolWithTag(ValueInformation, TAG_VIDEO_PORT_BUFFER);
277 return Status;
278 }
279
280 /* Write the registry value */
281 Status = ZwSetValueKey(DestKeyHandle,
282 &ValueNameString,
283 ValueInformation->TitleIndex,
284 ValueInformation->Type,
285 ValueInformation->Data,
286 ValueInformation->DataLength);
287
288 ExFreePoolWithTag(ValueInformation, TAG_VIDEO_PORT_BUFFER);
289
290 if (!NT_SUCCESS(Status))
291 ERR_(VIDEOPRT, "ZwSetValueKey failed, status 0x%lx\n", Status);
292
293 return Status;
294}
@ KeyValuePartialInformation
Definition: nt_native.h:1185
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
#define NT_ASSERT
Definition: rtlfuncs.h:3327

Referenced by IntSetupDeviceSettingsKey().

◆ IntCreateNewRegistryPath()

NTSTATUS NTAPI IntCreateNewRegistryPath ( PVIDEO_PORT_DEVICE_EXTENSION  DeviceExtension)
Todo:
HACK

Definition at line 408 of file registry.c.

410{
411 static UNICODE_STRING VideoIdValueName = RTL_CONSTANT_STRING(L"VideoId");
412 static UNICODE_STRING ControlVideoPathName =
413 RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Video\\");
414 HANDLE DevInstRegKey, SettingsKey, NewKey;
416 UNICODE_STRING VideoIdString;
417 UUID VideoId;
418 PKEY_VALUE_PARTIAL_INFORMATION ValueInformation ;
421 USHORT KeyMaxLength;
423 PWCHAR InstanceIdBuffer;
424
425 if (!DeviceExtension->PhysicalDeviceObject)
426 {
428 &DeviceExtension->RegistryPath,
429 &DeviceExtension->NewRegistryPath);
430 if (!NT_SUCCESS(Status))
431 ERR_(VIDEOPRT, "IntDuplicateUnicodeString() failed, status 0x%lx\n", Status);
432 return Status;
433 }
434
435 /* Open the hardware key: HKLM\System\CurrentControlSet\Enum\... */
440 if (Status != STATUS_SUCCESS)
441 {
442 ERR_(VIDEOPRT, "IoOpenDeviceRegistryKey failed, status 0x%lx\n", Status);
443 return Status;
444 }
445
446 /* Query the VideoId value */
447 ValueInformation = (PKEY_VALUE_PARTIAL_INFORMATION)VideoIdBuffer;
448 Status = ZwQueryValueKey(DevInstRegKey,
449 &VideoIdValueName,
451 ValueInformation,
452 sizeof(VideoIdBuffer),
453 &ResultLength);
454 if (!NT_SUCCESS(Status))
455 {
456 /* Create a new video Id */
457 Status = ExUuidCreate(&VideoId);
458 if (!NT_SUCCESS(Status))
459 {
460 ERR_(VIDEOPRT, "ExUuidCreate failed, status 0x%lx\n", Status);
462 return Status;
463 }
464
465 /* Convert the GUID into a string */
466 Status = RtlStringFromGUID(&VideoId, &VideoIdString);
467 if (!NT_SUCCESS(Status))
468 {
469 ERR_(VIDEOPRT, "RtlStringFromGUID failed, status 0x%lx\n", Status);
471 return Status;
472 }
473
474 /* Copy the GUID String to our buffer */
475 ValueInformation->DataLength = min(VideoIdString.Length, GUID_STRING_LENGTH);
476 RtlCopyMemory(ValueInformation->Data,
477 VideoIdString.Buffer,
478 ValueInformation->DataLength);
479
480 /* Free the GUID string */
481 RtlFreeUnicodeString(&VideoIdString);
482
483 /* Write the VideoId registry value */
484 Status = ZwSetValueKey(DevInstRegKey,
485 &VideoIdValueName,
486 0,
487 REG_SZ,
488 ValueInformation->Data,
489 ValueInformation->DataLength);
490 if (!NT_SUCCESS(Status))
491 {
492 ERR_(VIDEOPRT, "ZwSetValueKey failed, status 0x%lx\n", Status);
494 return Status;
495 }
496 }
497
498 /* Initialize the VideoId string from the registry data */
499 VideoIdString.Buffer = (PWCHAR)ValueInformation->Data;
500 VideoIdString.Length = (USHORT)ValueInformation->DataLength;
501 VideoIdString.MaximumLength = VideoIdString.Length;
502
503 /* Close the hardware key */
505
506 /* Calculate the size needed for the new registry path name */
507 KeyMaxLength = ControlVideoPathName.Length +
508 VideoIdString.Length +
509 sizeof(L"\\0000");
510
511 /* Allocate the path name buffer */
512 DeviceExtension->NewRegistryPath.Length = 0;
513 DeviceExtension->NewRegistryPath.MaximumLength = KeyMaxLength;
515 KeyMaxLength,
517 if (DeviceExtension->NewRegistryPath.Buffer == NULL)
518 {
519 ERR_(VIDEOPRT, "Failed to allocate key name buffer\n");
521 }
522
523 /* Copy the root key name and append the VideoId string */
524 RtlCopyUnicodeString(&DeviceExtension->NewRegistryPath,
525 &ControlVideoPathName);
527 &VideoIdString);
528
529 /* Check if we have the key already */
531 DeviceExtension->NewRegistryPath.Buffer);
532 if (Status != STATUS_SUCCESS)
533 {
534 /* Try to create the new key */
536 DeviceExtension->NewRegistryPath.Buffer);
537 }
538
539 /* Append the instance path */
540 RtlAppendUnicodeToString(&DeviceExtension->NewRegistryPath, L"\\");
541 InstanceIdBuffer = DeviceExtension->NewRegistryPath.Buffer +
542 DeviceExtension->NewRegistryPath.Length / sizeof(WCHAR);
543 RtlAppendUnicodeToString(&DeviceExtension->NewRegistryPath, L"0000");
544
545 /* Write instance ID */
546 swprintf(InstanceIdBuffer, L"%04u", DeviceExtension->DisplayNumber);
547
548 /* Check if the name exists */
550 DeviceExtension->NewRegistryPath.Buffer);
551 if (Status != STATUS_SUCCESS)
552 {
553 /* Try to create the new key */
555 DeviceExtension->NewRegistryPath.Buffer);
556 if (!NT_SUCCESS(Status))
557 {
558 ERR_(VIDEOPRT, "Failed to create key '%wZ', status 0x%lx\n",
559 &DeviceExtension->NewRegistryPath, Status);
560 return Status;
561 }
562
563 /* Open the new key */
565 &DeviceExtension->NewRegistryPath,
567 NULL,
568 NULL);
569 Status = ZwOpenKey(&NewKey, KEY_WRITE, &ObjectAttributes);
570 if (!NT_SUCCESS(Status))
571 {
572 ERR_(VIDEOPRT, "Failed to open settings key, status 0x%lx\n", Status);
573 return Status;
574 }
575
576 /* Open the device profile key */
578 &DeviceExtension->RegistryPath,
580 NULL,
581 NULL);
582 Status = ZwOpenKey(&SettingsKey, KEY_READ, &ObjectAttributes);
583 if (!NT_SUCCESS(Status))
584 {
585 ERR_(VIDEOPRT, "Failed to open settings key, status 0x%lx\n", Status);
586 ObCloseHandle(NewKey, KernelMode);
587 return Status;
588 }
589
590 /* Copy the registry data from the legacy key */
591 Status = IntCopyRegistryKey(SettingsKey, NewKey);
592
593 /* Close the key handles */
594 ObCloseHandle(SettingsKey, KernelMode);
595 ObCloseHandle(NewKey, KernelMode);
596 }
597
598 return Status;
599}
#define swprintf
Definition: precomp.h:40
#define L(x)
Definition: resources.c:13
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
#define RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
Definition: green.h:15
NTSYSAPI NTSTATUS WINAPI RtlStringFromGUID(REFGUID, PUNICODE_STRING)
NTSYSAPI NTSTATUS WINAPI RtlCheckRegistryKey(ULONG, PWSTR)
#define REG_SZ
Definition: layer.c:22
NTKERNELAPI NTSTATUS ExUuidCreate(OUT UUID *Uuid)
Definition: uuid.c:380
#define min(a, b)
Definition: monoChain.cc:55
NTSYSAPI NTSTATUS NTAPI RtlCreateRegistryKey(_In_ ULONG RelativeTo, _In_ PWSTR Path)
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
#define KEY_ALL_ACCESS
Definition: nt_native.h:1044
#define RTL_REGISTRY_ABSOLUTE
Definition: nt_native.h:161
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
struct _KEY_VALUE_PARTIAL_INFORMATION * PKEY_VALUE_PARTIAL_INFORMATION
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
NTSTATUS NTAPI IoOpenDeviceRegistryKey(IN PDEVICE_OBJECT DeviceObject, IN ULONG DevInstKeyType, IN ACCESS_MASK DesiredAccess, OUT PHANDLE DevInstRegKey)
Definition: pnpmgr.c:1621
PDEVICE_OBJECT PhysicalDeviceObject
Definition: videoprt.h:87
UNICODE_STRING RegistryPath
Definition: videoprt.h:90
UNICODE_STRING NewRegistryPath
Definition: videoprt.h:91
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint16_t * PWCHAR
Definition: typedefs.h:56
#define TAG_VIDEO_PORT
Definition: videoprt.h:38
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3782
NTSTATUS IntDuplicateUnicodeString(IN ULONG Flags, IN PCUNICODE_STRING SourceString, OUT PUNICODE_STRING DestinationString)
Definition: registry.c:361
#define GUID_STRING_LENGTH
Definition: wmip.h:6
_In_ ULONG _In_ ACCESS_MASK _Out_ PHANDLE DevInstRegKey
Definition: iofuncs.h:1127
#define PLUGPLAY_REGKEY_DEVICE
Definition: iofuncs.h:2786
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by IntVideoPortCreateAdapterDeviceObject().

◆ IntCreateRegistryPath()

NTSTATUS NTAPI IntCreateRegistryPath ( IN PCUNICODE_STRING  DriverRegistryPath,
IN ULONG  DeviceNumber,
OUT PUNICODE_STRING  DeviceRegistryPath 
)

Definition at line 603 of file registry.c.

607{
608 static const WCHAR RegistryMachineSystem[] = L"\\REGISTRY\\MACHINE\\SYSTEM\\";
609 static const WCHAR CurrentControlSet[] = L"CURRENTCONTROLSET\\";
610 static const WCHAR ControlSet[] = L"CONTROLSET";
611 static const WCHAR Insert1[] = L"Hardware Profiles\\Current\\System\\CurrentControlSet\\";
612 static const WCHAR Insert2[] = L"\\Device";
613 UNICODE_STRING DeviceNumberString;
614 WCHAR DeviceNumberBuffer[20];
615 BOOLEAN Valid;
616 UNICODE_STRING AfterControlSet;
618
619 AfterControlSet = *DriverRegistryPath;
620
621 /* Convert DeviceNumber to string */
622 DeviceNumberString.Length = 0;
623 DeviceNumberString.MaximumLength = sizeof(DeviceNumberBuffer);
624 DeviceNumberString.Buffer = DeviceNumberBuffer;
625 Status = RtlIntegerToUnicodeString(DeviceNumber, 10, &DeviceNumberString);
626 if (!NT_SUCCESS(Status))
627 {
628 ERR_(VIDEOPRT, "RtlIntegerToUnicodeString(%u) returned 0x%08x\n", DeviceNumber, Status);
629 return Status;
630 }
631
632 /* Check if path begins with \\REGISTRY\\MACHINE\\SYSTEM\\ */
633 Valid = (DriverRegistryPath->Length > sizeof(RegistryMachineSystem) &&
634 _wcsnicmp(DriverRegistryPath->Buffer, RegistryMachineSystem,
635 CONST_STR_LEN(RegistryMachineSystem)) == 0);
636 if (Valid)
637 {
638 AfterControlSet.Buffer += CONST_STR_LEN(RegistryMachineSystem);
639 AfterControlSet.Length -= CONST_STR_SIZE(RegistryMachineSystem);
640
641 /* Check if path contains CURRENTCONTROLSET */
642 if (AfterControlSet.Length > sizeof(CurrentControlSet) &&
643 _wcsnicmp(AfterControlSet.Buffer, CurrentControlSet, CONST_STR_LEN(CurrentControlSet)) == 0)
644 {
645 AfterControlSet.Buffer += CONST_STR_LEN(CurrentControlSet);
646 AfterControlSet.Length -= CONST_STR_SIZE(CurrentControlSet);
647 }
648 /* Check if path contains CONTROLSETnum */
649 else if (AfterControlSet.Length > sizeof(ControlSet) &&
650 _wcsnicmp(AfterControlSet.Buffer, ControlSet, CONST_STR_LEN(ControlSet)) == 0)
651 {
652 AfterControlSet.Buffer += CONST_STR_LEN(ControlSet);
653 AfterControlSet.Length -= CONST_STR_SIZE(ControlSet);
654 while (AfterControlSet.Length > 0 &&
655 *AfterControlSet.Buffer >= L'0' &&
656 *AfterControlSet.Buffer <= L'9')
657 {
658 AfterControlSet.Buffer++;
659 AfterControlSet.Length -= sizeof(WCHAR);
660 }
661
662 Valid = (AfterControlSet.Length > 0 && L'\\' == *AfterControlSet.Buffer);
663 AfterControlSet.Buffer++;
664 AfterControlSet.Length -= sizeof(WCHAR);
665 AfterControlSet.MaximumLength = AfterControlSet.Length;
666 }
667 else
668 {
669 Valid = FALSE;
670 }
671 }
672
674 {
675 INFO_(VIDEOPRT, "Using old registry key as 'UseNewKey' is FALSE\n");
676 Valid = FALSE;
677 }
678 else if (Valid)
679 {
680 DeviceRegistryPath->MaximumLength = DriverRegistryPath->Length + sizeof(Insert1) + sizeof(Insert2)
681 + DeviceNumberString.Length;
682 DeviceRegistryPath->Buffer = ExAllocatePoolWithTag(PagedPool,
683 DeviceRegistryPath->MaximumLength,
685 if (DeviceRegistryPath->Buffer != NULL)
686 {
687 /* Build device path */
688 wcsncpy(DeviceRegistryPath->Buffer,
690 AfterControlSet.Buffer - DriverRegistryPath->Buffer);
691 DeviceRegistryPath->Length = (ULONG_PTR)AfterControlSet.Buffer - (ULONG_PTR)DriverRegistryPath->Buffer;
692 RtlAppendUnicodeToString(DeviceRegistryPath, Insert1);
693 RtlAppendUnicodeStringToString(DeviceRegistryPath, &AfterControlSet);
694 RtlAppendUnicodeToString(DeviceRegistryPath, Insert2);
695 RtlAppendUnicodeStringToString(DeviceRegistryPath, &DeviceNumberString);
696
697 /* Check if registry key exists */
698 Valid = NT_SUCCESS(RtlCheckRegistryKey(RTL_REGISTRY_ABSOLUTE, DeviceRegistryPath->Buffer));
699 if (!Valid)
700 ExFreePoolWithTag(DeviceRegistryPath->Buffer, TAG_VIDEO_PORT);
701 }
702 else
703 {
704 Valid = FALSE;
705 }
706 }
707 else
708 {
709 WARN_(VIDEOPRT, "Unparsable registry path %wZ\n", DriverRegistryPath);
710 }
711
712 /* If path doesn't point to *ControlSet*, use DriverRegistryPath directly */
713 if (!Valid)
714 {
715 DeviceRegistryPath->MaximumLength = DriverRegistryPath->Length + sizeof(Insert2) + DeviceNumberString.Length;
716 DeviceRegistryPath->Buffer = ExAllocatePoolWithTag(NonPagedPool,
717 DeviceRegistryPath->MaximumLength,
719
720 if (!DeviceRegistryPath->Buffer)
721 return STATUS_NO_MEMORY;
722
723 RtlCopyUnicodeString(DeviceRegistryPath, DriverRegistryPath);
724 RtlAppendUnicodeToString(DeviceRegistryPath, Insert2);
725 RtlAppendUnicodeStringToString(DeviceRegistryPath, &DeviceNumberString);
726 }
727
728 INFO_(VIDEOPRT, "Formatted registry key '%wZ' -> '%wZ'\n",
729 DriverRegistryPath, DeviceRegistryPath);
730
731 return STATUS_SUCCESS;
732}
unsigned char BOOLEAN
_In_ PCHAR _In_ ULONG DeviceNumber
Definition: classpnp.h:1230
wcsncpy
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define FALSE
Definition: types.h:117
#define ULONG_PTR
Definition: config.h:101
#define NonPagedPool
Definition: env_spec_w32.h:307
UNICODE_STRING DriverRegistryPath
Definition: inport.c:17
NTSYSAPI NTSTATUS NTAPI RtlIntegerToUnicodeString(ULONG Value, ULONG Base, PUNICODE_STRING String)
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
#define INFO_(ch,...)
Definition: debug.h:159
uint32_t ULONG_PTR
Definition: typedefs.h:65
BOOLEAN VideoPortUseNewKey
Definition: videoprt.c:41
#define CONST_STR_LEN(x)
Definition: registry.c:27
#define CONST_STR_SIZE(x)
Definition: registry.c:26

Referenced by IntVideoPortCreateAdapterDeviceObject().

◆ IntDuplicateUnicodeString()

NTSTATUS IntDuplicateUnicodeString ( IN ULONG  Flags,
IN PCUNICODE_STRING  SourceString,
OUT PUNICODE_STRING  DestinationString 
)

Definition at line 361 of file registry.c.

365{
366 if (SourceString == NULL ||
371 Flags >= 4)
372 {
374 }
375
376 if ((SourceString->Length == 0) &&
379 {
383 }
384 else
385 {
386 USHORT DestMaxLength = SourceString->Length;
387
389 DestMaxLength += sizeof(UNICODE_NULL);
390
393 return STATUS_NO_MEMORY;
394
397 DestinationString->MaximumLength = DestMaxLength;
398
401 }
402
403 return STATUS_SUCCESS;
404}
#define RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING
Definition: green.h:16
_Out_ _Inout_ POEM_STRING _In_ PCUNICODE_STRING SourceString
Definition: rtlfuncs.h:1957
_Out_ _Inout_ POEM_STRING DestinationString
Definition: rtlfuncs.h:1956
#define UNICODE_NULL
unsigned short Length
Definition: sprintf.c:451
void * Buffer
Definition: sprintf.c:453
unsigned short MaximumLength
Definition: sprintf.c:452
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by IntCreateNewRegistryPath().

◆ IntSetupDeviceSettingsKey()

NTSTATUS NTAPI IntSetupDeviceSettingsKey ( PVIDEO_PORT_DEVICE_EXTENSION  DeviceExtension)

Definition at line 298 of file registry.c.

300{
301 static UNICODE_STRING SettingsKeyName = RTL_CONSTANT_STRING(L"Settings");
302 HANDLE DevInstRegKey, SourceKeyHandle, DestKeyHandle;
305
306 if (!DeviceExtension->PhysicalDeviceObject)
307 return STATUS_SUCCESS;
308
309 /* Open the software key: HKLM\System\CurrentControlSet\Control\Class<ClassGUID><n> */
314 if (Status != STATUS_SUCCESS)
315 {
316 ERR_(VIDEOPRT, "Failed to open device software key, status 0x%lx\n", Status);
317 return Status;
318 }
319
320 /* Open the 'Settings' sub-key */
322 &SettingsKeyName,
325 NULL);
326 Status = ZwOpenKey(&DestKeyHandle, KEY_WRITE, &ObjectAttributes);
327
328 /* Close the device software key */
330
331 if (Status != STATUS_SUCCESS)
332 {
333 ERR_(VIDEOPRT, "Failed to open settings key, status 0x%lx\n", Status);
334 return Status;
335 }
336
337 /* Open the device profile key */
339 &DeviceExtension->RegistryPath,
341 NULL,
342 NULL);
343 Status = ZwOpenKey(&SourceKeyHandle, KEY_READ, &ObjectAttributes);
344 if (Status != STATUS_SUCCESS)
345 {
346 ERR_(VIDEOPRT, "ZwOpenKey failed for settings key, status 0x%lx\n", Status);
347 ObCloseHandle(DestKeyHandle, KernelMode);
348 return Status;
349 }
350
351 IntCopyRegistryValue(SourceKeyHandle, DestKeyHandle, L"InstalledDisplayDrivers");
352 IntCopyRegistryValue(SourceKeyHandle, DestKeyHandle, L"Attach.ToDesktop");
353
354 ObCloseHandle(SourceKeyHandle, KernelMode);
355 ObCloseHandle(DestKeyHandle, KernelMode);
356
357 return STATUS_SUCCESS;
358}
#define PLUGPLAY_REGKEY_DRIVER
Definition: usbd.c:42
NTSTATUS NTAPI IntCopyRegistryValue(HANDLE SourceKeyHandle, HANDLE DestKeyHandle, PWSTR ValueName)
Definition: registry.c:233

Referenced by IntVideoPortCreateAdapterDeviceObject().