1 /* 2 * ReactOS kernel 3 * Copyright (C) 2002 ReactOS Team 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 /* 20 * COPYRIGHT: See COPYING in the top level directory 21 * PROJECT: ReactOS text-mode setup 22 * FILE: base/setup/lib/infsupp.c 23 * PURPOSE: Interfacing with Setup* API .INF Files support functions 24 * PROGRAMMERS: Hervé Poussineau 25 * Hermes Belusca-Maito (hermes.belusca@sfr.fr) 26 */ 27 28 /* INCLUDES ******************************************************************/ 29 30 #ifndef _USETUP_PCH_ 31 #include "usetup.h" 32 #endif 33 34 #define NDEBUG 35 #include <debug.h> 36 37 /* SETUP* API COMPATIBILITY FUNCTIONS ****************************************/ 38 39 /* Functions from the INFLIB library */ 40 41 extern VOID InfCloseFile(HINF InfHandle); 42 // #define SetupCloseInfFile InfCloseFile 43 VOID 44 WINAPI 45 SetupCloseInfFile( 46 IN HINF InfHandle) 47 { 48 if (InfHandle == INVALID_HANDLE_VALUE) 49 return; 50 InfCloseFile(InfHandle); 51 } 52 53 // #define SetupFindFirstLineW InfpFindFirstLineW 54 BOOL 55 WINAPI 56 SetupFindFirstLineW( 57 IN HINF InfHandle, 58 IN PCWSTR Section, 59 IN PCWSTR Key, 60 IN OUT PINFCONTEXT Context) 61 { 62 PINFCONTEXT pContext; 63 BOOL ret; 64 65 if (InfHandle == INVALID_HANDLE_VALUE) 66 return FALSE; 67 68 ret = InfFindFirstLine(InfHandle, Section, Key, &pContext); 69 if (!ret) 70 return FALSE; 71 72 memcpy(Context, pContext, sizeof(INFCONTEXT)); 73 InfFreeContext(pContext); 74 return TRUE; 75 } 76 77 extern BOOLEAN InfFindNextLine(PINFCONTEXT ContextIn, 78 PINFCONTEXT ContextOut); 79 // #define SetupFindNextLine InfFindNextLine 80 BOOL 81 WINAPI 82 SetupFindNextLine( 83 IN PINFCONTEXT ContextIn, 84 OUT PINFCONTEXT ContextOut) 85 { 86 return !!InfFindNextLine(ContextIn, ContextOut); 87 } 88 89 extern LONG InfGetFieldCount(PINFCONTEXT Context); 90 // #define SetupGetFieldCount InfGetFieldCount 91 ULONG 92 WINAPI 93 SetupGetFieldCount( 94 IN PINFCONTEXT Context) 95 { 96 return (ULONG)InfGetFieldCount(Context); 97 } 98 99 /* 100 * This function corresponds to an undocumented but exported SetupAPI function 101 * that exists since WinNT4 and is still present in Win10. 102 * The returned string pointer is a read-only pointer to a string in the 103 * maintained INF cache, and is always in UNICODE (on NT systems). 104 */ 105 extern BOOLEAN InfGetDataField(PINFCONTEXT Context, 106 ULONG FieldIndex, 107 PWCHAR *Data); 108 PCWSTR 109 WINAPI 110 pSetupGetField( 111 IN PINFCONTEXT Context, 112 IN ULONG FieldIndex) 113 { 114 PWCHAR Data = NULL; 115 if (!InfGetDataField(Context, FieldIndex, &Data)) 116 return NULL; 117 return Data; 118 } 119 120 extern BOOLEAN InfGetBinaryField(PINFCONTEXT Context, 121 ULONG FieldIndex, 122 PUCHAR ReturnBuffer, 123 ULONG ReturnBufferSize, 124 PULONG RequiredSize); 125 // #define SetupGetBinaryField InfGetBinaryField 126 BOOL 127 WINAPI 128 SetupGetBinaryField( 129 IN PINFCONTEXT Context, 130 IN ULONG FieldIndex, 131 OUT PUCHAR ReturnBuffer, 132 IN ULONG ReturnBufferSize, 133 OUT PULONG RequiredSize) 134 { 135 return !!InfGetBinaryField(Context, 136 FieldIndex, 137 ReturnBuffer, 138 ReturnBufferSize, 139 RequiredSize); 140 } 141 142 extern BOOLEAN InfGetIntField(PINFCONTEXT Context, 143 ULONG FieldIndex, 144 INT *IntegerValue); 145 // #define SetupGetIntField InfGetIntField 146 BOOL 147 WINAPI 148 SetupGetIntField( 149 IN PINFCONTEXT Context, 150 IN ULONG FieldIndex, 151 OUT INT *IntegerValue) // PINT 152 { 153 return !!InfGetIntField(Context, FieldIndex, IntegerValue); 154 } 155 156 extern BOOLEAN InfGetMultiSzField(PINFCONTEXT Context, 157 ULONG FieldIndex, 158 PWSTR ReturnBuffer, 159 ULONG ReturnBufferSize, 160 PULONG RequiredSize); 161 // #define SetupGetMultiSzFieldW InfGetMultiSzField 162 BOOL 163 WINAPI 164 SetupGetMultiSzFieldW( 165 IN PINFCONTEXT Context, 166 IN ULONG FieldIndex, 167 OUT PWSTR ReturnBuffer, 168 IN ULONG ReturnBufferSize, 169 OUT PULONG RequiredSize) 170 { 171 return !!InfGetMultiSzField(Context, 172 FieldIndex, 173 ReturnBuffer, 174 ReturnBufferSize, 175 RequiredSize); 176 } 177 178 extern BOOLEAN InfGetStringField(PINFCONTEXT Context, 179 ULONG FieldIndex, 180 PWSTR ReturnBuffer, 181 ULONG ReturnBufferSize, 182 PULONG RequiredSize); 183 // #define SetupGetStringFieldW InfGetStringField 184 BOOL 185 WINAPI 186 SetupGetStringFieldW( 187 IN PINFCONTEXT Context, 188 IN ULONG FieldIndex, 189 OUT PWSTR ReturnBuffer, 190 IN ULONG ReturnBufferSize, 191 OUT PULONG RequiredSize) 192 { 193 return !!InfGetStringField(Context, 194 FieldIndex, 195 ReturnBuffer, 196 ReturnBufferSize, 197 RequiredSize); 198 } 199 200 /* SetupOpenInfFileW with support for a user-provided LCID */ 201 // #define SetupOpenInfFileExW InfpOpenInfFileW 202 HINF 203 WINAPI 204 SetupOpenInfFileExW( 205 IN PCWSTR FileName, 206 IN PCWSTR InfClass, 207 IN DWORD InfStyle, 208 IN LCID LocaleId, 209 OUT PUINT ErrorLine) 210 { 211 HINF hInf = NULL; 212 UNICODE_STRING FileNameU; 213 ULONG ErrorLineUL; 214 NTSTATUS Status; 215 216 RtlInitUnicodeString(&FileNameU, FileName); 217 Status = InfOpenFile(&hInf, 218 &FileNameU, 219 LANGIDFROMLCID(LocaleId), 220 &ErrorLineUL); 221 *ErrorLine = (UINT)ErrorLineUL; 222 if (!NT_SUCCESS(Status)) 223 return INVALID_HANDLE_VALUE; 224 225 return hInf; 226 } 227 228 229 /* GLOBALS *******************************************************************/ 230 231 SPINF_EXPORTS SpInfExports = 232 { 233 SetupCloseInfFile, 234 SetupFindFirstLineW, 235 SetupFindNextLine, 236 SetupGetFieldCount, 237 SetupGetBinaryField, 238 SetupGetIntField, 239 SetupGetMultiSzFieldW, 240 SetupGetStringFieldW, 241 pSetupGetField, 242 SetupOpenInfFileExW 243 }; 244 245 246 /* HELPER FUNCTIONS **********************************************************/ 247 248 HINF WINAPI 249 INF_OpenBufferedFileA( 250 IN PSTR FileBuffer, 251 IN ULONG FileSize, 252 IN PCSTR InfClass, 253 IN DWORD InfStyle, 254 IN LCID LocaleId, 255 OUT PUINT ErrorLine) 256 { 257 HINF hInf = NULL; 258 ULONG ErrorLineUL; 259 NTSTATUS Status; 260 261 Status = InfOpenBufferedFile(&hInf, 262 FileBuffer, 263 FileSize, 264 LANGIDFROMLCID(LocaleId), 265 &ErrorLineUL); 266 *ErrorLine = (UINT)ErrorLineUL; 267 if (!NT_SUCCESS(Status)) 268 return INVALID_HANDLE_VALUE; 269 270 return hInf; 271 } 272 273 /* EOF */ 274