2010-04-25 15:58:34 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: .inf file parser
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* PROGRAMMER: Royce Mitchell III
|
|
|
|
* Eric Kohl
|
|
|
|
* Ge van Geldorp <gvg@reactos.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
|
|
|
#include "inflib.h"
|
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2018-04-23 09:58:34 +00:00
|
|
|
static size_t
|
2010-04-25 15:58:34 +00:00
|
|
|
InfpSubstituteString(PINFCACHE Inf,
|
|
|
|
const WCHAR *text,
|
|
|
|
WCHAR *buffer,
|
2018-04-23 09:58:34 +00:00
|
|
|
size_t size);
|
2010-04-25 15:58:34 +00:00
|
|
|
|
2013-07-18 20:29:18 +00:00
|
|
|
static void
|
|
|
|
ShortToHex(PWCHAR Buffer,
|
|
|
|
USHORT Value)
|
|
|
|
{
|
|
|
|
WCHAR HexDigits[] = L"0123456789abcdef";
|
|
|
|
|
|
|
|
Buffer[0] = HexDigits[Value >> 12 & 0xf];
|
|
|
|
Buffer[1] = HexDigits[Value >> 8 & 0xf];
|
|
|
|
Buffer[2] = HexDigits[Value >> 4 & 0xf];
|
|
|
|
Buffer[3] = HexDigits[Value >> 0 & 0xf];
|
|
|
|
}
|
|
|
|
|
2010-04-25 15:58:34 +00:00
|
|
|
/* retrieve the string substitution for a given string, or NULL if not found */
|
|
|
|
/* if found, len is set to the substitution length */
|
|
|
|
static PCWSTR
|
|
|
|
InfpGetSubstitutionString(PINFCACHE Inf,
|
|
|
|
PCWSTR str,
|
2018-04-23 09:58:34 +00:00
|
|
|
size_t *len,
|
2010-04-25 15:58:34 +00:00
|
|
|
BOOL no_trailing_slash)
|
|
|
|
{
|
|
|
|
static const WCHAR percent = '%';
|
|
|
|
|
|
|
|
INFSTATUS Status = INF_STATUS_NOT_FOUND;
|
|
|
|
PINFCONTEXT Context = NULL;
|
|
|
|
PWCHAR Data = NULL;
|
|
|
|
WCHAR ValueName[MAX_INF_STRING_LENGTH +1];
|
2013-07-18 20:29:18 +00:00
|
|
|
WCHAR StringLangId[] = L"Strings.XXXX";
|
2010-04-25 15:58:34 +00:00
|
|
|
|
|
|
|
if (!*len) /* empty string (%%) is replaced by single percent */
|
|
|
|
{
|
|
|
|
*len = 1;
|
|
|
|
return &percent;
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:17:11 +00:00
|
|
|
memcpy(ValueName, str, *len * sizeof(WCHAR));
|
2010-04-25 15:58:34 +00:00
|
|
|
ValueName[*len] = 0;
|
|
|
|
|
|
|
|
DPRINT("Value name: %S\n", ValueName);
|
|
|
|
|
2010-04-25 19:20:59 +00:00
|
|
|
if (Inf->LanguageId != 0)
|
2010-04-25 15:58:34 +00:00
|
|
|
{
|
2013-07-18 20:29:18 +00:00
|
|
|
ShortToHex(&StringLangId[sizeof("Strings.") - 1],
|
|
|
|
Inf->LanguageId);
|
2010-04-25 15:58:34 +00:00
|
|
|
|
|
|
|
Status = InfpFindFirstLine(Inf,
|
|
|
|
StringLangId,
|
|
|
|
ValueName,
|
|
|
|
&Context);
|
|
|
|
if (Status != INF_STATUS_SUCCESS)
|
|
|
|
{
|
2013-07-18 20:29:18 +00:00
|
|
|
ShortToHex(&StringLangId[sizeof("Strings.") - 1],
|
|
|
|
MAKELANGID(PRIMARYLANGID(Inf->LanguageId), SUBLANG_NEUTRAL));
|
2010-04-25 15:58:34 +00:00
|
|
|
|
|
|
|
Status = InfpFindFirstLine(Inf,
|
|
|
|
StringLangId,
|
|
|
|
ValueName,
|
|
|
|
&Context);
|
|
|
|
if (Status != INF_STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
Status = InfpFindFirstLine(Inf,
|
|
|
|
L"Strings",
|
|
|
|
ValueName,
|
|
|
|
&Context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = InfpFindFirstLine(Inf,
|
|
|
|
L"Strings",
|
|
|
|
ValueName,
|
|
|
|
&Context);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Status != INF_STATUS_SUCCESS || Context == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
Status = InfpGetData(Context,
|
|
|
|
NULL,
|
|
|
|
&Data);
|
|
|
|
|
|
|
|
InfpFreeContext(Context);
|
|
|
|
|
|
|
|
if (Status == STATUS_SUCCESS)
|
|
|
|
{
|
2010-05-01 10:43:39 +00:00
|
|
|
*len = strlenW(Data);
|
2018-04-23 09:58:34 +00:00
|
|
|
DPRINT("Substitute: %S Length: %zu\n", Data, *len);
|
2010-04-25 15:58:34 +00:00
|
|
|
return Data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* do string substitutions on the specified text */
|
|
|
|
/* the buffer is assumed to be large enough */
|
|
|
|
/* returns necessary length not including terminating null */
|
2018-04-23 09:58:34 +00:00
|
|
|
static size_t
|
2010-04-25 15:58:34 +00:00
|
|
|
InfpSubstituteString(PINFCACHE Inf,
|
|
|
|
PCWSTR text,
|
|
|
|
PWSTR buffer,
|
2018-04-23 09:58:34 +00:00
|
|
|
size_t size)
|
2010-04-25 15:58:34 +00:00
|
|
|
{
|
|
|
|
const WCHAR *start, *subst, *p;
|
2018-04-23 09:58:34 +00:00
|
|
|
size_t len, total = 0;
|
2010-04-25 15:58:34 +00:00
|
|
|
int inside = 0;
|
|
|
|
|
|
|
|
if (!buffer) size = MAX_INF_STRING_LENGTH + 1;
|
|
|
|
for (p = start = text; *p; p++)
|
|
|
|
{
|
|
|
|
if (*p != '%') continue;
|
|
|
|
inside = !inside;
|
|
|
|
if (inside) /* start of a %xx% string */
|
|
|
|
{
|
2018-04-23 09:58:34 +00:00
|
|
|
len = (p - start);
|
2010-04-25 15:58:34 +00:00
|
|
|
if (len > size - 1) len = size - 1;
|
|
|
|
if (buffer) memcpy( buffer + total, start, len * sizeof(WCHAR) );
|
|
|
|
total += len;
|
|
|
|
size -= len;
|
|
|
|
start = p;
|
|
|
|
}
|
|
|
|
else /* end of the %xx% string, find substitution */
|
|
|
|
{
|
2018-04-23 09:58:34 +00:00
|
|
|
len = (p - start - 1);
|
2010-04-25 15:58:34 +00:00
|
|
|
subst = InfpGetSubstitutionString( Inf, start + 1, &len, p[1] == '\\' );
|
|
|
|
if (!subst)
|
|
|
|
{
|
|
|
|
subst = start;
|
2018-04-23 09:58:34 +00:00
|
|
|
len = (p - start + 1);
|
2010-04-25 15:58:34 +00:00
|
|
|
}
|
|
|
|
if (len > size - 1) len = size - 1;
|
|
|
|
if (buffer) memcpy( buffer + total, subst, len * sizeof(WCHAR) );
|
|
|
|
total += len;
|
|
|
|
size -= len;
|
|
|
|
start = p + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start != p) /* unfinished string, copy it */
|
|
|
|
{
|
|
|
|
len = (unsigned int)(p - start);
|
|
|
|
if (len > size - 1) len = size - 1;
|
|
|
|
if (buffer) memcpy( buffer + total, start, len * sizeof(WCHAR) );
|
|
|
|
total += len;
|
|
|
|
}
|
|
|
|
if (buffer && size) buffer[total] = 0;
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INFSTATUS
|
|
|
|
InfpFindFirstLine(PINFCACHE Cache,
|
|
|
|
PCWSTR Section,
|
|
|
|
PCWSTR Key,
|
|
|
|
PINFCONTEXT *Context)
|
|
|
|
{
|
|
|
|
PINFCACHESECTION CacheSection;
|
|
|
|
PINFCACHELINE CacheLine;
|
|
|
|
|
|
|
|
if (Cache == NULL || Section == NULL || Context == NULL)
|
|
|
|
{
|
|
|
|
DPRINT1("Invalid parameter\n");
|
|
|
|
return INF_STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
CacheSection = InfpFindSection(Cache, Section);
|
|
|
|
if (NULL == CacheSection)
|
|
|
|
{
|
|
|
|
DPRINT("Section not found\n");
|
|
|
|
return INF_STATUS_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Key != NULL)
|
|
|
|
{
|
|
|
|
CacheLine = InfpFindKeyLine(CacheSection, Key);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CacheLine = CacheSection->FirstLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL == CacheLine)
|
|
|
|
{
|
|
|
|
DPRINT("Key not found\n");
|
|
|
|
return INF_STATUS_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
*Context = MALLOC(sizeof(INFCONTEXT));
|
|
|
|
if (NULL == *Context)
|
|
|
|
{
|
|
|
|
DPRINT1("MALLOC() failed\n");
|
|
|
|
return INF_STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
(*Context)->Inf = (PVOID)Cache;
|
2019-06-23 20:35:19 +00:00
|
|
|
(*Context)->Section = CacheSection->Id;
|
|
|
|
(*Context)->Line = CacheLine->Id;
|
2010-04-25 15:58:34 +00:00
|
|
|
|
|
|
|
return INF_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INFSTATUS
|
|
|
|
InfpFindNextLine(PINFCONTEXT ContextIn,
|
|
|
|
PINFCONTEXT ContextOut)
|
|
|
|
{
|
|
|
|
PINFCACHELINE CacheLine;
|
|
|
|
|
|
|
|
if (ContextIn == NULL || ContextOut == NULL)
|
|
|
|
return INF_STATUS_INVALID_PARAMETER;
|
|
|
|
|
2019-06-23 20:35:19 +00:00
|
|
|
CacheLine = InfpGetLineForContext(ContextIn);
|
|
|
|
if (CacheLine == NULL)
|
2010-04-25 15:58:34 +00:00
|
|
|
return INF_STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if (CacheLine->Next == NULL)
|
|
|
|
return INF_STATUS_NOT_FOUND;
|
|
|
|
|
|
|
|
if (ContextIn != ContextOut)
|
|
|
|
{
|
|
|
|
ContextOut->Inf = ContextIn->Inf;
|
|
|
|
ContextOut->Section = ContextIn->Section;
|
|
|
|
}
|
2019-06-23 20:35:19 +00:00
|
|
|
ContextOut->Line = CacheLine->Next->Id;
|
2010-04-25 15:58:34 +00:00
|
|
|
|
|
|
|
return INF_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INFSTATUS
|
|
|
|
InfpFindFirstMatchLine(PINFCONTEXT ContextIn,
|
|
|
|
PCWSTR Key,
|
|
|
|
PINFCONTEXT ContextOut)
|
|
|
|
{
|
2019-06-23 20:35:19 +00:00
|
|
|
PINFCACHESECTION Section;
|
2010-04-25 15:58:34 +00:00
|
|
|
PINFCACHELINE CacheLine;
|
|
|
|
|
|
|
|
if (ContextIn == NULL || ContextOut == NULL || Key == NULL || *Key == 0)
|
|
|
|
return INF_STATUS_INVALID_PARAMETER;
|
|
|
|
|
2019-06-23 20:35:19 +00:00
|
|
|
Section = InfpGetSectionForContext(ContextIn);
|
|
|
|
if (Section == NULL)
|
|
|
|
return INF_STATUS_INVALID_PARAMETER;
|
2010-04-25 15:58:34 +00:00
|
|
|
|
2019-06-23 20:35:19 +00:00
|
|
|
CacheLine = Section->FirstLine;
|
2010-04-25 15:58:34 +00:00
|
|
|
while (CacheLine != NULL)
|
|
|
|
{
|
2010-05-01 10:43:39 +00:00
|
|
|
if (CacheLine->Key != NULL && strcmpiW (CacheLine->Key, Key) == 0)
|
2010-04-25 15:58:34 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (ContextIn != ContextOut)
|
|
|
|
{
|
|
|
|
ContextOut->Inf = ContextIn->Inf;
|
|
|
|
ContextOut->Section = ContextIn->Section;
|
|
|
|
}
|
2019-06-23 20:35:19 +00:00
|
|
|
ContextOut->Line = CacheLine->Id;
|
2010-04-25 15:58:34 +00:00
|
|
|
|
|
|
|
return INF_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
CacheLine = CacheLine->Next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return INF_STATUS_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INFSTATUS
|
|
|
|
InfpFindNextMatchLine(PINFCONTEXT ContextIn,
|
|
|
|
PCWSTR Key,
|
|
|
|
PINFCONTEXT ContextOut)
|
|
|
|
{
|
2019-06-23 20:35:19 +00:00
|
|
|
PINFCACHESECTION Section;
|
2010-04-25 15:58:34 +00:00
|
|
|
PINFCACHELINE CacheLine;
|
|
|
|
|
|
|
|
if (ContextIn == NULL || ContextOut == NULL || Key == NULL || *Key == 0)
|
|
|
|
return INF_STATUS_INVALID_PARAMETER;
|
|
|
|
|
2019-06-23 20:35:19 +00:00
|
|
|
Section = InfpGetSectionForContext(ContextIn);
|
|
|
|
if (Section == NULL)
|
|
|
|
return INF_STATUS_INVALID_PARAMETER;
|
2010-04-25 15:58:34 +00:00
|
|
|
|
2019-06-23 20:35:19 +00:00
|
|
|
CacheLine = InfpGetLineForContext(ContextIn);
|
2010-04-25 15:58:34 +00:00
|
|
|
while (CacheLine != NULL)
|
|
|
|
{
|
2010-05-01 10:43:39 +00:00
|
|
|
if (CacheLine->Key != NULL && strcmpiW (CacheLine->Key, Key) == 0)
|
2010-04-25 15:58:34 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (ContextIn != ContextOut)
|
|
|
|
{
|
|
|
|
ContextOut->Inf = ContextIn->Inf;
|
|
|
|
ContextOut->Section = ContextIn->Section;
|
|
|
|
}
|
2019-06-23 20:35:19 +00:00
|
|
|
ContextOut->Line = CacheLine->Id;
|
2010-04-25 15:58:34 +00:00
|
|
|
|
|
|
|
return INF_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
CacheLine = CacheLine->Next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return INF_STATUS_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LONG
|
|
|
|
InfpGetLineCount(HINF InfHandle,
|
|
|
|
PCWSTR 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 (CacheSection != NULL)
|
|
|
|
{
|
|
|
|
/* Are the section names the same? */
|
2010-05-01 10:43:39 +00:00
|
|
|
if (strcmpiW(CacheSection->Name, Section) == 0)
|
2010-04-25 15:58:34 +00:00
|
|
|
{
|
|
|
|
return CacheSection->LineCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the next section */
|
|
|
|
CacheSection = CacheSection->Next;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT("Section not found\n");
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* InfpGetLineText */
|
|
|
|
|
|
|
|
|
|
|
|
LONG
|
|
|
|
InfpGetFieldCount(PINFCONTEXT Context)
|
|
|
|
{
|
2019-06-23 20:35:19 +00:00
|
|
|
PINFCACHELINE Line;
|
2010-04-25 15:58:34 +00:00
|
|
|
|
2019-06-23 20:35:19 +00:00
|
|
|
Line = InfpGetLineForContext(Context);
|
|
|
|
if (Line == NULL)
|
|
|
|
return 0;
|
|
|
|
return Line->FieldCount;
|
2010-04-25 15:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INFSTATUS
|
|
|
|
InfpGetBinaryField(PINFCONTEXT Context,
|
|
|
|
ULONG FieldIndex,
|
|
|
|
PUCHAR ReturnBuffer,
|
|
|
|
ULONG ReturnBufferSize,
|
|
|
|
PULONG RequiredSize)
|
|
|
|
{
|
|
|
|
PINFCACHELINE CacheLine;
|
|
|
|
PINFCACHEFIELD CacheField;
|
|
|
|
ULONG Index;
|
|
|
|
ULONG Size;
|
|
|
|
PUCHAR Ptr;
|
|
|
|
|
2019-06-23 20:35:19 +00:00
|
|
|
if (Context == NULL || FieldIndex == 0)
|
2010-04-25 15:58:34 +00:00
|
|
|
{
|
|
|
|
DPRINT("Invalid parameter\n");
|
|
|
|
return INF_STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RequiredSize != NULL)
|
|
|
|
*RequiredSize = 0;
|
|
|
|
|
2019-06-23 20:35:19 +00:00
|
|
|
CacheLine = InfpGetLineForContext(Context);
|
2010-04-25 15:58:34 +00:00
|
|
|
|
|
|
|
if (FieldIndex > (ULONG)CacheLine->FieldCount)
|
|
|
|
return INF_STATUS_NOT_FOUND;
|
|
|
|
|
|
|
|
CacheField = CacheLine->FirstField;
|
|
|
|
for (Index = 1; Index < FieldIndex; Index++)
|
|
|
|
CacheField = CacheField->Next;
|
|
|
|
|
|
|
|
Size = (ULONG)CacheLine->FieldCount - FieldIndex + 1;
|
|
|
|
|
|
|
|
if (RequiredSize != NULL)
|
|
|
|
*RequiredSize = Size;
|
|
|
|
|
|
|
|
if (ReturnBuffer != NULL)
|
|
|
|
{
|
|
|
|
if (ReturnBufferSize < Size)
|
|
|
|
return INF_STATUS_BUFFER_OVERFLOW;
|
|
|
|
|
|
|
|
/* Copy binary data */
|
|
|
|
Ptr = ReturnBuffer;
|
|
|
|
while (CacheField != NULL)
|
|
|
|
{
|
2010-05-01 10:43:39 +00:00
|
|
|
*Ptr = (UCHAR)strtoulW(CacheField->Data, NULL, 16);
|
2010-04-25 15:58:34 +00:00
|
|
|
|
|
|
|
Ptr++;
|
|
|
|
CacheField = CacheField->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return INF_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INFSTATUS
|
|
|
|
InfpGetIntField(PINFCONTEXT Context,
|
|
|
|
ULONG FieldIndex,
|
2010-07-25 14:09:08 +00:00
|
|
|
INT *IntegerValue)
|
2010-04-25 15:58:34 +00:00
|
|
|
{
|
|
|
|
PINFCACHELINE CacheLine;
|
|
|
|
PINFCACHEFIELD CacheField;
|
|
|
|
ULONG Index;
|
|
|
|
PWCHAR Ptr;
|
|
|
|
|
2019-06-23 20:35:19 +00:00
|
|
|
if (Context == NULL || IntegerValue == NULL)
|
2010-04-25 15:58:34 +00:00
|
|
|
{
|
|
|
|
DPRINT("Invalid parameter\n");
|
|
|
|
return INF_STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2019-06-23 20:35:19 +00:00
|
|
|
CacheLine = InfpGetLineForContext(Context);
|
2010-04-25 15:58:34 +00:00
|
|
|
|
|
|
|
if (FieldIndex > (ULONG)CacheLine->FieldCount)
|
|
|
|
{
|
|
|
|
DPRINT("Invalid parameter\n");
|
|
|
|
return INF_STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FieldIndex == 0)
|
|
|
|
{
|
|
|
|
Ptr = CacheLine->Key;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CacheField = CacheLine->FirstField;
|
|
|
|
for (Index = 1; Index < FieldIndex; Index++)
|
|
|
|
CacheField = CacheField->Next;
|
|
|
|
|
|
|
|
Ptr = CacheField->Data;
|
|
|
|
}
|
|
|
|
|
2010-05-01 10:43:39 +00:00
|
|
|
*IntegerValue = (LONG)strtolW(Ptr, NULL, 0);
|
2010-04-25 15:58:34 +00:00
|
|
|
|
|
|
|
return INF_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INFSTATUS
|
|
|
|
InfpGetMultiSzField(PINFCONTEXT Context,
|
|
|
|
ULONG FieldIndex,
|
|
|
|
PWSTR ReturnBuffer,
|
|
|
|
ULONG ReturnBufferSize,
|
|
|
|
PULONG RequiredSize)
|
|
|
|
{
|
|
|
|
PINFCACHELINE CacheLine;
|
|
|
|
PINFCACHEFIELD CacheField;
|
|
|
|
PINFCACHEFIELD FieldPtr;
|
|
|
|
ULONG Index;
|
|
|
|
ULONG Size;
|
|
|
|
PWCHAR Ptr;
|
|
|
|
|
2019-06-23 20:35:19 +00:00
|
|
|
if (Context == NULL || FieldIndex == 0)
|
2010-04-25 15:58:34 +00:00
|
|
|
{
|
|
|
|
DPRINT("Invalid parameter\n");
|
|
|
|
return INF_STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RequiredSize != NULL)
|
|
|
|
*RequiredSize = 0;
|
|
|
|
|
2019-06-23 20:35:19 +00:00
|
|
|
CacheLine = InfpGetLineForContext(Context);
|
2010-04-25 15:58:34 +00:00
|
|
|
|
|
|
|
if (FieldIndex > (ULONG)CacheLine->FieldCount)
|
|
|
|
return INF_STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
CacheField = CacheLine->FirstField;
|
|
|
|
for (Index = 1; Index < FieldIndex; Index++)
|
|
|
|
CacheField = CacheField->Next;
|
|
|
|
|
|
|
|
/* Calculate the required buffer size */
|
|
|
|
FieldPtr = CacheField;
|
|
|
|
Size = 0;
|
|
|
|
while (FieldPtr != NULL)
|
|
|
|
{
|
2010-05-01 10:43:39 +00:00
|
|
|
Size += ((ULONG)strlenW(FieldPtr->Data) + 1);
|
2010-04-25 15:58:34 +00:00
|
|
|
FieldPtr = FieldPtr->Next;
|
|
|
|
}
|
|
|
|
Size++;
|
|
|
|
|
|
|
|
if (RequiredSize != NULL)
|
|
|
|
*RequiredSize = Size;
|
|
|
|
|
|
|
|
if (ReturnBuffer != NULL)
|
|
|
|
{
|
|
|
|
if (ReturnBufferSize < Size)
|
|
|
|
return INF_STATUS_BUFFER_OVERFLOW;
|
|
|
|
|
|
|
|
/* Copy multi-sz string */
|
|
|
|
Ptr = ReturnBuffer;
|
|
|
|
FieldPtr = CacheField;
|
|
|
|
while (FieldPtr != NULL)
|
|
|
|
{
|
2010-05-01 10:43:39 +00:00
|
|
|
Size = (ULONG)strlenW(FieldPtr->Data) + 1;
|
2010-04-25 15:58:34 +00:00
|
|
|
|
2010-05-01 10:43:39 +00:00
|
|
|
strcpyW(Ptr, FieldPtr->Data);
|
2010-04-25 15:58:34 +00:00
|
|
|
|
|
|
|
Ptr = Ptr + Size;
|
|
|
|
FieldPtr = FieldPtr->Next;
|
|
|
|
}
|
|
|
|
*Ptr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return INF_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INFSTATUS
|
|
|
|
InfpGetStringField(PINFCONTEXT Context,
|
|
|
|
ULONG FieldIndex,
|
|
|
|
PWSTR ReturnBuffer,
|
|
|
|
ULONG ReturnBufferSize,
|
|
|
|
PULONG RequiredSize)
|
|
|
|
{
|
|
|
|
PINFCACHELINE CacheLine;
|
|
|
|
PINFCACHEFIELD CacheField;
|
|
|
|
ULONG Index;
|
|
|
|
PWCHAR Ptr;
|
2018-04-23 09:58:34 +00:00
|
|
|
SIZE_T Size;
|
2010-04-25 15:58:34 +00:00
|
|
|
|
2019-06-23 20:35:19 +00:00
|
|
|
if (Context == NULL)
|
2010-04-25 15:58:34 +00:00
|
|
|
{
|
|
|
|
DPRINT("Invalid parameter\n");
|
|
|
|
return INF_STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RequiredSize != NULL)
|
|
|
|
*RequiredSize = 0;
|
|
|
|
|
2019-06-23 20:35:19 +00:00
|
|
|
CacheLine = InfpGetLineForContext(Context);
|
2010-04-25 15:58:34 +00:00
|
|
|
|
|
|
|
if (FieldIndex > (ULONG)CacheLine->FieldCount)
|
|
|
|
return INF_STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if (FieldIndex == 0)
|
|
|
|
{
|
|
|
|
Ptr = CacheLine->Key;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CacheField = CacheLine->FirstField;
|
|
|
|
for (Index = 1; Index < FieldIndex; Index++)
|
|
|
|
CacheField = CacheField->Next;
|
|
|
|
|
|
|
|
Ptr = CacheField->Data;
|
|
|
|
}
|
|
|
|
|
2010-05-01 10:43:39 +00:00
|
|
|
// Size = (ULONG)strlenW(Ptr) + 1;
|
2010-04-25 15:58:34 +00:00
|
|
|
Size = InfpSubstituteString(Context->Inf,
|
|
|
|
Ptr,
|
|
|
|
NULL,
|
|
|
|
0);
|
|
|
|
|
|
|
|
if (RequiredSize != NULL)
|
2019-04-15 11:29:33 +00:00
|
|
|
*RequiredSize = (ULONG)Size + 1;
|
2010-04-25 15:58:34 +00:00
|
|
|
|
|
|
|
if (ReturnBuffer != NULL)
|
|
|
|
{
|
|
|
|
if (ReturnBufferSize <= Size)
|
|
|
|
return INF_STATUS_BUFFER_OVERFLOW;
|
|
|
|
|
2010-05-01 10:43:39 +00:00
|
|
|
// strcpyW(ReturnBuffer, Ptr);
|
2010-04-25 15:58:34 +00:00
|
|
|
InfpSubstituteString(Context->Inf,
|
|
|
|
Ptr,
|
|
|
|
ReturnBuffer,
|
|
|
|
ReturnBufferSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
return INF_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INFSTATUS
|
|
|
|
InfpGetData(PINFCONTEXT Context,
|
|
|
|
PWCHAR *Key,
|
|
|
|
PWCHAR *Data)
|
|
|
|
{
|
|
|
|
PINFCACHELINE CacheKey;
|
|
|
|
|
2019-06-23 20:35:19 +00:00
|
|
|
if (Context == NULL || Data == NULL)
|
2010-04-25 15:58:34 +00:00
|
|
|
{
|
|
|
|
DPRINT("Invalid parameter\n");
|
|
|
|
return INF_STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2019-06-23 20:35:19 +00:00
|
|
|
CacheKey = InfpGetLineForContext(Context);
|
2010-04-25 15:58:34 +00:00
|
|
|
if (Key != NULL)
|
|
|
|
*Key = CacheKey->Key;
|
|
|
|
|
|
|
|
if (Data != NULL)
|
|
|
|
{
|
|
|
|
if (CacheKey->FirstField == NULL)
|
|
|
|
{
|
|
|
|
*Data = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*Data = CacheKey->FirstField->Data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return INF_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INFSTATUS
|
|
|
|
InfpGetDataField(PINFCONTEXT Context,
|
|
|
|
ULONG FieldIndex,
|
|
|
|
PWCHAR *Data)
|
|
|
|
{
|
|
|
|
PINFCACHELINE CacheLine;
|
|
|
|
PINFCACHEFIELD CacheField;
|
|
|
|
ULONG Index;
|
|
|
|
|
2019-06-23 20:35:19 +00:00
|
|
|
if (Context == NULL || Data == NULL)
|
2010-04-25 15:58:34 +00:00
|
|
|
{
|
|
|
|
DPRINT("Invalid parameter\n");
|
|
|
|
return INF_STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2019-06-23 20:35:19 +00:00
|
|
|
CacheLine = InfpGetLineForContext(Context);
|
2010-04-25 15:58:34 +00:00
|
|
|
|
|
|
|
if (FieldIndex > (ULONG)CacheLine->FieldCount)
|
|
|
|
return INF_STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if (FieldIndex == 0)
|
|
|
|
{
|
|
|
|
*Data = CacheLine->Key;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CacheField = CacheLine->FirstField;
|
|
|
|
for (Index = 1; Index < FieldIndex; Index++)
|
|
|
|
CacheField = CacheField->Next;
|
|
|
|
|
|
|
|
*Data = CacheField->Data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return INF_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
InfpFreeContext(PINFCONTEXT Context)
|
|
|
|
{
|
|
|
|
FREE(Context);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|