ReactOS 0.4.15-dev-6057-gd708c79
infrosgen.c File Reference
#include "inflib.h"
#include "infros.h"
#include <debug.h>
Include dependency graph for infrosgen.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static VOID CheckHeap (VOID)
 
VOID InfSetHeap (PVOID Heap)
 
NTSTATUS InfOpenBufferedFile (PHINF InfHandle, PVOID Buffer, ULONG BufferSize, LANGID LanguageId, PULONG ErrorLine)
 
NTSTATUS InfOpenFile (PHINF InfHandle, PUNICODE_STRING FileName, LANGID LanguageId, PULONG ErrorLine)
 
VOID InfCloseFile (HINF InfHandle)
 

Variables

static int InfpHeapRefCount
 
PVOID InfpHeap
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file infrosgen.c.

Function Documentation

◆ CheckHeap()

static VOID CheckHeap ( VOID  )
static

Definition at line 22 of file infrosgen.c.

23{
24 if (NULL == InfpHeap)
25 {
27 }
28 if (0 <= InfpHeapRefCount)
29 {
31 }
32}
#define NULL
Definition: types.h:112
static int InfpHeapRefCount
Definition: infrosgen.c:19
PVOID InfpHeap
Definition: infrosgen.c:37
NTSYSAPI PVOID NTAPI RtlCreateHeap(IN ULONG Flags, IN PVOID HeapBase OPTIONAL, IN ULONG ReserveSize OPTIONAL, IN ULONG CommitSize OPTIONAL, IN PVOID Lock OPTIONAL, IN PRTL_HEAP_PARAMETERS Parameters OPTIONAL)
#define HEAP_GROWABLE
Definition: nt_native.h:1693

Referenced by InfOpenBufferedFile(), and InfOpenFile().

◆ InfCloseFile()

VOID InfCloseFile ( HINF  InfHandle)

Definition at line 334 of file infrosgen.c.

335{
337
338 Cache = (PINFCACHE)InfHandle;
339
340 if (Cache == NULL)
341 {
342 return;
343 }
344
345 while (Cache->FirstSection != NULL)
346 {
347 Cache->FirstSection = InfpFreeSection(Cache->FirstSection);
348 }
349 Cache->LastSection = NULL;
350
351 FREE(Cache);
352
353 if (0 < InfpHeapRefCount)
354 {
356 if (0 == InfpHeapRefCount)
357 {
359 InfpHeap = NULL;
360 }
361 }
362}
#define FREE(ptr, size)
Definition: auth_des.c:64
PINFCACHESECTION InfpFreeSection(PINFCACHESECTION Section)
Definition: infcore.c:119
struct _INFCACHE * PINFCACHE
NTSYSAPI PVOID NTAPI RtlDestroyHeap(IN PVOID HeapHandle)
Definition: fatfs.h:173

Referenced by LoadReactOSSetup(), and SetupCloseInfFile().

◆ InfOpenBufferedFile()

NTSTATUS InfOpenBufferedFile ( PHINF  InfHandle,
PVOID  Buffer,
ULONG  BufferSize,
LANGID  LanguageId,
PULONG  ErrorLine 
)

Definition at line 51 of file infrosgen.c.

