📄 inffile.c
字号:
if (InfHandle == NULL || Section == NULL || Context == NULL)
{
// DPRINT("Invalid parameter\n");
return FALSE;
}
Cache = (PINFCACHE)InfHandle;
/* Iterate through list of sections */
CacheSection = Cache->FirstSection;
while (Section != NULL)
{
// DPRINT("Comparing '%S' and '%S'\n", CacheSection->Name, Section);
/* Are the section names the same? */
if (_stricmp(CacheSection->Name, Section) == 0)
{
if (Key != NULL)
{
CacheLine = InfpCacheFindKeyLine (CacheSection, Key);
}
else
{
CacheLine = CacheSection->FirstLine;
}
if (CacheLine == NULL)
return FALSE;
Context->Inf = (PVOID)Cache;
Context->Section = (PVOID)CacheSection;
Context->Line = (PVOID)CacheLine;
return TRUE;
}
/* Get the next section */
CacheSection = CacheSection->Next;
}
// DPRINT("Section not found\n");
return FALSE;
}
BOOLEAN
InfFindNextLine (PINFCONTEXT ContextIn,
PINFCONTEXT ContextOut)
{
PINFCACHELINE CacheLine;
if (ContextIn == NULL || ContextOut == NULL)
return FALSE;
if (ContextIn->Line == NULL)
return FALSE;
CacheLine = (PINFCACHELINE)ContextIn->Line;
if (CacheLine->Next == NULL)
return FALSE;
if (ContextIn != ContextOut)
{
ContextOut->Inf = ContextIn->Inf;
ContextOut->Section = ContextIn->Section;
}
ContextOut->Line = (PVOID)(CacheLine->Next);
return TRUE;
}
BOOLEAN
InfFindFirstMatchLine (PINFCONTEXT ContextIn,
PCHAR Key,
PINFCONTEXT ContextOut)
{
PINFCACHELINE CacheLine;
if (ContextIn == NULL || ContextOut == NULL || Key == NULL || *Key == 0)
return FALSE;
if (ContextIn->Inf == NULL || ContextIn->Section == NULL)
return FALSE;
CacheLine = ((PINFCACHESECTION)(ContextIn->Section))->FirstLine;
while (CacheLine != NULL)
{
if (CacheLine->Key != NULL && _stricmp (CacheLine->Key, Key) == 0)
{
if (ContextIn != ContextOut)
{
ContextOut->Inf = ContextIn->Inf;
ContextOut->Section = ContextIn->Section;
}
ContextOut->Line = (PVOID)CacheLine;
return TRUE;
}
CacheLine = CacheLine->Next;
}
return FALSE;
}
BOOLEAN
InfFindNextMatchLine (PINFCONTEXT ContextIn,
PCHAR Key,
PINFCONTEXT ContextOut)
{
PINFCACHELINE CacheLine;
if (ContextIn == NULL || ContextOut == NULL || Key == NULL || *Key == 0)
return FALSE;
if (ContextIn->Inf == NULL || ContextIn->Section == NULL || ContextIn->Line == NULL)
return FALSE;
CacheLine = (PINFCACHELINE)ContextIn->Line;
while (CacheLine != NULL)
{
if (CacheLine->Key != NULL && _stricmp (CacheLine->Key, Key) == 0)
{
if (ContextIn != ContextOut)
{
ContextOut->Inf = ContextIn->Inf;
ContextOut->Section = ContextIn->Section;
}
ContextOut->Line = (PVOID)CacheLine;
return TRUE;
}
CacheLine = CacheLine->Next;
}
return FALSE;
}
LONG
InfGetLineCount(HINF InfHandle,
PCHAR Section)
{
PINFCACHE Cache;
PINFCACHESECTION CacheSection;
if (InfHandle == NULL || Section == NULL)
{
// DPRINT("Invalid parameter\n");
return -1;
}
Cache = (PINFCACHE)InfHandle;
/* Iterate through list of sections */
CacheSection = Cache->FirstSection;
while (Section != NULL)
{
// DPRINT("Comparing '%S' and '%S'\n", CacheSection->Name, Section);
/* Are the section names the same? */
if (_stricmp(CacheSection->Name, Section) == 0)
{
return CacheSection->LineCount;
}
/* Get the next section */
CacheSection = CacheSection->Next;
}
// DPRINT("Section not found\n");
return -1;
}
/* InfGetLineText */
LONG
InfGetFieldCount(PINFCONTEXT Context)
{
if (Context == NULL || Context->Line == NULL)
return 0;
return ((PINFCACHELINE)Context->Line)->FieldCount;
}
BOOLEAN
InfGetBinaryField (PINFCONTEXT Context,
ULONG FieldIndex,
PUCHAR ReturnBuffer,
ULONG ReturnBufferSize,
PULONG RequiredSize)
{
PINFCACHELINE CacheLine;
PINFCACHEFIELD CacheField;
ULONG Index;
ULONG Size;
PUCHAR Ptr;
if (Context == NULL || Context->Line == NULL || FieldIndex == 0)
{
// DPRINT("Invalid parameter\n");
return FALSE;
}
if (RequiredSize != NULL)
*RequiredSize = 0;
CacheLine = (PINFCACHELINE)Context->Line;
if (FieldIndex > CacheLine->FieldCount)
return FALSE;
CacheField = CacheLine->FirstField;
for (Index = 1; Index < FieldIndex; Index++)
CacheField = CacheField->Next;
Size = CacheLine->FieldCount - FieldIndex + 1;
if (RequiredSize != NULL)
*RequiredSize = Size;
if (ReturnBuffer != NULL)
{
if (ReturnBufferSize < Size)
return FALSE;
/* Copy binary data */
Ptr = ReturnBuffer;
while (CacheField != NULL)
{
*Ptr = (UCHAR)atoi(CacheField->Data); //strtoul (CacheField->Data, NULL, 16);
Ptr++;
CacheField = CacheField->Next;
}
}
return TRUE;
}
BOOLEAN
InfGetIntField (PINFCONTEXT Context,
ULONG FieldIndex,
LONG *IntegerValue)
{
PINFCACHELINE CacheLine;
PINFCACHEFIELD CacheField;
ULONG Index;
PCHAR Ptr;
if (Context == NULL || Context->Line == NULL || IntegerValue == NULL)
{
// DPRINT("Invalid parameter\n");
return FALSE;
}
CacheLine = (PINFCACHELINE)Context->Line;
if (FieldIndex > CacheLine->FieldCount)
{
// DPRINT("Invalid parameter\n");
return FALSE;
}
if (FieldIndex == 0)
{
Ptr = CacheLine->Key;
}
else
{
CacheField = CacheLine->FirstField;
for (Index = 1; Index < FieldIndex; Index++)
CacheField = CacheField->Next;
Ptr = CacheField->Data;
}
*IntegerValue = atoi (Ptr); //strtol (Ptr, NULL, 0);
return TRUE;
}
BOOLEAN
InfGetMultiSzField (PINFCONTEXT Context,
ULONG FieldIndex,
PCHAR ReturnBuffer,
ULONG ReturnBufferSize,
PULONG RequiredSize)
{
PINFCACHELINE CacheLine;
PINFCACHEFIELD CacheField;
PINFCACHEFIELD FieldPtr;
ULONG Index;
ULONG Size;
PCHAR Ptr;
if (Context == NULL || Context->Line == NULL || FieldIndex == 0)
{
// DPRINT("Invalid parameter\n");
return FALSE;
}
if (RequiredSize != NULL)
*RequiredSize = 0;
CacheLine = (PINFCACHELINE)Context->Line;
if (FieldIndex > CacheLine->FieldCount)
return FALSE;
CacheField = CacheLine->FirstField;
for (Index = 1; Index < FieldIndex; Index++)
CacheField = CacheField->Next;
/* Calculate the required buffer size */
FieldPtr = CacheField;
Size = 0;
while (FieldPtr != NULL)
{
Size += (strlen (FieldPtr->Data) + 1);
FieldPtr = FieldPtr->Next;
}
Size++;
if (RequiredSize != NULL)
*RequiredSize = Size;
if (ReturnBuffer != NULL)
{
if (ReturnBufferSize < Size)
return FALSE;
/* Copy multi-sz string */
Ptr = ReturnBuffer;
FieldPtr = CacheField;
while (FieldPtr != NULL)
{
Size = strlen (FieldPtr->Data) + 1;
strcpy (Ptr, FieldPtr->Data);
Ptr = Ptr + Size;
FieldPtr = FieldPtr->Next;
}
*Ptr = 0;
}
return TRUE;
}
BOOLEAN
InfGetStringField (PINFCONTEXT Context,
ULONG FieldIndex,
PCHAR ReturnBuffer,
ULONG ReturnBufferSize,
PULONG RequiredSize)
{
PINFCACHELINE CacheLine;
PINFCACHEFIELD CacheField;
ULONG Index;
PCHAR Ptr;
ULONG Size;
if (Context == NULL || Context->Line == NULL || FieldIndex == 0)
{
// DPRINT("Invalid parameter\n");
return FALSE;
}
if (RequiredSize != NULL)
*RequiredSize = 0;
CacheLine = (PINFCACHELINE)Context->Line;
if (FieldIndex > CacheLine->FieldCount)
return FALSE;
if (FieldIndex == 0)
{
Ptr = CacheLine->Key;
}
else
{
CacheField = CacheLine->FirstField;
for (Index = 1; Index < FieldIndex; Index++)
CacheField = CacheField->Next;
Ptr = CacheField->Data;
}
Size = strlen (Ptr) + 1;
if (RequiredSize != NULL)
*RequiredSize = Size;
if (ReturnBuffer != NULL)
{
if (ReturnBufferSize < Size)
return FALSE;
strcpy (ReturnBuffer, Ptr);
}
return TRUE;
}
BOOLEAN
InfGetData (PINFCONTEXT Context,
PCHAR *Key,
PCHAR *Data)
{
PINFCACHELINE CacheKey;
if (Context == NULL || Context->Line == NULL || Data == NULL)
{
// DPRINT("Invalid parameter\n");
return FALSE;
}
CacheKey = (PINFCACHELINE)Context->Line;
if (Key != NULL)
*Key = CacheKey->Key;
if (Data != NULL)
{
if (CacheKey->FirstField == NULL)
{
*Data = NULL;
}
else
{
*Data = CacheKey->FirstField->Data;
}
}
return TRUE;
}
BOOLEAN
InfGetDataField (PINFCONTEXT Context,
ULONG FieldIndex,
PCSTR *Data)
{
PINFCACHELINE CacheLine;
PINFCACHEFIELD CacheField;
ULONG Index;
if (Context == NULL || Context->Line == NULL || Data == NULL)
{
// DPRINT("Invalid parameter\n");
return FALSE;
}
CacheLine = (PINFCACHELINE)Context->Line;
if (FieldIndex > CacheLine->FieldCount)
return FALSE;
if (FieldIndex == 0)
{
*Data = CacheLine->Key;
}
else
{
CacheField = CacheLine->FirstField;
for (Index = 1; Index < FieldIndex; Index++)
CacheField = CacheField->Next;
*Data = CacheField->Data;
}
return TRUE;
}
/* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -