static void RetrieveDriverConfiguration() { NDIS_CONFIGURATION_OBJECT co; NDIS_HANDLE cfg, params; NDIS_STATUS status; DEBUG_ENTRY(2); co.Header.Type = NDIS_OBJECT_TYPE_CONFIGURATION_OBJECT; co.Header.Revision = NDIS_CONFIGURATION_OBJECT_REVISION_1; co.Header.Size = NDIS_SIZEOF_CONFIGURATION_OBJECT_REVISION_1; co.Flags = 0; co.NdisHandle = DriverHandle; status = NdisOpenConfigurationEx(&co, &cfg); if (status == NDIS_STATUS_SUCCESS) { NDIS_STRING paramsName = {0}; #pragma warning(push) #pragma warning(disable:6102) NdisInitializeString(¶msName, (PUCHAR)"Parameters"); NdisOpenConfigurationKeyByName(&status, cfg, ¶msName, ¶ms); if (status == NDIS_STATUS_SUCCESS) { ReadGlobalConfigurationEntry(params, "DisableMSI", &bDisableMSI); ReadGlobalConfigurationEntry(params, "EarlyDebug", (PULONG)&resourceFilterLevel); NdisCloseConfiguration(params); } #pragma warning(pop) NdisCloseConfiguration(cfg); if (paramsName.Buffer) NdisFreeString(paramsName); } }
VOID NdisOpenConfigurationKeyByIndex( OUT PNDIS_STATUS Status, IN PNDIS_HANDLE ConfigurationHandle, IN ULONG Index, OUT PNDIS_STRING KeyName, OUT PNDIS_HANDLE KeyHandle ) /*++ Routine Description: This routine is used to open a subkey relative to the configuration handle. Arguments: Status - Returns the status of the request. ConfigurationHandle - Handle to an already open section of the registry Index - Index of the sub-key to open KeyName - Placeholder for the name of subkey being opened KeyHandle - Placeholder for the handle to the sub-key. Return Value: None. --*/ { PNDIS_CONFIGURATION_HANDLE ConfigHandle = (PNDIS_CONFIGURATION_HANDLE)ConfigurationHandle; HANDLE Handle; OBJECT_ATTRIBUTES ObjAttr; UNICODE_STRING KeyPath, Services, AbsolutePath; PKEY_BASIC_INFORMATION InfoBuf = NULL; ULONG Len; ASSERT (KeGetCurrentIrql() < DISPATCH_LEVEL); *KeyHandle = NULL; do { // // Open the current key and lookup the Nth subkey. But first conver the service relative // path to absolute since this is what ZwOpenKey expects. // RtlInitUnicodeString(&KeyPath, ConfigHandle->KeyQueryTable[3].Name); RtlInitUnicodeString(&Services, L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\"); AbsolutePath.MaximumLength = KeyPath.Length + Services.Length + sizeof(WCHAR); AbsolutePath.Buffer = (PWSTR)ALLOC_FROM_POOL(AbsolutePath.MaximumLength, NDIS_TAG_DEFAULT); if (AbsolutePath.Buffer == NULL) { break; } NdisMoveMemory(AbsolutePath.Buffer, Services.Buffer, Services.Length); AbsolutePath.Length = Services.Length; RtlAppendUnicodeStringToString(&AbsolutePath, &KeyPath); InitializeObjectAttributes(&ObjAttr, &AbsolutePath, OBJ_CASE_INSENSITIVE, NULL, NULL); *Status = ZwOpenKey(&Handle, GENERIC_READ | MAXIMUM_ALLOWED, &ObjAttr); if (*Status != STATUS_SUCCESS) { break; } // // Allocate memory for the call to ZwEnumerateKey // Len = sizeof(KEY_BASIC_INFORMATION) + 256; InfoBuf = (PKEY_BASIC_INFORMATION)ALLOC_FROM_POOL(Len, NDIS_TAG_DEFAULT); if (InfoBuf == NULL) { ZwClose(Handle); *Status = NDIS_STATUS_RESOURCES; break; } // // Get the Index(th) key, if it exists // *Status = ZwEnumerateKey(Handle, Index, KeyValueBasicInformation, InfoBuf, Len, &Len); ZwClose(Handle); if (*Status == STATUS_SUCCESS) { // // This worked. Now simply pick up the name and do a NdisOpenConfigurationKeyByName on it. // KeyPath.Length = KeyPath.MaximumLength = (USHORT)InfoBuf->NameLength; KeyPath.Buffer = InfoBuf->Name; NdisOpenConfigurationKeyByName(Status, ConfigurationHandle, &KeyPath, KeyHandle); if (*Status == NDIS_STATUS_SUCCESS) { PNDIS_CONFIGURATION_HANDLE NewHandle = *(PNDIS_CONFIGURATION_HANDLE *)KeyHandle; // // The path in the new handle has the name of the key. Extract it and return to caller // RtlInitUnicodeString(KeyName, NewHandle->KeyQueryTable[3].Name); KeyName->Buffer = (PWSTR)((PUCHAR)KeyName->Buffer + KeyName->Length - KeyPath.Length); KeyName->Length = KeyPath.Length; KeyName->MaximumLength = KeyPath.MaximumLength; } } } while (FALSE); if (AbsolutePath.Buffer != NULL) { FREE_POOL(AbsolutePath.Buffer); } if (InfoBuf != NULL) { FREE_POOL(InfoBuf); } }