[NTOS:IO] Fix indentation. No code changes!

This commit is contained in:
Eric Kohl 2020-03-01 23:34:30 +01:00
parent 9a07cde37f
commit 7a7212f984

View file

@ -59,7 +59,7 @@ PDEVICE_NODE
FASTCALL FASTCALL
IopGetDeviceNode(PDEVICE_OBJECT DeviceObject) IopGetDeviceNode(PDEVICE_OBJECT DeviceObject)
{ {
return ((PEXTENDED_DEVOBJ_EXTENSION)DeviceObject->DeviceObjectExtension)->DeviceNode; return ((PEXTENDED_DEVOBJ_EXTENSION)DeviceObject->DeviceObjectExtension)->DeviceNode;
} }
VOID VOID
@ -2872,128 +2872,128 @@ NTSTATUS
IopActionConfigureChildServices(PDEVICE_NODE DeviceNode, IopActionConfigureChildServices(PDEVICE_NODE DeviceNode,
PVOID Context) PVOID Context)
{ {
RTL_QUERY_REGISTRY_TABLE QueryTable[3]; RTL_QUERY_REGISTRY_TABLE QueryTable[3];
PDEVICE_NODE ParentDeviceNode; PDEVICE_NODE ParentDeviceNode;
PUNICODE_STRING Service; PUNICODE_STRING Service;
UNICODE_STRING ClassGUID; UNICODE_STRING ClassGUID;
NTSTATUS Status; NTSTATUS Status;
DEVICE_CAPABILITIES DeviceCaps; DEVICE_CAPABILITIES DeviceCaps;
DPRINT("IopActionConfigureChildServices(%p, %p)\n", DeviceNode, Context); DPRINT("IopActionConfigureChildServices(%p, %p)\n", DeviceNode, Context);
ParentDeviceNode = (PDEVICE_NODE)Context; ParentDeviceNode = (PDEVICE_NODE)Context;
/* /*
* We are called for the parent too, but we don't need to do special * We are called for the parent too, but we don't need to do special
* handling for this node * handling for this node
*/ */
if (DeviceNode == ParentDeviceNode) if (DeviceNode == ParentDeviceNode)
{ {
DPRINT("Success\n"); DPRINT("Success\n");
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
/* /*
* Make sure this device node is a direct child of the parent device node * Make sure this device node is a direct child of the parent device node
* that is given as an argument * that is given as an argument
*/ */
if (DeviceNode->Parent != ParentDeviceNode) if (DeviceNode->Parent != ParentDeviceNode)
{ {
DPRINT("Skipping 2+ level child\n"); DPRINT("Skipping 2+ level child\n");
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
if (!(DeviceNode->Flags & DNF_PROCESSED)) if (!(DeviceNode->Flags & DNF_PROCESSED))
{ {
DPRINT1("Child not ready to be configured\n"); DPRINT1("Child not ready to be configured\n");
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
if (!(DeviceNode->Flags & (DNF_DISABLED | DNF_STARTED | DNF_ADDED))) if (!(DeviceNode->Flags & (DNF_DISABLED | DNF_STARTED | DNF_ADDED)))
{ {
UNICODE_STRING RegKey; UNICODE_STRING RegKey;
/* Install the service for this if it's in the CDDB */ /* Install the service for this if it's in the CDDB */
IopInstallCriticalDevice(DeviceNode); IopInstallCriticalDevice(DeviceNode);
/* /*
* Retrieve configuration from Enum key * Retrieve configuration from Enum key
*/ */
Service = &DeviceNode->ServiceName; Service = &DeviceNode->ServiceName;
RtlZeroMemory(QueryTable, sizeof(QueryTable)); RtlZeroMemory(QueryTable, sizeof(QueryTable));
RtlInitUnicodeString(Service, NULL); RtlInitUnicodeString(Service, NULL);
RtlInitUnicodeString(&ClassGUID, NULL); RtlInitUnicodeString(&ClassGUID, NULL);
QueryTable[0].Name = L"Service"; QueryTable[0].Name = L"Service";
QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT; QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
QueryTable[0].EntryContext = Service; QueryTable[0].EntryContext = Service;
QueryTable[1].Name = L"ClassGUID"; QueryTable[1].Name = L"ClassGUID";
QueryTable[1].Flags = RTL_QUERY_REGISTRY_DIRECT; QueryTable[1].Flags = RTL_QUERY_REGISTRY_DIRECT;
QueryTable[1].EntryContext = &ClassGUID; QueryTable[1].EntryContext = &ClassGUID;
QueryTable[1].DefaultType = REG_SZ; QueryTable[1].DefaultType = REG_SZ;
QueryTable[1].DefaultData = L""; QueryTable[1].DefaultData = L"";
QueryTable[1].DefaultLength = 0; QueryTable[1].DefaultLength = 0;
RegKey.Length = 0; RegKey.Length = 0;
RegKey.MaximumLength = sizeof(ENUM_ROOT) + sizeof(WCHAR) + DeviceNode->InstancePath.Length; RegKey.MaximumLength = sizeof(ENUM_ROOT) + sizeof(WCHAR) + DeviceNode->InstancePath.Length;
RegKey.Buffer = ExAllocatePoolWithTag(PagedPool, RegKey.Buffer = ExAllocatePoolWithTag(PagedPool,
RegKey.MaximumLength, RegKey.MaximumLength,
TAG_IO); TAG_IO);
if (RegKey.Buffer == NULL) if (RegKey.Buffer == NULL)
{ {
IopDeviceNodeSetFlag(DeviceNode, DNF_DISABLED);
return STATUS_INSUFFICIENT_RESOURCES;
}
RtlAppendUnicodeToString(&RegKey, ENUM_ROOT);
RtlAppendUnicodeToString(&RegKey, L"\\");
RtlAppendUnicodeStringToString(&RegKey, &DeviceNode->InstancePath);
Status = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE,
RegKey.Buffer, QueryTable, NULL, NULL);
ExFreePoolWithTag(RegKey.Buffer, TAG_IO);
if (!NT_SUCCESS(Status))
{
/* FIXME: Log the error */
DPRINT("Could not retrieve configuration for device %wZ (Status 0x%08x)\n",
&DeviceNode->InstancePath, Status);
IopDeviceNodeSetFlag(DeviceNode, DNF_DISABLED);
return STATUS_SUCCESS;
}
if (Service->Buffer == NULL)
{
if (NT_SUCCESS(IopQueryDeviceCapabilities(DeviceNode, &DeviceCaps)) &&
DeviceCaps.RawDeviceOK)
{
DPRINT("%wZ is using parent bus driver (%wZ)\n", &DeviceNode->InstancePath, &ParentDeviceNode->ServiceName);
RtlInitEmptyUnicodeString(&DeviceNode->ServiceName, NULL, 0);
}
else if (ClassGUID.Length != 0)
{
/* Device has a ClassGUID value, but no Service value.
* Suppose it is using the NULL driver, so state the
* device is started */
DPRINT("%wZ is using NULL driver\n", &DeviceNode->InstancePath);
IopDeviceNodeSetFlag(DeviceNode, DNF_STARTED);
}
else
{
DeviceNode->Problem = CM_PROB_FAILED_INSTALL;
IopDeviceNodeSetFlag(DeviceNode, DNF_DISABLED); IopDeviceNodeSetFlag(DeviceNode, DNF_DISABLED);
} return STATUS_INSUFFICIENT_RESOURCES;
return STATUS_SUCCESS; }
}
DPRINT("Got Service %S\n", Service->Buffer); RtlAppendUnicodeToString(&RegKey, ENUM_ROOT);
} RtlAppendUnicodeToString(&RegKey, L"\\");
RtlAppendUnicodeStringToString(&RegKey, &DeviceNode->InstancePath);
return STATUS_SUCCESS; Status = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE,
RegKey.Buffer, QueryTable, NULL, NULL);
ExFreePoolWithTag(RegKey.Buffer, TAG_IO);
if (!NT_SUCCESS(Status))
{
/* FIXME: Log the error */
DPRINT("Could not retrieve configuration for device %wZ (Status 0x%08x)\n",
&DeviceNode->InstancePath, Status);
IopDeviceNodeSetFlag(DeviceNode, DNF_DISABLED);
return STATUS_SUCCESS;
}
if (Service->Buffer == NULL)
{
if (NT_SUCCESS(IopQueryDeviceCapabilities(DeviceNode, &DeviceCaps)) &&
DeviceCaps.RawDeviceOK)
{
DPRINT("%wZ is using parent bus driver (%wZ)\n", &DeviceNode->InstancePath, &ParentDeviceNode->ServiceName);
RtlInitEmptyUnicodeString(&DeviceNode->ServiceName, NULL, 0);
}
else if (ClassGUID.Length != 0)
{
/* Device has a ClassGUID value, but no Service value.
* Suppose it is using the NULL driver, so state the
* device is started */
DPRINT("%wZ is using NULL driver\n", &DeviceNode->InstancePath);
IopDeviceNodeSetFlag(DeviceNode, DNF_STARTED);
}
else
{
DeviceNode->Problem = CM_PROB_FAILED_INSTALL;
IopDeviceNodeSetFlag(DeviceNode, DNF_DISABLED);
}
return STATUS_SUCCESS;
}
DPRINT("Got Service %S\n", Service->Buffer);
}
return STATUS_SUCCESS;
} }
/* /*
@ -3017,120 +3017,122 @@ NTSTATUS
IopActionInitChildServices(PDEVICE_NODE DeviceNode, IopActionInitChildServices(PDEVICE_NODE DeviceNode,
PVOID Context) PVOID Context)
{ {
PDEVICE_NODE ParentDeviceNode; PDEVICE_NODE ParentDeviceNode;
NTSTATUS Status; NTSTATUS Status;
BOOLEAN BootDrivers = !PnpSystemInit; BOOLEAN BootDrivers = !PnpSystemInit;
DPRINT("IopActionInitChildServices(%p, %p)\n", DeviceNode, Context); DPRINT("IopActionInitChildServices(%p, %p)\n", DeviceNode, Context);
ParentDeviceNode = Context; ParentDeviceNode = Context;
/* /*
* We are called for the parent too, but we don't need to do special * We are called for the parent too, but we don't need to do special
* handling for this node * handling for this node
*/ */
if (DeviceNode == ParentDeviceNode) if (DeviceNode == ParentDeviceNode)
{ {
DPRINT("Success\n"); DPRINT("Success\n");
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
/* /*
* We don't want to check for a direct child because * We don't want to check for a direct child because
* this function is called during boot to reinitialize * this function is called during boot to reinitialize
* devices with drivers that couldn't load yet due to * devices with drivers that couldn't load yet due to
* stage 0 limitations (ie can't load from disk yet). * stage 0 limitations (ie can't load from disk yet).
*/ */
if (!(DeviceNode->Flags & DNF_PROCESSED)) if (!(DeviceNode->Flags & DNF_PROCESSED))
{ {
DPRINT1("Child not ready to be added\n"); DPRINT1("Child not ready to be added\n");
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
if (IopDeviceNodeHasFlag(DeviceNode, DNF_STARTED) || if (IopDeviceNodeHasFlag(DeviceNode, DNF_STARTED) ||
IopDeviceNodeHasFlag(DeviceNode, DNF_ADDED) || IopDeviceNodeHasFlag(DeviceNode, DNF_ADDED) ||
IopDeviceNodeHasFlag(DeviceNode, DNF_DISABLED)) IopDeviceNodeHasFlag(DeviceNode, DNF_DISABLED))
return STATUS_SUCCESS; return STATUS_SUCCESS;
if (DeviceNode->ServiceName.Buffer == NULL) if (DeviceNode->ServiceName.Buffer == NULL)
{ {
/* We don't need to worry about loading the driver because we're /* We don't need to worry about loading the driver because we're
* being driven in raw mode so our parent must be loaded to get here */ * being driven in raw mode so our parent must be loaded to get here */
Status = IopInitializeDevice(DeviceNode, NULL); Status = IopInitializeDevice(DeviceNode, NULL);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
Status = IopStartDevice(DeviceNode); Status = IopStartDevice(DeviceNode);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("IopStartDevice(%wZ) failed with status 0x%08x\n", DPRINT1("IopStartDevice(%wZ) failed with status 0x%08x\n",
&DeviceNode->InstancePath, Status); &DeviceNode->InstancePath, Status);
} }
} }
} }
else else
{ {
PLDR_DATA_TABLE_ENTRY ModuleObject; PLDR_DATA_TABLE_ENTRY ModuleObject;
PDRIVER_OBJECT DriverObject; PDRIVER_OBJECT DriverObject;
KeEnterCriticalRegion(); KeEnterCriticalRegion();
ExAcquireResourceExclusiveLite(&IopDriverLoadResource, TRUE); ExAcquireResourceExclusiveLite(&IopDriverLoadResource, TRUE);
/* Get existing DriverObject pointer (in case the driver has /* Get existing DriverObject pointer (in case the driver has
already been loaded and initialized) */ already been loaded and initialized) */
Status = IopGetDriverObject( Status = IopGetDriverObject(
&DriverObject, &DriverObject,
&DeviceNode->ServiceName, &DeviceNode->ServiceName,
FALSE); FALSE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
/* Driver is not initialized, try to load it */ /* Driver is not initialized, try to load it */
Status = IopLoadServiceModule(&DeviceNode->ServiceName, &ModuleObject); Status = IopLoadServiceModule(&DeviceNode->ServiceName, &ModuleObject);
if (NT_SUCCESS(Status) || Status == STATUS_IMAGE_ALREADY_LOADED) if (NT_SUCCESS(Status) || Status == STATUS_IMAGE_ALREADY_LOADED)
{ {
/* Initialize the driver */ /* Initialize the driver */
Status = IopInitializeDriverModule(DeviceNode, ModuleObject, Status = IopInitializeDriverModule(DeviceNode, ModuleObject,
&DeviceNode->ServiceName, FALSE, &DriverObject); &DeviceNode->ServiceName, FALSE, &DriverObject);
if (!NT_SUCCESS(Status)) DeviceNode->Problem = CM_PROB_FAILED_DRIVER_ENTRY; if (!NT_SUCCESS(Status))
} DeviceNode->Problem = CM_PROB_FAILED_DRIVER_ENTRY;
else if (Status == STATUS_DRIVER_UNABLE_TO_LOAD) }
{ else if (Status == STATUS_DRIVER_UNABLE_TO_LOAD)
DPRINT1("Service '%wZ' is disabled\n", &DeviceNode->ServiceName); {
DeviceNode->Problem = CM_PROB_DISABLED_SERVICE; DPRINT1("Service '%wZ' is disabled\n", &DeviceNode->ServiceName);
} DeviceNode->Problem = CM_PROB_DISABLED_SERVICE;
else }
{ else
DPRINT("IopLoadServiceModule(%wZ) failed with status 0x%08x\n", {
&DeviceNode->ServiceName, Status); DPRINT("IopLoadServiceModule(%wZ) failed with status 0x%08x\n",
if (!BootDrivers) DeviceNode->Problem = CM_PROB_DRIVER_FAILED_LOAD; &DeviceNode->ServiceName, Status);
} if (!BootDrivers)
} DeviceNode->Problem = CM_PROB_DRIVER_FAILED_LOAD;
ExReleaseResourceLite(&IopDriverLoadResource); }
KeLeaveCriticalRegion(); }
ExReleaseResourceLite(&IopDriverLoadResource);
KeLeaveCriticalRegion();
/* Driver is loaded and initialized at this point */ /* Driver is loaded and initialized at this point */
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
/* Initialize the device, including all filters */ /* Initialize the device, including all filters */
Status = PipCallDriverAddDevice(DeviceNode, FALSE, DriverObject); Status = PipCallDriverAddDevice(DeviceNode, FALSE, DriverObject);
/* Remove the extra reference */ /* Remove the extra reference */
ObDereferenceObject(DriverObject); ObDereferenceObject(DriverObject);
} }
else else
{ {
/* /*
* Don't disable when trying to load only boot drivers * Don't disable when trying to load only boot drivers
*/ */
if (!BootDrivers) if (!BootDrivers)
{ {
IopDeviceNodeSetFlag(DeviceNode, DNF_DISABLED); IopDeviceNodeSetFlag(DeviceNode, DNF_DISABLED);
} }
} }
} }
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
/* /*
@ -3148,17 +3150,17 @@ IopActionInitChildServices(PDEVICE_NODE DeviceNode,
NTSTATUS NTSTATUS
IopInitializePnpServices(IN PDEVICE_NODE DeviceNode) IopInitializePnpServices(IN PDEVICE_NODE DeviceNode)
{ {
DEVICETREE_TRAVERSE_CONTEXT Context; DEVICETREE_TRAVERSE_CONTEXT Context;
DPRINT("IopInitializePnpServices(%p)\n", DeviceNode); DPRINT("IopInitializePnpServices(%p)\n", DeviceNode);
IopInitDeviceTreeTraverseContext( IopInitDeviceTreeTraverseContext(
&Context, &Context,
DeviceNode, DeviceNode,
IopActionInitChildServices, IopActionInitChildServices,
DeviceNode); DeviceNode);
return IopTraverseDeviceTree(&Context); return IopTraverseDeviceTree(&Context);
} }
static static
@ -3599,69 +3601,69 @@ INIT_FUNCTION
BOOLEAN BOOLEAN
IopIsFirmwareMapperDisabled(VOID) IopIsFirmwareMapperDisabled(VOID)
{ {
UNICODE_STRING KeyPathU = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM\\CURRENTCONTROLSET\\Control\\Pnp"); UNICODE_STRING KeyPathU = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM\\CURRENTCONTROLSET\\Control\\Pnp");
UNICODE_STRING KeyNameU = RTL_CONSTANT_STRING(L"DisableFirmwareMapper"); UNICODE_STRING KeyNameU = RTL_CONSTANT_STRING(L"DisableFirmwareMapper");
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
HANDLE hPnpKey; HANDLE hPnpKey;
PKEY_VALUE_PARTIAL_INFORMATION KeyInformation; PKEY_VALUE_PARTIAL_INFORMATION KeyInformation;
ULONG DesiredLength, Length; ULONG DesiredLength, Length;
ULONG KeyValue = 0; ULONG KeyValue = 0;
NTSTATUS Status; NTSTATUS Status;
InitializeObjectAttributes(&ObjectAttributes, &KeyPathU, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL); InitializeObjectAttributes(&ObjectAttributes, &KeyPathU, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL);
Status = ZwOpenKey(&hPnpKey, KEY_QUERY_VALUE, &ObjectAttributes); Status = ZwOpenKey(&hPnpKey, KEY_QUERY_VALUE, &ObjectAttributes);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
Status = ZwQueryValueKey(hPnpKey, Status = ZwQueryValueKey(hPnpKey,
&KeyNameU, &KeyNameU,
KeyValuePartialInformation, KeyValuePartialInformation,
NULL, NULL,
0, 0,
&DesiredLength); &DesiredLength);
if ((Status == STATUS_BUFFER_TOO_SMALL) || if ((Status == STATUS_BUFFER_TOO_SMALL) ||
(Status == STATUS_BUFFER_OVERFLOW)) (Status == STATUS_BUFFER_OVERFLOW))
{ {
Length = DesiredLength; Length = DesiredLength;
KeyInformation = ExAllocatePool(PagedPool, Length); KeyInformation = ExAllocatePool(PagedPool, Length);
if (KeyInformation) if (KeyInformation)
{ {
Status = ZwQueryValueKey(hPnpKey, Status = ZwQueryValueKey(hPnpKey,
&KeyNameU, &KeyNameU,
KeyValuePartialInformation, KeyValuePartialInformation,
KeyInformation, KeyInformation,
Length, Length,
&DesiredLength); &DesiredLength);
if (NT_SUCCESS(Status) && KeyInformation->DataLength == sizeof(ULONG)) if (NT_SUCCESS(Status) && KeyInformation->DataLength == sizeof(ULONG))
{ {
KeyValue = (ULONG)(*KeyInformation->Data); KeyValue = (ULONG)(*KeyInformation->Data);
} }
else else
{ {
DPRINT1("ZwQueryValueKey(%wZ%wZ) failed\n", &KeyPathU, &KeyNameU); DPRINT1("ZwQueryValueKey(%wZ%wZ) failed\n", &KeyPathU, &KeyNameU);
} }
ExFreePool(KeyInformation); ExFreePool(KeyInformation);
} }
else else
{ {
DPRINT1("Failed to allocate memory for registry query\n"); DPRINT1("Failed to allocate memory for registry query\n");
} }
} }
else else
{ {
DPRINT1("ZwQueryValueKey(%wZ%wZ) failed with status 0x%08lx\n", &KeyPathU, &KeyNameU, Status); DPRINT1("ZwQueryValueKey(%wZ%wZ) failed with status 0x%08lx\n", &KeyPathU, &KeyNameU, Status);
} }
ZwClose(hPnpKey); ZwClose(hPnpKey);
} }
else else
{ {
DPRINT1("ZwOpenKey(%wZ) failed with status 0x%08lx\n", &KeyPathU, Status); DPRINT1("ZwOpenKey(%wZ) failed with status 0x%08lx\n", &KeyPathU, Status);
} }
DPRINT("Firmware mapper is %s\n", KeyValue != 0 ? "disabled" : "enabled"); DPRINT("Firmware mapper is %s\n", KeyValue != 0 ? "disabled" : "enabled");
return (KeyValue != 0) ? TRUE : FALSE; return (KeyValue != 0) ? TRUE : FALSE;
} }
INIT_FUNCTION INIT_FUNCTION
@ -3669,32 +3671,32 @@ NTSTATUS
NTAPI NTAPI
IopUpdateRootKey(VOID) IopUpdateRootKey(VOID)
{ {
UNICODE_STRING EnumU = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Enum"); UNICODE_STRING EnumU = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Enum");
UNICODE_STRING RootPathU = RTL_CONSTANT_STRING(L"Root"); UNICODE_STRING RootPathU = RTL_CONSTANT_STRING(L"Root");
UNICODE_STRING MultiKeyPathU = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System\\MultifunctionAdapter"); UNICODE_STRING MultiKeyPathU = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System\\MultifunctionAdapter");
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
HANDLE hEnum, hRoot; HANDLE hEnum, hRoot;
NTSTATUS Status; NTSTATUS Status;
InitializeObjectAttributes(&ObjectAttributes, &EnumU, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL); InitializeObjectAttributes(&ObjectAttributes, &EnumU, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL);
Status = ZwCreateKey(&hEnum, KEY_CREATE_SUB_KEY, &ObjectAttributes, 0, NULL, REG_OPTION_NON_VOLATILE, NULL); Status = ZwCreateKey(&hEnum, KEY_CREATE_SUB_KEY, &ObjectAttributes, 0, NULL, REG_OPTION_NON_VOLATILE, NULL);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("ZwCreateKey() failed with status 0x%08lx\n", Status); DPRINT1("ZwCreateKey() failed with status 0x%08lx\n", Status);
return Status; return Status;
} }
InitializeObjectAttributes(&ObjectAttributes, &RootPathU, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, hEnum, NULL); InitializeObjectAttributes(&ObjectAttributes, &RootPathU, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, hEnum, NULL);
Status = ZwCreateKey(&hRoot, KEY_CREATE_SUB_KEY, &ObjectAttributes, 0, NULL, REG_OPTION_NON_VOLATILE, NULL); Status = ZwCreateKey(&hRoot, KEY_CREATE_SUB_KEY, &ObjectAttributes, 0, NULL, REG_OPTION_NON_VOLATILE, NULL);
ZwClose(hEnum); ZwClose(hEnum);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("ZwOpenKey() failed with status 0x%08lx\n", Status); DPRINT1("ZwOpenKey() failed with status 0x%08lx\n", Status);
return Status; return Status;
} }
if (!IopIsFirmwareMapperDisabled()) if (!IopIsFirmwareMapperDisabled())
{ {
Status = IopOpenRegistryKeyEx(&hEnum, NULL, &MultiKeyPathU, KEY_ENUMERATE_SUB_KEYS); Status = IopOpenRegistryKeyEx(&hEnum, NULL, &MultiKeyPathU, KEY_ENUMERATE_SUB_KEYS);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
@ -3711,16 +3713,16 @@ IopUpdateRootKey(VOID)
NULL, NULL,
0); 0);
ZwClose(hEnum); ZwClose(hEnum);
} }
else else
{ {
/* Enumeration is disabled */ /* Enumeration is disabled */
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
} }
ZwClose(hRoot); ZwClose(hRoot);
return Status; return Status;
} }
NTSTATUS NTSTATUS
@ -4628,145 +4630,145 @@ IoOpenDeviceRegistryKey(IN PDEVICE_OBJECT DeviceObject,
IN ACCESS_MASK DesiredAccess, IN ACCESS_MASK DesiredAccess,
OUT PHANDLE DevInstRegKey) OUT PHANDLE DevInstRegKey)
{ {
static WCHAR RootKeyName[] = static WCHAR RootKeyName[] =
L"\\Registry\\Machine\\System\\CurrentControlSet\\"; L"\\Registry\\Machine\\System\\CurrentControlSet\\";
static WCHAR ProfileKeyName[] = static WCHAR ProfileKeyName[] =
L"Hardware Profiles\\Current\\System\\CurrentControlSet\\"; L"Hardware Profiles\\Current\\System\\CurrentControlSet\\";
static WCHAR ClassKeyName[] = L"Control\\Class\\"; static WCHAR ClassKeyName[] = L"Control\\Class\\";
static WCHAR EnumKeyName[] = L"Enum\\"; static WCHAR EnumKeyName[] = L"Enum\\";
static WCHAR DeviceParametersKeyName[] = L"Device Parameters"; static WCHAR DeviceParametersKeyName[] = L"Device Parameters";
ULONG KeyNameLength; ULONG KeyNameLength;
PWSTR KeyNameBuffer; PWSTR KeyNameBuffer;
UNICODE_STRING KeyName; UNICODE_STRING KeyName;
ULONG DriverKeyLength; ULONG DriverKeyLength;
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
PDEVICE_NODE DeviceNode = NULL; PDEVICE_NODE DeviceNode = NULL;
NTSTATUS Status; NTSTATUS Status;
DPRINT("IoOpenDeviceRegistryKey() called\n"); DPRINT("IoOpenDeviceRegistryKey() called\n");
if ((DevInstKeyType & (PLUGPLAY_REGKEY_DEVICE | PLUGPLAY_REGKEY_DRIVER)) == 0) if ((DevInstKeyType & (PLUGPLAY_REGKEY_DEVICE | PLUGPLAY_REGKEY_DRIVER)) == 0)
{ {
DPRINT1("IoOpenDeviceRegistryKey(): got wrong params, exiting... \n"); DPRINT1("IoOpenDeviceRegistryKey(): got wrong params, exiting... \n");
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
} }
if (!IopIsValidPhysicalDeviceObject(DeviceObject)) if (!IopIsValidPhysicalDeviceObject(DeviceObject))
return STATUS_INVALID_DEVICE_REQUEST; return STATUS_INVALID_DEVICE_REQUEST;
DeviceNode = IopGetDeviceNode(DeviceObject); DeviceNode = IopGetDeviceNode(DeviceObject);
/* /*
* Calculate the length of the base key name. This is the full * Calculate the length of the base key name. This is the full
* name for driver key or the name excluding "Device Parameters" * name for driver key or the name excluding "Device Parameters"
* subkey for device key. * subkey for device key.
*/ */
KeyNameLength = sizeof(RootKeyName); KeyNameLength = sizeof(RootKeyName);
if (DevInstKeyType & PLUGPLAY_REGKEY_CURRENT_HWPROFILE) if (DevInstKeyType & PLUGPLAY_REGKEY_CURRENT_HWPROFILE)
KeyNameLength += sizeof(ProfileKeyName) - sizeof(UNICODE_NULL); KeyNameLength += sizeof(ProfileKeyName) - sizeof(UNICODE_NULL);
if (DevInstKeyType & PLUGPLAY_REGKEY_DRIVER) if (DevInstKeyType & PLUGPLAY_REGKEY_DRIVER)
{ {
KeyNameLength += sizeof(ClassKeyName) - sizeof(UNICODE_NULL); KeyNameLength += sizeof(ClassKeyName) - sizeof(UNICODE_NULL);
Status = IoGetDeviceProperty(DeviceObject, DevicePropertyDriverKeyName, Status = IoGetDeviceProperty(DeviceObject, DevicePropertyDriverKeyName,
0, NULL, &DriverKeyLength); 0, NULL, &DriverKeyLength);
if (Status != STATUS_BUFFER_TOO_SMALL) if (Status != STATUS_BUFFER_TOO_SMALL)
return Status; return Status;
KeyNameLength += DriverKeyLength; KeyNameLength += DriverKeyLength;
} }
else else
{ {
KeyNameLength += sizeof(EnumKeyName) - sizeof(UNICODE_NULL) + KeyNameLength += sizeof(EnumKeyName) - sizeof(UNICODE_NULL) +
DeviceNode->InstancePath.Length; DeviceNode->InstancePath.Length;
} }
/* /*
* Now allocate the buffer for the key name... * Now allocate the buffer for the key name...
*/ */
KeyNameBuffer = ExAllocatePool(PagedPool, KeyNameLength); KeyNameBuffer = ExAllocatePool(PagedPool, KeyNameLength);
if (KeyNameBuffer == NULL) if (KeyNameBuffer == NULL)
return STATUS_INSUFFICIENT_RESOURCES; return STATUS_INSUFFICIENT_RESOURCES;
KeyName.Length = 0; KeyName.Length = 0;
KeyName.MaximumLength = (USHORT)KeyNameLength; KeyName.MaximumLength = (USHORT)KeyNameLength;
KeyName.Buffer = KeyNameBuffer; KeyName.Buffer = KeyNameBuffer;
/* /*
* ...and build the key name. * ...and build the key name.
*/ */
KeyName.Length += sizeof(RootKeyName) - sizeof(UNICODE_NULL); KeyName.Length += sizeof(RootKeyName) - sizeof(UNICODE_NULL);
RtlCopyMemory(KeyNameBuffer, RootKeyName, KeyName.Length); RtlCopyMemory(KeyNameBuffer, RootKeyName, KeyName.Length);
if (DevInstKeyType & PLUGPLAY_REGKEY_CURRENT_HWPROFILE) if (DevInstKeyType & PLUGPLAY_REGKEY_CURRENT_HWPROFILE)
RtlAppendUnicodeToString(&KeyName, ProfileKeyName); RtlAppendUnicodeToString(&KeyName, ProfileKeyName);
if (DevInstKeyType & PLUGPLAY_REGKEY_DRIVER) if (DevInstKeyType & PLUGPLAY_REGKEY_DRIVER)
{ {
RtlAppendUnicodeToString(&KeyName, ClassKeyName); RtlAppendUnicodeToString(&KeyName, ClassKeyName);
Status = IoGetDeviceProperty(DeviceObject, DevicePropertyDriverKeyName, Status = IoGetDeviceProperty(DeviceObject, DevicePropertyDriverKeyName,
DriverKeyLength, KeyNameBuffer + DriverKeyLength, KeyNameBuffer +
(KeyName.Length / sizeof(WCHAR)), (KeyName.Length / sizeof(WCHAR)),
&DriverKeyLength); &DriverKeyLength);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("Call to IoGetDeviceProperty() failed with Status 0x%08lx\n", Status); DPRINT1("Call to IoGetDeviceProperty() failed with Status 0x%08lx\n", Status);
ExFreePool(KeyNameBuffer); ExFreePool(KeyNameBuffer);
return Status; return Status;
} }
KeyName.Length += (USHORT)DriverKeyLength - sizeof(UNICODE_NULL); KeyName.Length += (USHORT)DriverKeyLength - sizeof(UNICODE_NULL);
} }
else else
{ {
RtlAppendUnicodeToString(&KeyName, EnumKeyName); RtlAppendUnicodeToString(&KeyName, EnumKeyName);
Status = RtlAppendUnicodeStringToString(&KeyName, &DeviceNode->InstancePath); Status = RtlAppendUnicodeStringToString(&KeyName, &DeviceNode->InstancePath);
if (DeviceNode->InstancePath.Length == 0) if (DeviceNode->InstancePath.Length == 0)
{ {
ExFreePool(KeyNameBuffer); ExFreePool(KeyNameBuffer);
return Status; return Status;
} }
} }
/* /*
* Open the base key. * Open the base key.
*/ */
Status = IopOpenRegistryKeyEx(DevInstRegKey, NULL, &KeyName, DesiredAccess); Status = IopOpenRegistryKeyEx(DevInstRegKey, NULL, &KeyName, DesiredAccess);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("IoOpenDeviceRegistryKey(%wZ): Base key doesn't exist, exiting... (Status 0x%08lx)\n", &KeyName, Status); DPRINT1("IoOpenDeviceRegistryKey(%wZ): Base key doesn't exist, exiting... (Status 0x%08lx)\n", &KeyName, Status);
ExFreePool(KeyNameBuffer); ExFreePool(KeyNameBuffer);
return Status; return Status;
} }
ExFreePool(KeyNameBuffer); ExFreePool(KeyNameBuffer);
/* /*
* For driver key we're done now. * For driver key we're done now.
*/ */
if (DevInstKeyType & PLUGPLAY_REGKEY_DRIVER) if (DevInstKeyType & PLUGPLAY_REGKEY_DRIVER)
return Status; return Status;
/* /*
* Let's go further. For device key we must open "Device Parameters" * Let's go further. For device key we must open "Device Parameters"
* subkey and create it if it doesn't exist yet. * subkey and create it if it doesn't exist yet.
*/ */
RtlInitUnicodeString(&KeyName, DeviceParametersKeyName); RtlInitUnicodeString(&KeyName, DeviceParametersKeyName);
InitializeObjectAttributes(&ObjectAttributes, InitializeObjectAttributes(&ObjectAttributes,
&KeyName, &KeyName,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
*DevInstRegKey, *DevInstRegKey,
NULL); NULL);
Status = ZwCreateKey(DevInstRegKey, Status = ZwCreateKey(DevInstRegKey,
DesiredAccess, DesiredAccess,
&ObjectAttributes, &ObjectAttributes,
0, 0,
NULL, NULL,
REG_OPTION_NON_VOLATILE, REG_OPTION_NON_VOLATILE,
NULL); NULL);
ZwClose(ObjectAttributes.RootDirectory); ZwClose(ObjectAttributes.RootDirectory);
return Status; return Status;
} }
static static