📄 config.c
字号:
OUT PNDIS_STATUS Status,
OUT PNDIS_CONFIGURATION_PARAMETER * ParameterValue,
IN NDIS_HANDLE ConfigurationHandle,
IN PNDIS_STRING Keyword,
IN NDIS_PARAMETER_TYPE ParameterType)
/*
* FUNCTION: Read a configuration value from the registry, tracking its resources
* ARGUMENTS:
* Status: points to a place to write status into
* ParameterValue: Pointer to receive a newly-allocated parameter structure
* ConfigurationHandle: handle originally returned by an open function
* Keyword: Value name to read, or one of the following constants:
* Environment - returns NdisEnvironmentWindowsNt
* ProcessorType - returns NdisProcessorX86 until more architectures are added
* NdisVersion - returns NDIS_VERSION
* ParameterType: the type of the value to be queried
* RETURNS:
* - A status in Status
* - A parameter value in ParameterValue
*/
{
KEY_VALUE_PARTIAL_INFORMATION *KeyInformation;
ULONG KeyDataLength;
PMINIPORT_RESOURCE MiniportResource;
PMINIPORT_CONFIGURATION_CONTEXT ConfigurationContext = (PMINIPORT_CONFIGURATION_CONTEXT)ConfigurationHandle;
*ParameterValue = NULL;
*Status = NDIS_STATUS_FAILURE;
if(ParameterType != NdisParameterInteger &&
ParameterType != NdisParameterHexInteger &&
ParameterType != NdisParameterString &&
ParameterType != NdisParameterMultiString &&
ParameterType != NdisParameterBinary
)
{
NDIS_DbgPrint(MID_TRACE,("unsupported parameter type\n"));
return;
}
NDIS_DbgPrint(MAX_TRACE,("requested read of %wZ\n", Keyword));
if(
!wcsncmp(Keyword->Buffer, L"Environment", Keyword->Length/sizeof(WCHAR)) &&
wcslen(L"Environment") == Keyword->Length/sizeof(WCHAR)
)
{
*ParameterValue = ExAllocatePool(PagedPool, sizeof(NDIS_CONFIGURATION_PARAMETER));
if(!*ParameterValue)
{
NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
*Status = NDIS_STATUS_RESOURCES;
return;
}
MiniportResource = ExAllocatePool(PagedPool, sizeof(MINIPORT_RESOURCE));
if(!MiniportResource)
{
NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
ExFreePool(*ParameterValue);
*ParameterValue = NULL;
*Status = NDIS_STATUS_RESOURCES;
return;
}
MiniportResource->ResourceType = 0;
MiniportResource->Resource = *ParameterValue;
NDIS_DbgPrint(MID_TRACE,("inserting 0x%x into the resource list\n",
MiniportResource->Resource));
ExInterlockedInsertTailList(&ConfigurationContext->ResourceListHead,
&MiniportResource->ListEntry, &ConfigurationContext->ResourceLock);
(*ParameterValue)->ParameterType = NdisParameterInteger;
(*ParameterValue)->ParameterData.IntegerData = NdisEnvironmentWindowsNt;
*Status = NDIS_STATUS_SUCCESS;
return;
}
if(
!wcsncmp(Keyword->Buffer, L"ProcessorType", Keyword->Length/sizeof(WCHAR)) &&
wcslen(L"ProcessorType") == Keyword->Length/sizeof(WCHAR)
)
{
*ParameterValue = ExAllocatePool(PagedPool, sizeof(NDIS_CONFIGURATION_PARAMETER));
if(!*ParameterValue)
{
NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
*Status = NDIS_STATUS_RESOURCES;
return;
}
MiniportResource = ExAllocatePool(PagedPool, sizeof(MINIPORT_RESOURCE));
if(!MiniportResource)
{
NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
ExFreePool(*ParameterValue);
*ParameterValue = NULL;
*Status = NDIS_STATUS_RESOURCES;
return;
}
MiniportResource->ResourceType = 0;
MiniportResource->Resource = *ParameterValue;
NDIS_DbgPrint(MID_TRACE,("inserting 0x%x into the resource list\n", MiniportResource->Resource));
ExInterlockedInsertTailList(&ConfigurationContext->ResourceListHead,
&MiniportResource->ListEntry, &ConfigurationContext->ResourceLock);
(*ParameterValue)->ParameterType = NdisParameterInteger;
(*ParameterValue)->ParameterData.IntegerData = NdisProcessorX86; /* XXX non-portable */
*Status = NDIS_STATUS_SUCCESS;
return;
}
if(
!wcsncmp(Keyword->Buffer, L"NdisVersion", Keyword->Length/sizeof(WCHAR)) &&
wcslen(L"NdisVersion") == Keyword->Length/sizeof(WCHAR)
)
{
*ParameterValue = ExAllocatePool(PagedPool, sizeof(NDIS_CONFIGURATION_PARAMETER));
if(!*ParameterValue)
{
NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
*Status = NDIS_STATUS_RESOURCES;
return;
}
MiniportResource = ExAllocatePool(PagedPool, sizeof(MINIPORT_RESOURCE));
if(!MiniportResource)
{
NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
ExFreePool(*ParameterValue);
*ParameterValue = NULL;
*Status = NDIS_STATUS_RESOURCES;
return;
}
MiniportResource->ResourceType = 0;
MiniportResource->Resource = *ParameterValue;
NDIS_DbgPrint(MID_TRACE,("inserting 0x%x into the resource list\n", MiniportResource->Resource));
ExInterlockedInsertTailList(&ConfigurationContext->ResourceListHead,
&MiniportResource->ListEntry, &ConfigurationContext->ResourceLock);
(*ParameterValue)->ParameterType = NdisParameterInteger;
(*ParameterValue)->ParameterData.IntegerData = NDIS_VERSION;
*Status = NDIS_STATUS_SUCCESS;
NDIS_DbgPrint(MAX_TRACE,("ParameterType = %0x%x, ParameterValue = 0x%x\n",
(*ParameterValue)->ParameterType, (*ParameterValue)->ParameterData.IntegerData));
return;
}
/* figure out how much buffer i should allocate */
*Status = ZwQueryValueKey(ConfigurationContext->Handle, Keyword, KeyValuePartialInformation, NULL, 0, &KeyDataLength);
if(*Status != STATUS_BUFFER_OVERFLOW && *Status != STATUS_BUFFER_TOO_SMALL && *Status != STATUS_SUCCESS)
{
NDIS_DbgPrint(MID_TRACE,("ZwQueryValueKey #1 failed for %wZ, status 0x%x\n", Keyword, *Status));
*Status = NDIS_STATUS_FAILURE;
return;
}
/* allocate it */
KeyInformation = ExAllocatePool(PagedPool, KeyDataLength + sizeof(KEY_VALUE_PARTIAL_INFORMATION));
if(!KeyInformation)
{
NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
*Status = NDIS_STATUS_RESOURCES;
return;
}
/* grab the value */
*Status = ZwQueryValueKey(ConfigurationContext->Handle, Keyword, KeyValuePartialInformation,
KeyInformation, KeyDataLength + sizeof(KEY_VALUE_PARTIAL_INFORMATION), &KeyDataLength);
if(*Status != STATUS_SUCCESS)
{
ExFreePool(KeyInformation);
NDIS_DbgPrint(MID_TRACE,("ZwQueryValueKey #2 failed for %wZ, status 0x%x\n", Keyword, *Status));
*Status = NDIS_STATUS_FAILURE;
return;
}
switch(ParameterType)
{
case NdisParameterInteger:
case NdisParameterHexInteger:
{
UNICODE_STRING str;
*ParameterValue = ExAllocatePool(PagedPool, sizeof(NDIS_CONFIGURATION_PARAMETER));
if(!*ParameterValue)
{
NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
ExFreePool(KeyInformation);
*Status = NDIS_STATUS_RESOURCES;
return;
}
str.Length = str.MaximumLength = (USHORT)KeyInformation->DataLength;
str.Buffer = (PWCHAR)KeyInformation->Data;
(*ParameterValue)->ParameterType = ParameterType;
/*
If ParameterType is NdisParameterInteger then the base of str is decimal.
If ParameterType is NdisParameterHexInteger then the base of str is hexadecimal.
*/
if (ParameterType == NdisParameterInteger)
*Status = RtlUnicodeStringToInteger(&str, 10, &(*ParameterValue)->ParameterData.IntegerData);
else if (ParameterType == NdisParameterHexInteger)
*Status = RtlUnicodeStringToInteger(&str, 16, &(*ParameterValue)->ParameterData.IntegerData);
ExFreePool(KeyInformation);
if(*Status != STATUS_SUCCESS)
*Status = NDIS_STATUS_FAILURE;
else
*Status = NDIS_STATUS_SUCCESS;
return;
}
case NdisParameterString:
case NdisParameterMultiString:
{
PWCHAR RegData = 0;
if(KeyInformation->Type != REG_SZ && KeyInformation->Type != REG_MULTI_SZ)
{
NDIS_DbgPrint(MID_TRACE,("requested type does not match actual value type\n"));
ExFreePool(KeyInformation);
*ParameterValue = NULL;
*Status = NDIS_STATUS_FAILURE;
return;
}
*ParameterValue = ExAllocatePool(PagedPool, sizeof(NDIS_CONFIGURATION_PARAMETER));
if(!*ParameterValue)
{
NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
ExFreePool(KeyInformation);
*Status = NDIS_STATUS_RESOURCES;
return;
}
RegData = ExAllocatePool(PagedPool, KeyInformation->DataLength);
if(!RegData)
{
NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
ExFreePool(KeyInformation);
ExFreePool(*ParameterValue);
*ParameterValue = NULL;
*Status = NDIS_STATUS_FAILURE;
return;
}
MiniportResource = ExAllocatePool(PagedPool, sizeof(MINIPORT_RESOURCE));
if(!MiniportResource)
{
NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
ExFreePool(KeyInformation);
ExFreePool(*ParameterValue);
*ParameterValue = NULL;
*Status = NDIS_STATUS_RESOURCES;
return;
}
MiniportResource->ResourceType = 0;
MiniportResource->Resource = *ParameterValue;
NDIS_DbgPrint(MID_TRACE,("inserting 0x%x into the resource list\n", MiniportResource->Resource));
ExInterlockedInsertTailList(&ConfigurationContext->ResourceListHead, &MiniportResource->ListEntry, &ConfigurationContext->ResourceLock);
memcpy(RegData, KeyInformation->Data, KeyInformation->DataLength);
(*ParameterValue)->ParameterType = ParameterType;
(*ParameterValue)->ParameterData.StringData.Length = (USHORT)KeyInformation->DataLength;
(*ParameterValue)->ParameterData.StringData.Buffer = RegData;
ExFreePool(KeyInformation);
*Status = NDIS_STATUS_SUCCESS;
return;
}
case NdisParameterBinary:
{
if(KeyInformation->Type != REG_BINARY)
{
NDIS_DbgPrint(MIN_TRACE,("requested type does not match actual value type\n"));
*Status = NDIS_STATUS_FAILURE;
ExFreePool(KeyInformation);
return;
}
*ParameterValue = ExAllocatePool(PagedPool, sizeof(NDIS_CONFIGURATION_PARAMETER) + KeyInformation->DataLength);
if(!*ParameterValue)
{
NDIS_DbgPrint(MIN_TRACE,("Insufficient resources.\n"));
ExFreePool(KeyInformation);
*Status = NDIS_STATUS_RESOURCES;
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -