26#define CONST_STR_SIZE(x) (sizeof(x) - sizeof(x[0]))
27#define CONST_STR_LEN(x) (sizeof(x)/sizeof(x[0]) - 1)
45 HANDLE SourceSubKeyHandle, DestSubKeyHandle;
49 InformationLength = 256;
56 if (InfoBuffer ==
NULL)
62 if (InfoBuffer ==
NULL)
64 ERR_(VIDEOPRT,
"Could not allocate buffer for key info\n");
70 KeyInformation = InfoBuffer;
71 Status = ZwEnumerateKey(SourceKeyHandle,
95 ERR_(VIDEOPRT,
"ZwEnumerateKey failed, status 0x%lx\n",
Status);
113 ERR_(VIDEOPRT,
"Failed to open the source key\n");
123 Status = ZwCreateKey(&DestSubKeyHandle,
132 ERR_(VIDEOPRT,
"Failed to create the destination key\n");
142 WARN_(VIDEOPRT,
"Failed to copy subkey '%wZ'\n", &NameString);
158 if (InfoBuffer ==
NULL)
164 if (InfoBuffer ==
NULL)
166 ERR_(VIDEOPRT,
"Could not allocate buffer for key values\n");
172 KeyValueInformation = InfoBuffer;
173 Status = ZwEnumerateValueKey(SourceKeyHandle,
198 ERR_(VIDEOPRT,
"ZwEnumerateValueKey failed, status 0x%lx\n",
Status);
203 NameString.
Buffer = KeyValueInformation->
Name;
208 Status = ZwSetValueKey(DestKeyHandle,
211 KeyValueInformation->
Type,
217 WARN_(VIDEOPRT,
"Failed to set value '%wZ'\n", &NameString);
226 if (InfoBuffer !=
NULL)
246 Status = ZwQueryValueKey(SourceKeyHandle,
262 if (ValueInformation ==
NULL)
268 Status = ZwQueryValueKey(SourceKeyHandle,
281 Status = ZwSetValueKey(DestKeyHandle,
284 ValueInformation->
Type,
285 ValueInformation->
Data,
291 ERR_(VIDEOPRT,
"ZwSetValueKey failed, status 0x%lx\n",
Status);
316 ERR_(VIDEOPRT,
"Failed to open device software key, status 0x%lx\n",
Status);
333 ERR_(VIDEOPRT,
"Failed to open settings key, status 0x%lx\n",
Status);
346 ERR_(VIDEOPRT,
"ZwOpenKey failed for settings key, status 0x%lx\n",
Status);
431 ERR_(VIDEOPRT,
"IntDuplicateUnicodeString() failed, status 0x%lx\n",
Status);
442 ERR_(VIDEOPRT,
"IoOpenDeviceRegistryKey failed, status 0x%lx\n",
Status);
452 sizeof(VideoIdBuffer),
460 ERR_(VIDEOPRT,
"ExUuidCreate failed, status 0x%lx\n",
Status);
469 ERR_(VIDEOPRT,
"RtlStringFromGUID failed, status 0x%lx\n",
Status);
477 VideoIdString.Buffer,
488 ValueInformation->
Data,
492 ERR_(VIDEOPRT,
"ZwSetValueKey failed, status 0x%lx\n",
Status);
499 VideoIdString.Buffer = (
PWCHAR)ValueInformation->
Data;
501 VideoIdString.MaximumLength = VideoIdString.Length;
507 KeyMaxLength = ControlVideoPathName.
Length +
508 VideoIdString.Length +
519 ERR_(VIDEOPRT,
"Failed to allocate key name buffer\n");
525 &ControlVideoPathName);
558 ERR_(VIDEOPRT,
"Failed to create key '%wZ', status 0x%lx\n",
572 ERR_(VIDEOPRT,
"Failed to open settings key, status 0x%lx\n",
Status);
585 ERR_(VIDEOPRT,
"Failed to open settings key, status 0x%lx\n",
Status);
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";
614 WCHAR DeviceNumberBuffer[20];
622 DeviceNumberString.
Length = 0;
623 DeviceNumberString.
MaximumLength =
sizeof(DeviceNumberBuffer);
624 DeviceNumberString.
Buffer = DeviceNumberBuffer;
642 if (AfterControlSet.
Length >
sizeof(CurrentControlSet) &&
649 else if (AfterControlSet.
Length >
sizeof(ControlSet) &&
654 while (AfterControlSet.
Length > 0 &&
655 *AfterControlSet.
Buffer >=
L'0' &&
656 *AfterControlSet.
Buffer <=
L'9')
662 Valid = (AfterControlSet.
Length > 0 &&
L'\\' == *AfterControlSet.
Buffer);
675 INFO_(VIDEOPRT,
"Using old registry key as 'UseNewKey' is FALSE\n");
681 + DeviceNumberString.
Length;
683 DeviceRegistryPath->MaximumLength,
685 if (DeviceRegistryPath->Buffer !=
NULL)
688 wcsncpy(DeviceRegistryPath->Buffer,
717 DeviceRegistryPath->MaximumLength,
720 if (!DeviceRegistryPath->Buffer)
728 INFO_(VIDEOPRT,
"Formatted registry key '%wZ' -> '%wZ'\n",
_In_ PCHAR _In_ ULONG DeviceNumber
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
#define NT_SUCCESS(StatCode)
static const WCHAR Cleanup[]
#define ExAllocatePoolWithTag(hernya, size, tag)
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
#define RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING
#define RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
#define OBJ_KERNEL_HANDLE
#define OBJ_CASE_INSENSITIVE
NTSYSAPI NTSTATUS WINAPI RtlStringFromGUID(REFGUID, PUNICODE_STRING)
UNICODE_STRING DriverRegistryPath
NTKERNELAPI NTSTATUS ExUuidCreate(OUT UUID *Uuid)
#define ExFreePoolWithTag(_P, _T)
#define InitializeObjectAttributes(p, n, a, r, s)
_Out_ _Inout_ POEM_STRING _In_ PCUNICODE_STRING SourceString
_Out_ _Inout_ POEM_STRING DestinationString
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
@ KeyValuePartialInformation
@ KeyValueFullInformation
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RTL_REGISTRY_ABSOLUTE
#define REG_OPTION_NON_VOLATILE
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
NTSYSAPI NTSTATUS NTAPI RtlIntegerToUnicodeString(ULONG Value, ULONG Base, PUNICODE_STRING String)
struct _KEY_VALUE_PARTIAL_INFORMATION * PKEY_VALUE_PARTIAL_INFORMATION
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
_In_ ULONG _In_ ULONG _In_ ULONG Length
#define STATUS_NO_MORE_ENTRIES
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
NTSTATUS NTAPI IoOpenDeviceRegistryKey(IN PDEVICE_OBJECT DeviceObject, IN ULONG DevInstKeyType, IN ACCESS_MASK DesiredAccess, OUT PHANDLE DevInstRegKey)
_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)
NTSTATUS NTAPI RtlCheckRegistryKey(IN ULONG RelativeTo, IN PWSTR Path)
NTSTATUS NTAPI RtlCreateRegistryKey(IN ULONG RelativeTo, IN PWSTR Path)
#define STATUS_BUFFER_TOO_SMALL
#define STATUS_BUFFER_OVERFLOW
unsigned short MaximumLength
PDEVICE_OBJECT PhysicalDeviceObject
UNICODE_STRING RegistryPath
UNICODE_STRING NewRegistryPath
#define RTL_CONSTANT_STRING(s)
#define RtlCopyMemory(Destination, Source, Length)
#define STATUS_INVALID_PARAMETER
#define STATUS_INSUFFICIENT_RESOURCES
#define PLUGPLAY_REGKEY_DRIVER
BOOLEAN VideoPortUseNewKey
#define TAG_VIDEO_PORT_BUFFER
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
NTSTATUS IntDuplicateUnicodeString(IN ULONG Flags, IN PCUNICODE_STRING SourceString, OUT PUNICODE_STRING DestinationString)
NTSTATUS NTAPI IntCreateRegistryPath(IN PCUNICODE_STRING DriverRegistryPath, IN ULONG DeviceNumber, OUT PUNICODE_STRING DeviceRegistryPath)
NTSTATUS NTAPI IntCopyRegistryValue(HANDLE SourceKeyHandle, HANDLE DestKeyHandle, PWSTR ValueName)
NTSTATUS NTAPI IntCreateNewRegistryPath(PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension)
#define CONST_STR_SIZE(x)
NTSTATUS NTAPI IntSetupDeviceSettingsKey(PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension)
NTSTATUS NTAPI IntCopyRegistryKey(_In_ HANDLE SourceKeyHandle, _In_ HANDLE DestKeyHandle)
_In_ ULONG _Out_opt_ PULONG RequiredLength
#define GUID_STRING_LENGTH
_Must_inspect_result_ _In_ ULONG Flags
_In_ ULONG _In_ ACCESS_MASK _Out_ PHANDLE DevInstRegKey
#define PLUGPLAY_REGKEY_DEVICE