ReactOS 0.4.15-dev-7924-g5949c20
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 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

◆ NDEBUG

#define NDEBUG

Definition at line 26 of file registry.c.

Function Documentation

◆ IntCopyRegistryKey()

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

Definition at line 31 of file registry.c.

34{
35 PVOID InfoBuffer;
36 PKEY_BASIC_INFORMATION KeyInformation;
37 PKEY_VALUE_FULL_INFORMATION KeyValueInformation;
39 ULONG Index, InformationLength, RequiredLength;
40 UNICODE_STRING NameString;
42 HANDLE SourceSubKeyHandle, DestSubKeyHandle;
43
44 /* Start with no buffer, set initial size */
45 InfoBuffer = NULL;
46 InformationLength = 256;
47
48 /* Start looping with key index 0 */
49 Index = 0;
50 while (TRUE)
51 {
52 /* Check if we have no buffer */
53 if (InfoBuffer == NULL)
54 {
55 /* Allocate a new buffer */
57 InformationLength,
59 if (InfoBuffer == NULL)
60 {
61 ERR_(VIDEOPRT, "Could not allocate buffer for key info\n");
63 }
64 }
65
66 /* Enumerate the next sub-key */
67 KeyInformation = InfoBuffer;
68 Status = ZwEnumerateKey(SourceKeyHandle,
69 Index,
71 KeyInformation,
72 InformationLength,
76 {
77 /* Free the buffer and remember the required size */
79 InfoBuffer = NULL;
80 InformationLength = RequiredLength;
81
82 /* Try again */
83 continue;
84 }
86 {
87 /* We are done with the sub-keys */
88 break;
89 }
90 else if (!NT_SUCCESS(Status))
91 {
92 ERR_(VIDEOPRT, "ZwEnumerateKey failed, status 0x%lx\n", Status);
93 goto Cleanup;
94 }
95
96 /* Initialize a unicode string from the key name */
97 NameString.Buffer = KeyInformation->Name;
98 NameString.Length = (USHORT)KeyInformation->NameLength;
99 NameString.MaximumLength = NameString.Length;
100
101 /* Initialize object attributes and open the source sub-key */
103 &NameString,
105 SourceKeyHandle,
106 NULL);
107 Status = ZwOpenKey(&SourceSubKeyHandle, KEY_READ, &ObjectAttributes);
108 if (!NT_SUCCESS(Status))
109 {
110 ERR_(VIDEOPRT, "failed to open the source key.\n");
111 goto Cleanup;
112 }
113
114 /* Initialize object attributes and create the dest sub-key */
116 &NameString,
118 DestKeyHandle,
119 NULL);
120 Status = ZwCreateKey(&DestSubKeyHandle,
121 KEY_WRITE,
123 0,
124 NULL,
126 NULL);
127 if (!NT_SUCCESS(Status))
128 {
129 ERR_(VIDEOPRT, "failed to create the destination key.\n");
130 ObCloseHandle(SourceSubKeyHandle, KernelMode);
131 goto Cleanup;
132 }
133
134 /* Recursively copy the sub-key */
135 Status = IntCopyRegistryKey(SourceSubKeyHandle, DestSubKeyHandle);
136 if (!NT_SUCCESS(Status))
137 {
138 /* Just warn, but continue with the remaining sub-keys */
139 WARN_(VIDEOPRT, "failed to copy subkey '%wZ'.\n", &NameString);
140 }
141
142 /* Close the sub-key handles */
143 ObCloseHandle(SourceSubKeyHandle, KernelMode);
144 ObCloseHandle(DestSubKeyHandle, KernelMode);
145
146 /* Next sub-key */
147 Index++;
148 }
149
150 /* Start looping with value index 0 */
151 Index = 0;
152 while (TRUE)
153 {
154 /* Check if we have no buffer */
155 if (InfoBuffer == NULL)
156 {
157 /* Allocate a new buffer */
158 InfoBuffer = ExAllocatePoolWithTag(PagedPool,
159 InformationLength,
161 if (InfoBuffer == NULL)
162 {
163 ERR_(VIDEOPRT, "Could not allocate buffer for key values\n");
164 return Status;
165 }
166 }
167
168 /* Enumerate the next value */
169 KeyValueInformation = InfoBuffer;
170 Status = ZwEnumerateValueKey(SourceKeyHandle,
171 Index,
173 KeyValueInformation,
174 InformationLength,
178 {
179 /* Free the buffer and remember the required size */
181 InfoBuffer = NULL;
182 InformationLength = RequiredLength;
183
184 /* Try again */
185 continue;
186 }
187 else if (Status == STATUS_NO_MORE_ENTRIES)
188 {
189 /* We are done with the values */
191 break;
192 }
193 else if (!NT_SUCCESS(Status))
194 {
195 ERR_(VIDEOPRT, "ZwEnumerateValueKey failed, status 0x%lx\n", Status);
196 goto Cleanup;
197 }
198
199 /* Initialize a unicode string from the value name */
200 NameString.Buffer = KeyValueInformation->Name;
201 NameString.Length = (USHORT)KeyValueInformation->NameLength;
202 NameString.MaximumLength = NameString.Length;
203
204 /* Create the key value in the destination key */
205 Status = ZwSetValueKey(DestKeyHandle,
206 &NameString,
207 KeyValueInformation->TitleIndex,
208 KeyValueInformation->Type,
209 (PUCHAR)KeyValueInformation + KeyValueInformation->DataOffset,
210 KeyValueInformation->DataLength);
211 if (!NT_SUCCESS(Status))
212 {
213 /* Just warn, but continue with the remaining sub-keys */
214 WARN_(VIDEOPRT, "failed to set value '%wZ'.\n", &NameString);
215 }
216
217 /* Next subkey */
218 Index++;
219 }
220
221Cleanup:
222 /* Free the buffer and return the failure code */
223 if (InfoBuffer != NULL)
225 return Status;
226}
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:32
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:34
@ KeyBasicInformation
Definition: nt_native.h:1131
@ KeyValueFullInformation
Definition: nt_native.h:1181
#define KEY_READ
Definition: nt_native.h:1023
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:205
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:31
_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 230 of file registry.c.

234{
235 PKEY_VALUE_PARTIAL_INFORMATION ValueInformation;
236 UNICODE_STRING ValueNameString;
239
240 RtlInitUnicodeString(&ValueNameString, ValueName);
241
242 /* Query the value length */
243 Status = ZwQueryValueKey(SourceKeyHandle,
244 &ValueNameString,
246 NULL,
247 0,
248 &Length);
251 {
252 /* The key seems not present */
254 return Status;
255 }
256
257 /* Allocate a buffer */
259 if (ValueInformation == NULL)
260 {
261 return Status;
262 }
263
264 /* Query the value */
265 Status = ZwQueryValueKey(SourceKeyHandle,
266 &ValueNameString,
268 ValueInformation,
269 Length,
270 &Length);
271 if (!NT_SUCCESS(Status))
272 {
273 ExFreePoolWithTag(ValueInformation, TAG_VIDEO_PORT_BUFFER);
274 return Status;
275 }
276
277 /* Write the registry value */
278 Status = ZwSetValueKey(DestKeyHandle,
279 &ValueNameString,
280 ValueInformation->TitleIndex,
281 ValueInformation->Type,
282 ValueInformation->Data,
283 ValueInformation->DataLength);
284
285 ExFreePoolWithTag(ValueInformation, TAG_VIDEO_PORT_BUFFER);
286
287 if (!NT_SUCCESS(Status))
288 {
289 ERR_(VIDEOPRT, "ZwSetValueKey failed: status 0x%lx\n", Status);
290 }
291
292 return Status;
293}
@ KeyValuePartialInformation
Definition: nt_native.h:1182
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:3310

Referenced by IntSetupDeviceSettingsKey().

◆ IntCreateNewRegistryPath()

NTSTATUS NTAPI IntCreateNewRegistryPath ( PVIDEO_PORT_DEVICE_EXTENSION  DeviceExtension)
Todo:
HACK

Definition at line 407 of file registry.c.

409{
410 static UNICODE_STRING VideoIdValueName = RTL_CONSTANT_STRING(L"VideoId");
411 static UNICODE_STRING ControlVideoPathName =
412 RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Video\\");
413 HANDLE DevInstRegKey, SettingsKey, NewKey;
415 UNICODE_STRING VideoIdString;
416 UUID VideoId;
417 PKEY_VALUE_PARTIAL_INFORMATION ValueInformation ;
420 USHORT KeyMaxLength;
422 PWCHAR InstanceIdBuffer;
423
424 if (!DeviceExtension->PhysicalDeviceObject)
425 {
427 &DeviceExtension->RegistryPath,
428 &DeviceExtension->NewRegistryPath);
429 if (!NT_SUCCESS(Status))
430 ERR_(VIDEOPRT, "IntDuplicateUnicodeString() failed with status 0x%lx\n", Status);
431 return Status;
432 }
433
434 /* Open the hardware key: HKLM\System\CurrentControlSet\Enum\... */
439 if (Status != STATUS_SUCCESS)
440 {
441 ERR_(VIDEOPRT, "IoOpenDeviceRegistryKey failed: status 0x%lx\n", Status);
442 return Status;
443 }
444
445 /* Query the VideoId value */
446 ValueInformation = (PKEY_VALUE_PARTIAL_INFORMATION)VideoIdBuffer;
447 Status = ZwQueryValueKey(DevInstRegKey,
448 &VideoIdValueName,
450 ValueInformation,
451 sizeof(VideoIdBuffer),
452 &ResultLength);
453 if (!NT_SUCCESS(Status))
454 {
455 /* Create a new video Id */
456 Status = ExUuidCreate(&VideoId);
457 if (!NT_SUCCESS(Status))
458 {
459 ERR_(VIDEOPRT, "ExUuidCreate failed: status 0x%lx\n", Status);
461 return Status;
462 }
463
464 /* Convert the GUID into a string */
465 Status = RtlStringFromGUID(&VideoId, &VideoIdString);
466 if (!NT_SUCCESS(Status))
467 {
468 ERR_(VIDEOPRT, "RtlStringFromGUID failed: status 0x%lx\n", Status);
470 return Status;
471 }
472
473 /* Copy the GUID String to our buffer */
474 ValueInformation->DataLength = min(VideoIdString.Length, GUID_STRING_LENGTH);
475 RtlCopyMemory(ValueInformation->Data,
476 VideoIdString.Buffer,
477 ValueInformation->DataLength);
478
479 /* Free the GUID string */
480 RtlFreeUnicodeString(&VideoIdString);
481
482 /* Write the VideoId registry value */
483 Status = ZwSetValueKey(DevInstRegKey,
484 &VideoIdValueName,
485 0,
486 REG_SZ,
487 ValueInformation->Data,
488 ValueInformation->DataLength);
489 if (!NT_SUCCESS(Status))
490 {
491 ERR_(VIDEOPRT, "ZwSetValueKey failed: status 0x%lx\n", Status);
493 return Status;
494 }
495 }
496
497 /* Initialize the VideoId string from the registry data */
498 VideoIdString.Buffer = (PWCHAR)ValueInformation->Data;
499 VideoIdString.Length = (USHORT)ValueInformation->DataLength;
500 VideoIdString.MaximumLength = VideoIdString.Length;
501
502 /* Close the hardware key */
504
505 /* Calculate the size needed for the new registry path name */
506 KeyMaxLength = ControlVideoPathName.Length +
507 VideoIdString.Length +
508 sizeof(L"\\0000");
509
510 /* Allocate the path name buffer */
511 DeviceExtension->NewRegistryPath.Length = 0;
512 DeviceExtension->NewRegistryPath.MaximumLength = KeyMaxLength;
514 KeyMaxLength,
516 if (DeviceExtension->NewRegistryPath.Buffer == NULL)
517 {
518 ERR_(VIDEOPRT, "Failed to allocate key name buffer.\n");
520 }
521
522 /* Copy the root key name and append the VideoId string */
523 RtlCopyUnicodeString(&DeviceExtension->NewRegistryPath,
524 &ControlVideoPathName);
526 &VideoIdString);
527
528 /* Check if we have the key already */
530 DeviceExtension->NewRegistryPath.Buffer);
531 if (Status != STATUS_SUCCESS)
532 {
533 /* Try to create the new key */
535 DeviceExtension->NewRegistryPath.Buffer);
536 }
537
538 /* Append a the instance path */
539 RtlAppendUnicodeToString(&DeviceExtension->NewRegistryPath, L"\\");
540 InstanceIdBuffer = DeviceExtension->NewRegistryPath.Buffer +
541 DeviceExtension->NewRegistryPath.Length / sizeof(WCHAR);
542 RtlAppendUnicodeToString(&DeviceExtension->NewRegistryPath, L"0000");
543
544 /* Write instance ID */
545 swprintf(InstanceIdBuffer, L"%04u", DeviceExtension->DisplayNumber);
546
547 /* Check if the name exists */
549 DeviceExtension->NewRegistryPath.Buffer);
550 if (Status != STATUS_SUCCESS)
551 {
552 /* Try to create the new key */
554 DeviceExtension->NewRegistryPath.Buffer);
555 if (!NT_SUCCESS(Status))
556 {
557 ERR_(VIDEOPRT, "Failed create key '%wZ'\n", &DeviceExtension->NewRegistryPath);
558 return Status;
559 }
560
561 /* Open the new key */
563 &DeviceExtension->NewRegistryPath,
565 NULL,
566 NULL);
567 Status = ZwOpenKey(&NewKey, KEY_WRITE, &ObjectAttributes);
568 if (!NT_SUCCESS(Status))
569 {
570 ERR_(VIDEOPRT, "Failed to open settings key. Status 0x%lx\n", Status);
571 return Status;
572 }
573
574 /* Open the device profile key */
576 &DeviceExtension->RegistryPath,
578 NULL,
579 NULL);
580 Status = ZwOpenKey(&SettingsKey, KEY_READ, &ObjectAttributes);
581 if (!NT_SUCCESS(Status))
582 {
583 ERR_(VIDEOPRT, "Failed to open settings key. Status 0x%lx\n", Status);
584 ObCloseHandle(NewKey, KernelMode);
585 return Status;
586 }
587
588 /* Copy the registry data from the legacy key */
589 Status = IntCopyRegistryKey(SettingsKey, NewKey);
590
591 /* Close the key handles */
592 ObCloseHandle(SettingsKey, KernelMode);
593 ObCloseHandle(NewKey, KernelMode);
594 }
595
596 return Status;
597}
#define swprintf
Definition: precomp.h:40
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:1041
#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)
#define L(x)
Definition: ntvdm.h:50
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:3776
NTSTATUS IntDuplicateUnicodeString(IN ULONG Flags, IN PCUNICODE_STRING SourceString, OUT PUNICODE_STRING DestinationString)
Definition: registry.c:360
#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 601 of file registry.c.

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

Referenced by IntVideoPortCreateAdapterDeviceObject().

◆ IntDuplicateUnicodeString()

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

Definition at line 360 of file registry.c.

364{
365 if (SourceString == NULL ||
370 Flags >= 4)
371 {
373 }
374
375 if ((SourceString->Length == 0) &&
378 {
382 }
383 else
384 {
385 USHORT DestMaxLength = SourceString->Length;
386
388 DestMaxLength += sizeof(UNICODE_NULL);
389
392 return STATUS_NO_MEMORY;
393
396 DestinationString->MaximumLength = DestMaxLength;
397
400 }
401
402 return STATUS_SUCCESS;
403}
#define RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING
Definition: green.h:16
_Out_ _Inout_ POEM_STRING _In_ PCUNICODE_STRING SourceString
Definition: rtlfuncs.h:1910
_Out_ _Inout_ POEM_STRING DestinationString
Definition: rtlfuncs.h:1909
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 297 of file registry.c.

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

Referenced by IntVideoPortCreateAdapterDeviceObject().