56{
59 PCHAR FileBuffer;
60 ULONG FileBufferSize;
61
62 CheckHeap();
63
64 *InfHandle = NULL;
65 *ErrorLine = (ULONG)-1;
66
67 /* Allocate file buffer */
68 FileBufferSize = BufferSize + 2;
69 FileBuffer = MALLOC(FileBufferSize);
70 if (FileBuffer == NULL)
71 {
72 DPRINT1("MALLOC() failed\n");
74 }
75
76 MEMCPY(FileBuffer, Buffer, BufferSize);
77
78 /* Append string terminator */
79 FileBuffer[BufferSize] = 0;
80 FileBuffer[BufferSize + 1] = 0;
81
82 /* Allocate infcache header */
83 Cache = (PINFCACHE)MALLOC(sizeof(INFCACHE));
84 if (Cache == NULL)
85 {
86 DPRINT("MALLOC() failed\n");
87 FREE(FileBuffer);
89 }
90
91 /* Initialize inicache header */
93 sizeof(INFCACHE));
94
95 Cache->LanguageId = LanguageId;
96
97 /* Parse the inf buffer */
98 if (!RtlIsTextUnicode(FileBuffer, FileBufferSize, NULL))
99 {
100// static const BYTE utf8_bom[3] = { 0xef, 0xbb, 0xbf };
101 WCHAR *new_buff;
102// UINT codepage = CP_ACP;
103 UINT offset = 0;
104
105// if (BufferSize > sizeof(utf8_bom) && !memcmp(FileBuffer, utf8_bom, sizeof(utf8_bom) ))
106// {
107// codepage = CP_UTF8;
108// offset = sizeof(utf8_bom);
109// }
110
111 new_buff = MALLOC(FileBufferSize * sizeof(WCHAR));
112 if (new_buff != NULL)
113 {
114 ULONG len;
116 FileBufferSize * sizeof(WCHAR),
117 &len,
118 (char *)FileBuffer + offset,
119 FileBufferSize - offset);
120
122 new_buff,
123 new_buff + len / sizeof(WCHAR),
124 ErrorLine);
125 FREE(new_buff);
126 }
127 else
129 }
130 else
131 {
132 WCHAR *new_buff = (WCHAR *)FileBuffer;
133 /* UCS-16 files should start with the Unicode BOM; we should skip it */
134 if (*new_buff == 0xfeff)
135 {
136 new_buff++;
137 FileBufferSize -= sizeof(WCHAR);
138 }
140 new_buff,
141 (WCHAR*)((char*)new_buff + FileBufferSize),
142 ErrorLine);
143 }
144
145 if (!INF_SUCCESS(Status))
146 {
147 FREE(Cache);
148 Cache = NULL;
149 }
150
151 /* Free file buffer */
152 FREE(FileBuffer);
153
154 *InfHandle = (HINF)Cache;
155
156 return(Status);
157}
#define DPRINT1
Definition: precomp.h:8
#define MALLOC(Size)
Definition: builddep.h:73
#define INF_SUCCESS(x)
Definition: builddep.h:82
#define ZEROMEMORY(Area, Size)
Definition: builddep.h:74
Definition: bufpool.h:45
#define BufferSize
Definition: mmc.h:75
Status
Definition: gdiplustypes.h:25
GLenum GLsizei len
Definition: glext.h:6722
GLintptr offset
Definition: glext.h:5920
static BOOLEAN InfpParseBuffer(PINFCACHE file, PCCHAR buffer, PCCHAR end, PULONG error_line)
Definition: inffile.c:878
int INFSTATUS
Definition: infpriv.h:77
#define INF_STATUS_INSUFFICIENT_RESOURCES
Definition: infpriv.h:15
static VOID CheckHeap(VOID)
Definition: infrosgen.c:22
PVOID HINF
Definition: infsupp.h:21
#define MEMCPY(DST, SRC, BYTES)
Definition: macros.h:231
unsigned int UINT
Definition: ndis.h:50
NTSYSAPI BOOLEAN NTAPI RtlIsTextUnicode(_In_ CONST VOID *Buffer, _In_ INT Size, _Inout_opt_ INT *Flags)
_Use_decl_annotations_ NTSTATUS NTAPI RtlMultiByteToUnicodeN(_Out_ PWCH UnicodeString, _In_ ULONG UnicodeSize, _Out_opt_ PULONG ResultSize, _In_ PCCH MbString, _In_ ULONG MbSize)
Definition: nlsboot.c:62
#define DPRINT
Definition: sndvol32.h:71
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by INF_OpenBufferedFileA().

◆ InfOpenFile()

NTSTATUS InfOpenFile ( PHINF  InfHandle,
PUNICODE_STRING  FileName,
LANGID  LanguageId,
PULONG  ErrorLine 
)

Definition at line 161 of file infrosgen.c.

