https://git.reactos.org/?p=reactos.git;a=commitdiff;h=a75e4db855059604ef2998...
commit a75e4db855059604ef29989a2fa5b8e75189cf8c Author: Timo Kreuzer timo.kreuzer@reactos.org AuthorDate: Sun Jun 23 22:35:19 2019 +0200 Commit: GitHub noreply@github.com CommitDate: Sun Jun 23 22:35:19 2019 +0200
[INFLIB] Fix INFCONTEXT structure to be compatible with the official definition (#1603)
* [INFLIB] Fix INFCONTEXT structure to be compatible with the official definition.
This makes inflib work on x64. --- sdk/lib/inflib/infcore.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ sdk/lib/inflib/infget.c | 62 +++++++++++++++++++++++------------------- sdk/lib/inflib/infpriv.h | 14 ++++++++-- sdk/lib/inflib/infput.c | 30 ++++++++++++++------- 4 files changed, 136 insertions(+), 40 deletions(-)
diff --git a/sdk/lib/inflib/infcore.c b/sdk/lib/inflib/infcore.c index 7e187359e2a..7618f9e2401 100644 --- a/sdk/lib/inflib/infcore.c +++ b/sdk/lib/inflib/infcore.c @@ -191,6 +191,7 @@ InfpAddSection(PINFCACHE Cache, } ZEROMEMORY (Section, Size); + Section->Id = ++Cache->NextSectionId;
/* Copy section name */ strcpyW(Section->Name, Name); @@ -231,6 +232,7 @@ InfpAddLine(PINFCACHESECTION Section) } ZEROMEMORY(Line, sizeof(INFCACHELINE)); + Line->Id = ++Section->NextLineId;
/* Append line */ if (Section->FirstLine == NULL) @@ -249,6 +251,74 @@ InfpAddLine(PINFCACHESECTION Section) return Line; }
+PINFCACHESECTION +InfpFindSectionById(PINFCACHE Cache, UINT Id) +{ + PINFCACHESECTION Section; + + for (Section = Cache->FirstSection; + Section != NULL; + Section = Section->Next) + { + if (Section->Id == Id) + { + return Section; + } + } + + return NULL; +} + +PINFCACHESECTION +InfpGetSectionForContext(PINFCONTEXT Context) +{ + PINFCACHE Cache; + + if (Context == NULL) + { + return NULL; + } + + Cache = (PINFCACHE)Context->Inf; + if (Cache == NULL) + { + return NULL; + } + + return InfpFindSectionById(Cache, Context->Section); +} + +PINFCACHELINE +InfpFindLineById(PINFCACHESECTION Section, UINT Id) +{ + PINFCACHELINE Line; + + for (Line = Section->FirstLine; + Line != NULL; + Line = Line->Next) + { + if (Line->Id == Id) + { + return Line; + } + } + + return NULL; +} + +PINFCACHELINE +InfpGetLineForContext(PINFCONTEXT Context) +{ + PINFCACHESECTION Section; + + Section = InfpGetSectionForContext(Context); + if (Section == NULL) + { + return NULL; + } + + return InfpFindLineById(Section, Context->Line); +}
PVOID InfpAddKeyToLine(PINFCACHELINE Line, diff --git a/sdk/lib/inflib/infget.c b/sdk/lib/inflib/infget.c index 70b3473ff83..b1f963ea7c9 100644 --- a/sdk/lib/inflib/infget.c +++ b/sdk/lib/inflib/infget.c @@ -213,8 +213,8 @@ InfpFindFirstLine(PINFCACHE Cache, return INF_STATUS_NO_MEMORY; } (*Context)->Inf = (PVOID)Cache; - (*Context)->Section = (PVOID)CacheSection; - (*Context)->Line = (PVOID)CacheLine; + (*Context)->Section = CacheSection->Id; + (*Context)->Line = CacheLine->Id;
return INF_STATUS_SUCCESS; } @@ -229,10 +229,10 @@ InfpFindNextLine(PINFCONTEXT ContextIn, if (ContextIn == NULL || ContextOut == NULL) return INF_STATUS_INVALID_PARAMETER;
- if (ContextIn->Line == NULL) + CacheLine = InfpGetLineForContext(ContextIn); + if (CacheLine == NULL) return INF_STATUS_INVALID_PARAMETER;
- CacheLine = (PINFCACHELINE)ContextIn->Line; if (CacheLine->Next == NULL) return INF_STATUS_NOT_FOUND;
@@ -241,7 +241,7 @@ InfpFindNextLine(PINFCONTEXT ContextIn, ContextOut->Inf = ContextIn->Inf; ContextOut->Section = ContextIn->Section; } - ContextOut->Line = (PVOID)(CacheLine->Next); + ContextOut->Line = CacheLine->Next->Id;
return INF_STATUS_SUCCESS; } @@ -252,15 +252,17 @@ InfpFindFirstMatchLine(PINFCONTEXT ContextIn, PCWSTR Key, PINFCONTEXT ContextOut) { + PINFCACHESECTION Section; PINFCACHELINE CacheLine;
if (ContextIn == NULL || ContextOut == NULL || Key == NULL || *Key == 0) return INF_STATUS_INVALID_PARAMETER;
- if (ContextIn->Inf == NULL || ContextIn->Section == NULL) - return INF_STATUS_INVALID_PARAMETER; + Section = InfpGetSectionForContext(ContextIn); + if (Section == NULL) + return INF_STATUS_INVALID_PARAMETER;
- CacheLine = ((PINFCACHESECTION)(ContextIn->Section))->FirstLine; + CacheLine = Section->FirstLine; while (CacheLine != NULL) { if (CacheLine->Key != NULL && strcmpiW (CacheLine->Key, Key) == 0) @@ -271,7 +273,7 @@ InfpFindFirstMatchLine(PINFCONTEXT ContextIn, ContextOut->Inf = ContextIn->Inf; ContextOut->Section = ContextIn->Section; } - ContextOut->Line = (PVOID)CacheLine; + ContextOut->Line = CacheLine->Id;
return INF_STATUS_SUCCESS; } @@ -288,15 +290,17 @@ InfpFindNextMatchLine(PINFCONTEXT ContextIn, PCWSTR Key, PINFCONTEXT ContextOut) { + PINFCACHESECTION Section; PINFCACHELINE CacheLine;
if (ContextIn == NULL || ContextOut == NULL || Key == NULL || *Key == 0) return INF_STATUS_INVALID_PARAMETER;
- if (ContextIn->Inf == NULL || ContextIn->Section == NULL || ContextIn->Line == NULL) - return INF_STATUS_INVALID_PARAMETER; + Section = InfpGetSectionForContext(ContextIn); + if (Section == NULL) + return INF_STATUS_INVALID_PARAMETER;
- CacheLine = (PINFCACHELINE)ContextIn->Line; + CacheLine = InfpGetLineForContext(ContextIn); while (CacheLine != NULL) { if (CacheLine->Key != NULL && strcmpiW (CacheLine->Key, Key) == 0) @@ -307,7 +311,7 @@ InfpFindNextMatchLine(PINFCONTEXT ContextIn, ContextOut->Inf = ContextIn->Inf; ContextOut->Section = ContextIn->Section; } - ContextOut->Line = (PVOID)CacheLine; + ContextOut->Line = CacheLine->Id;
return INF_STATUS_SUCCESS; } @@ -360,10 +364,12 @@ InfpGetLineCount(HINF InfHandle, LONG InfpGetFieldCount(PINFCONTEXT Context) { - if (Context == NULL || Context->Line == NULL) - return 0; + PINFCACHELINE Line;
- return ((PINFCACHELINE)Context->Line)->FieldCount; + Line = InfpGetLineForContext(Context); + if (Line == NULL) + return 0; + return Line->FieldCount; }
@@ -380,7 +386,7 @@ InfpGetBinaryField(PINFCONTEXT Context, ULONG Size; PUCHAR Ptr;
- if (Context == NULL || Context->Line == NULL || FieldIndex == 0) + if (Context == NULL || FieldIndex == 0) { DPRINT("Invalid parameter\n"); return INF_STATUS_INVALID_PARAMETER; @@ -389,7 +395,7 @@ InfpGetBinaryField(PINFCONTEXT Context, if (RequiredSize != NULL) *RequiredSize = 0;
- CacheLine = (PINFCACHELINE)Context->Line; + CacheLine = InfpGetLineForContext(Context);
if (FieldIndex > (ULONG)CacheLine->FieldCount) return INF_STATUS_NOT_FOUND; @@ -433,13 +439,13 @@ InfpGetIntField(PINFCONTEXT Context, ULONG Index; PWCHAR Ptr;
- if (Context == NULL || Context->Line == NULL || IntegerValue == NULL) + if (Context == NULL || IntegerValue == NULL) { DPRINT("Invalid parameter\n"); return INF_STATUS_INVALID_PARAMETER; }
- CacheLine = (PINFCACHELINE)Context->Line; + CacheLine = InfpGetLineForContext(Context);
if (FieldIndex > (ULONG)CacheLine->FieldCount) { @@ -480,7 +486,7 @@ InfpGetMultiSzField(PINFCONTEXT Context, ULONG Size; PWCHAR Ptr;
- if (Context == NULL || Context->Line == NULL || FieldIndex == 0) + if (Context == NULL || FieldIndex == 0) { DPRINT("Invalid parameter\n"); return INF_STATUS_INVALID_PARAMETER; @@ -489,7 +495,7 @@ InfpGetMultiSzField(PINFCONTEXT Context, if (RequiredSize != NULL) *RequiredSize = 0;
- CacheLine = (PINFCACHELINE)Context->Line; + CacheLine = InfpGetLineForContext(Context);
if (FieldIndex > (ULONG)CacheLine->FieldCount) return INF_STATUS_INVALID_PARAMETER; @@ -548,7 +554,7 @@ InfpGetStringField(PINFCONTEXT Context, PWCHAR Ptr; SIZE_T Size;
- if (Context == NULL || Context->Line == NULL) + if (Context == NULL) { DPRINT("Invalid parameter\n"); return INF_STATUS_INVALID_PARAMETER; @@ -557,7 +563,7 @@ InfpGetStringField(PINFCONTEXT Context, if (RequiredSize != NULL) *RequiredSize = 0;
- CacheLine = (PINFCACHELINE)Context->Line; + CacheLine = InfpGetLineForContext(Context);
if (FieldIndex > (ULONG)CacheLine->FieldCount) return INF_STATUS_INVALID_PARAMETER; @@ -607,13 +613,13 @@ InfpGetData(PINFCONTEXT Context, { PINFCACHELINE CacheKey;
- if (Context == NULL || Context->Line == NULL || Data == NULL) + if (Context == NULL || Data == NULL) { DPRINT("Invalid parameter\n"); return INF_STATUS_INVALID_PARAMETER; }
- CacheKey = (PINFCACHELINE)Context->Line; + CacheKey = InfpGetLineForContext(Context); if (Key != NULL) *Key = CacheKey->Key;
@@ -642,13 +648,13 @@ InfpGetDataField(PINFCONTEXT Context, PINFCACHEFIELD CacheField; ULONG Index;
- if (Context == NULL || Context->Line == NULL || Data == NULL) + if (Context == NULL || Data == NULL) { DPRINT("Invalid parameter\n"); return INF_STATUS_INVALID_PARAMETER; }
- CacheLine = (PINFCACHELINE)Context->Line; + CacheLine = InfpGetLineForContext(Context);
if (FieldIndex > (ULONG)CacheLine->FieldCount) return INF_STATUS_INVALID_PARAMETER; diff --git a/sdk/lib/inflib/infpriv.h b/sdk/lib/inflib/infpriv.h index 1df8bb4d065..a91a1ae5a07 100644 --- a/sdk/lib/inflib/infpriv.h +++ b/sdk/lib/inflib/infpriv.h @@ -30,6 +30,7 @@ typedef struct _INFCACHELINE { struct _INFCACHELINE *Next; struct _INFCACHELINE *Prev; + UINT Id;
LONG FieldCount;
@@ -47,8 +48,10 @@ typedef struct _INFCACHESECTION
PINFCACHELINE FirstLine; PINFCACHELINE LastLine; + UINT Id;
LONG LineCount; + UINT NextLineId;
WCHAR Name[1]; } INFCACHESECTION, *PINFCACHESECTION; @@ -58,6 +61,7 @@ typedef struct _INFCACHE LANGID LanguageId; PINFCACHESECTION FirstSection; PINFCACHESECTION LastSection; + UINT NextSectionId;
PINFCACHESECTION StringsSection; } INFCACHE, *PINFCACHE; @@ -66,8 +70,8 @@ typedef struct _INFCONTEXT { PINFCACHE Inf; PINFCACHE CurrentInf; - PINFCACHESECTION Section; - PINFCACHELINE Line; + UINT Section; + UINT Line; } INFCONTEXT;
typedef int INFSTATUS; @@ -142,5 +146,11 @@ extern INFSTATUS InfpAddLineWithKey(PINFCONTEXT Context, PCWSTR Key); extern INFSTATUS InfpAddField(PINFCONTEXT Context, PCWSTR Data);
extern VOID InfpFreeContext(PINFCONTEXT Context); +PINFCACHELINE +InfpFindLineById(PINFCACHESECTION Section, UINT Id); +PINFCACHESECTION +InfpGetSectionForContext(PINFCONTEXT Context); +PINFCACHELINE +InfpGetLineForContext(PINFCONTEXT Context);
/* EOF */ diff --git a/sdk/lib/inflib/infput.c b/sdk/lib/inflib/infput.c index c049f3fdcf5..7661582659c 100644 --- a/sdk/lib/inflib/infput.c +++ b/sdk/lib/inflib/infput.c @@ -191,6 +191,7 @@ InfpFindOrAddSection(PINFCACHE Cache, PCWSTR Section, PINFCONTEXT *Context) { + PINFCACHESECTION CacheSection; DPRINT("InfpFindOrAddSection section %S\n", Section);
*Context = MALLOC(sizeof(INFCONTEXT)); @@ -201,13 +202,13 @@ InfpFindOrAddSection(PINFCACHE Cache, }
(*Context)->Inf = Cache; - (*Context)->Section = InfpFindSection(Cache, Section); - (*Context)->Line = NULL; - if (NULL == (*Context)->Section) + (*Context)->Line = 0; + CacheSection = InfpFindSection(Cache, Section); + if (NULL == CacheSection) { DPRINT("Section not found, creating it\n"); - (*Context)->Section = InfpAddSection(Cache, Section); - if (NULL == (*Context)->Section) + CacheSection = InfpAddSection(Cache, Section); + if (NULL == CacheSection) { DPRINT("Failed to create section\n"); FREE(*Context); @@ -215,26 +216,32 @@ InfpFindOrAddSection(PINFCACHE Cache, } }
+ (*Context)->Section = CacheSection->Id; return INF_STATUS_SUCCESS; }
INFSTATUS InfpAddLineWithKey(PINFCONTEXT Context, PCWSTR Key) { + PINFCACHESECTION Section; + PINFCACHELINE Line; + if (NULL == Context) { DPRINT1("Invalid parameter\n"); return INF_STATUS_INVALID_PARAMETER; }
- Context->Line = InfpAddLine(Context->Section); - if (NULL == Context->Line) + Section = InfpGetSectionForContext(Context); + Line = InfpAddLine(Section); + if (NULL == Line) { DPRINT("Failed to create line\n"); return INF_STATUS_NO_MEMORY; } + Context->Line = Line->Id;
- if (NULL != Key && NULL == InfpAddKeyToLine(Context->Line, Key)) + if (NULL != Key && NULL == InfpAddKeyToLine(Line, Key)) { DPRINT("Failed to add key\n"); return INF_STATUS_NO_MEMORY; @@ -246,13 +253,16 @@ InfpAddLineWithKey(PINFCONTEXT Context, PCWSTR Key) INFSTATUS InfpAddField(PINFCONTEXT Context, PCWSTR Data) { - if (NULL == Context || NULL == Context->Line) + PINFCACHELINE Line; + + if (NULL == Context) { DPRINT1("Invalid parameter\n"); return INF_STATUS_INVALID_PARAMETER; }
- if (NULL == InfpAddFieldToLine(Context->Line, Data)) + Line = InfpGetLineForContext(Context); + if (NULL == InfpAddFieldToLine(Line, Data)) { DPRINT("Failed to add field\n"); return INF_STATUS_NO_MEMORY;