165{
171 PCHAR FileBuffer;
173 ULONG FileBufferLength;
176
177 CheckHeap();
178
179 *InfHandle = NULL;
180 *ErrorLine = (ULONG)-1;
181
182 /* Open the inf file */
184 FileName,
185 0,
186 NULL,
187 NULL);
188
195 if (!INF_SUCCESS(Status))
196 {
197 DPRINT("NtOpenFile() failed (Status %lx)\n", Status);
198 return(Status);
199 }
200
201 DPRINT("NtOpenFile() successful\n");
202
203 /* Query file size */
206 &FileInfo,
209 if (!INF_SUCCESS(Status))
210 {
211 DPRINT("NtQueryInformationFile() failed (Status %lx)\n", Status);
213 return(Status);
214 }
215
216 FileLength = FileInfo.EndOfFile.u.LowPart;
217
218 DPRINT("File size: %lu\n", FileLength);
219
220 /* Allocate file buffer */
221 FileBufferLength = FileLength + 2;
222 FileBuffer = MALLOC(FileBufferLength);
223 if (FileBuffer == NULL)
224 {
225 DPRINT1("MALLOC() failed\n");
228 }
229
230 /* Read file */
231 FileOffset.QuadPart = 0ULL;
233 NULL,
234 NULL,
235 NULL,
237 FileBuffer,
239 &FileOffset,
240 NULL);
241
242 /* Append string terminator */
243 FileBuffer[FileLength] = 0;
244 FileBuffer[FileLength + 1] = 0;
245
247
248 if (!INF_SUCCESS(Status))
249 {
250 DPRINT("NtReadFile() failed (Status %lx)\n", Status);
251 FREE(FileBuffer);
252 return(Status);
253 }
254
255 /* Allocate infcache header */
256 Cache = (PINFCACHE)MALLOC(sizeof(INFCACHE));
257 if (Cache == NULL)
258 {
259 DPRINT("MALLOC() failed\n");
260 FREE(FileBuffer);
262 }
263
264 /* Initialize inicache header */
266 sizeof(INFCACHE));
267
268 Cache->LanguageId = LanguageId;
269
270 /* Parse the inf buffer */
271 if (!RtlIsTextUnicode(FileBuffer, FileBufferLength, NULL))
272 {
273// static const BYTE utf8_bom[3] = { 0xef, 0xbb, 0xbf };
274 WCHAR *new_buff;
275// UINT codepage = CP_ACP;
276 UINT offset = 0;
277
278// if (FileLength > sizeof(utf8_bom) && !memcmp(FileBuffer, utf8_bom, sizeof(utf8_bom) ))
279// {
280// codepage = CP_UTF8;
281// offset = sizeof(utf8_bom);
282// }
283
284 new_buff = MALLOC(FileBufferLength * sizeof(WCHAR));
285 if (new_buff != NULL)
286 {
287 ULONG len;
289 FileBufferLength * sizeof(WCHAR),
290 &len,
291 (char *)FileBuffer + offset,
292 FileBufferLength - offset);
293
295 new_buff,
296 new_buff + len / sizeof(WCHAR),
297 ErrorLine);
298 FREE(new_buff);
299 }
300 else
302 }
303 else
304 {
305 WCHAR *new_buff = (WCHAR *)FileBuffer;
306 /* UCS-16 files should start with the Unicode BOM; we should skip it */
307 if (*new_buff == 0xfeff)
308 {
309 new_buff++;
310 FileBufferLength -= sizeof(WCHAR);
311 }
313 new_buff,
314 (WCHAR*)((char*)new_buff + FileBufferLength),
315 ErrorLine);
316 }
317
318 if (!INF_SUCCESS(Status))
319 {
320 FREE(Cache);
321 Cache = NULL;
322 }
323
324 /* Free file buffer */
325 FREE(FileBuffer);
326
327 *InfHandle = (HINF)Cache;
328
329 return(Status);
330}
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:160
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define GENERIC_READ
Definition: compat.h:135
#define FILE_SHARE_READ
Definition: compat.h:136
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define ULL(a, b)
Definition: format_msg.c:27
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_Out_ PNDIS_HANDLE _Out_ PUINT FileLength
Definition: ndis.h:3228
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3952
#define SYNCHRONIZE
Definition: nt_native.h:61
NTSYSAPI NTSTATUS NTAPI NtQueryInformationFile(IN HANDLE hFile, OUT PIO_STATUS_BLOCK pIoStatusBlock, OUT PVOID FileInformationBuffer, IN ULONG FileInformationBufferLength, IN FILE_INFORMATION_CLASS FileInfoClass)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define FileStandardInformation
Definition: propsheet.cpp:61
NTSTATUS NTAPI NtReadFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)

◆ InfSetHeap()

VOID InfSetHeap ( PVOID  Heap)

Definition at line 40 of file infrosgen.c.

41{
42 if (NULL == InfpHeap)
43 {
44 InfpHeap = Heap;
46 }
47}

Referenced by RunUSetup().

Variable Documentation

◆ InfpHeap

PVOID InfpHeap

Definition at line 37 of file infrosgen.c.

Referenced by CheckHeap(), InfCloseFile(), and InfSetHeap().

◆ InfpHeapRefCount

int InfpHeapRefCount
static

Definition at line 19 of file infrosgen.c.

Referenced by CheckHeap(), InfCloseFile(), and InfSetHeap().