setupapi: Support arbitrary wildcards in fake dlls creation.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2021-03-18 12:48:45 +01:00
parent 00b9c975d4
commit 5d3d73f803
2 changed files with 32 additions and 54 deletions

View File

@ -466,7 +466,7 @@ done:
} }
/* create the fake dll destination file */ /* create the fake dll destination file */
static HANDLE create_dest_file( const WCHAR *name ) static HANDLE create_dest_file( const WCHAR *name, BOOL delete )
{ {
/* first check for an existing file */ /* first check for an existing file */
HANDLE h = CreateFileW( name, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL ); HANDLE h = CreateFileW( name, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL );
@ -478,11 +478,17 @@ static HANDLE create_dest_file( const WCHAR *name )
CloseHandle( h ); CloseHandle( h );
return 0; return 0;
} }
if (delete)
{
CloseHandle( h );
DeleteFileW( name );
return INVALID_HANDLE_VALUE;
}
/* truncate the file */ /* truncate the file */
SetFilePointer( h, 0, NULL, FILE_BEGIN ); SetFilePointer( h, 0, NULL, FILE_BEGIN );
SetEndOfFile( h ); SetEndOfFile( h );
} }
else else if (!delete)
{ {
if (GetLastError() == ERROR_PATH_NOT_FOUND) create_directories( name ); if (GetLastError() == ERROR_PATH_NOT_FOUND) create_directories( name );
@ -872,7 +878,7 @@ static void register_fake_dll( const WCHAR *name, const void *data, size_t size,
} }
/* copy a fake dll file to the dest directory */ /* copy a fake dll file to the dest directory */
static int install_fake_dll( WCHAR *dest, WCHAR *file, const WCHAR *ext, BOOL expect_builtin, struct list *delay_copy ) static int install_fake_dll( WCHAR *dest, WCHAR *file, const WCHAR *ext, BOOL delete, BOOL expect_builtin, struct list *delay_copy )
{ {
int ret; int ret;
SIZE_T size; SIZE_T size;
@ -897,7 +903,7 @@ static int install_fake_dll( WCHAR *dest, WCHAR *file, const WCHAR *ext, BOOL ex
if (ret != -1) if (ret != -1)
{ {
HANDLE h = create_dest_file( dest ); HANDLE h = create_dest_file( dest, delete );
if (h && h != INVALID_HANDLE_VALUE) if (h && h != INVALID_HANDLE_VALUE)
{ {
@ -935,7 +941,7 @@ static void delay_copy_files( struct list *delay_copy )
continue; continue;
} }
h = create_dest_file( copy->dest ); h = create_dest_file( copy->dest, FALSE );
if (h && h != INVALID_HANDLE_VALUE) if (h && h != INVALID_HANDLE_VALUE)
{ {
ret = (WriteFile( h, data, size, &written, NULL ) && written == size); ret = (WriteFile( h, data, size, &written, NULL ) && written == size);
@ -948,7 +954,8 @@ static void delay_copy_files( struct list *delay_copy )
} }
/* find and install all fake dlls in a given lib directory */ /* find and install all fake dlls in a given lib directory */
static void install_lib_dir( WCHAR *dest, WCHAR *file, const WCHAR *default_ext, BOOL expect_builtin ) static void install_lib_dir( WCHAR *dest, WCHAR *file, const WCHAR *wildcard,
const WCHAR *default_ext, BOOL delete, BOOL expect_builtin )
{ {
WCHAR *name; WCHAR *name;
intptr_t handle; intptr_t handle;
@ -958,7 +965,7 @@ static void install_lib_dir( WCHAR *dest, WCHAR *file, const WCHAR *default_ext,
file[1] = '\\'; /* change \??\ to \\?\ */ file[1] = '\\'; /* change \??\ to \\?\ */
name = file + lstrlenW(file); name = file + lstrlenW(file);
*name++ = '\\'; *name++ = '\\';
lstrcpyW( name, L"*" ); lstrcpyW( name, wildcard );
if ((handle = _wfindfirst( file, &data )) == -1) return; if ((handle = _wfindfirst( file, &data )) == -1) return;
do do
@ -973,14 +980,14 @@ static void install_lib_dir( WCHAR *dest, WCHAR *file, const WCHAR *default_ext,
lstrcatW( name, data.name ); lstrcatW( name, data.name );
if (wcschr( data.name, '.' )) /* module possibly already has an extension */ if (wcschr( data.name, '.' )) /* module possibly already has an extension */
{ {
if (install_fake_dll( dest, file, NULL, expect_builtin, &delay_copy )) continue; if (install_fake_dll( dest, file, NULL, delete, expect_builtin, &delay_copy )) continue;
if (install_fake_dll( dest, file, L".fake", FALSE, &delay_copy )) continue; if (install_fake_dll( dest, file, L".fake", delete, FALSE, &delay_copy )) continue;
} }
lstrcatW( name, default_ext ); lstrcatW( name, default_ext );
if (install_fake_dll( dest, file, NULL, expect_builtin, &delay_copy )) continue; if (install_fake_dll( dest, file, NULL, delete, expect_builtin, &delay_copy )) continue;
if (install_fake_dll( dest, file, L".fake", FALSE, &delay_copy )) continue; if (install_fake_dll( dest, file, L".fake", delete, FALSE, &delay_copy )) continue;
} }
else install_fake_dll( dest, file, NULL, expect_builtin, &delay_copy ); else install_fake_dll( dest, file, NULL, delete, expect_builtin, &delay_copy );
} }
while (!_wfindnext( handle, &data )); while (!_wfindnext( handle, &data ));
_findclose( handle ); _findclose( handle );
@ -989,12 +996,12 @@ static void install_lib_dir( WCHAR *dest, WCHAR *file, const WCHAR *default_ext,
} }
/* create fake dlls in dirname for all the files we can find */ /* create fake dlls in dirname for all the files we can find */
static BOOL create_wildcard_dlls( const WCHAR *dirname ) static BOOL create_wildcard_dlls( const WCHAR *dirname, const WCHAR *wildcard, BOOL delete )
{ {
const WCHAR *build_dir = _wgetenv( L"WINEBUILDDIR" ); const WCHAR *build_dir = _wgetenv( L"WINEBUILDDIR" );
const WCHAR *path; const WCHAR *path;
unsigned int i, maxlen = 0; unsigned int i, maxlen = 0;
WCHAR *file, *dest; WCHAR *file, *dest, *p;
if (build_dir) maxlen = lstrlenW(build_dir) + ARRAY_SIZE(L"\\programs") + 1; if (build_dir) maxlen = lstrlenW(build_dir) + ARRAY_SIZE(L"\\programs") + 1;
for (i = 0; (path = enum_load_path(i)); i++) maxlen = max( maxlen, lstrlenW(path) ); for (i = 0; (path = enum_load_path(i)); i++) maxlen = max( maxlen, lstrlenW(path) );
@ -1007,24 +1014,24 @@ static BOOL create_wildcard_dlls( const WCHAR *dirname )
return FALSE; return FALSE;
} }
lstrcpyW( dest, dirname ); lstrcpyW( dest, dirname );
dest[lstrlenW(dest) - 1] = 0; /* remove wildcard */ if ((p = wcsrchr( dest, '\\' ))) p[1] = 0; /* remove wildcard */
if (build_dir) if (build_dir)
{ {
lstrcpyW( file, build_dir ); lstrcpyW( file, build_dir );
lstrcatW( file, L"\\dlls" ); lstrcatW( file, L"\\dlls" );
install_lib_dir( dest, file, L".dll", TRUE ); install_lib_dir( dest, file, wildcard, L".dll", delete, TRUE );
lstrcpyW( file, build_dir ); lstrcpyW( file, build_dir );
lstrcatW( file, L"\\programs" ); lstrcatW( file, L"\\programs" );
install_lib_dir( dest, file, L".exe", TRUE ); install_lib_dir( dest, file, wildcard, L".exe", delete, TRUE );
} }
for (i = 0; (path = enum_load_path( i )); i++) for (i = 0; (path = enum_load_path( i )); i++)
{ {
lstrcpyW( file, path ); lstrcpyW( file, path );
install_lib_dir( dest, file, NULL, TRUE ); install_lib_dir( dest, file, wildcard, NULL, delete, TRUE );
lstrcpyW( file, path ); lstrcpyW( file, path );
lstrcatW( file, L"\\fakedlls" ); lstrcatW( file, L"\\fakedlls" );
install_lib_dir( dest, file, NULL, FALSE ); install_lib_dir( dest, file, wildcard, NULL, delete, FALSE );
} }
HeapFree( GetProcessHeap(), 0, file ); HeapFree( GetProcessHeap(), 0, file );
HeapFree( GetProcessHeap(), 0, dest ); HeapFree( GetProcessHeap(), 0, dest );
@ -1042,6 +1049,7 @@ BOOL create_fake_dll( const WCHAR *name, const WCHAR *source )
SIZE_T size; SIZE_T size;
const WCHAR *filename; const WCHAR *filename;
void *buffer; void *buffer;
BOOL delete = !wcscmp( source, L"-" ); /* '-' source means delete the file */
if (!(filename = wcsrchr( name, '\\' ))) filename = name; if (!(filename = wcsrchr( name, '\\' ))) filename = name;
else filename++; else filename++;
@ -1052,20 +1060,14 @@ BOOL create_fake_dll( const WCHAR *name, const WCHAR *source )
create_directories( name ); create_directories( name );
return TRUE; return TRUE;
} }
if (filename[0] == '*' && !filename[1]) return create_wildcard_dlls( name ); if (wcspbrk( filename, L"*?" )) return create_wildcard_dlls( name, filename, delete );
add_handled_dll( filename ); add_handled_dll( filename );
if (!(h = create_dest_file( name ))) return TRUE; /* not a fake dll */ if (!(h = create_dest_file( name, delete ))) return TRUE; /* not a fake dll */
if (h == INVALID_HANDLE_VALUE) return FALSE; if (h == INVALID_HANDLE_VALUE) return FALSE;
if (source[0] == '-' && !source[1]) if ((buffer = load_fake_dll( source, &size )))
{
/* '-' source means delete the file */
TRACE( "deleting %s\n", debugstr_w(name) );
ret = FALSE;
}
else if ((buffer = load_fake_dll( source, &size )))
{ {
DWORD written; DWORD written;

View File

@ -2630,19 +2630,6 @@ HKLM,%CurrentVersion%\Telephony\Country List\998,"SameAreaRule",,"G"
10,syswow64,stdole2.tlb 10,syswow64,stdole2.tlb
11,,iexplore.exe 11,,iexplore.exe
11,,winetest.exe,- 11,,winetest.exe,-
12,,fltmgr.sys,-
12,,hidclass.sys,-
12,,http.sys,-
12,,ksecdd.sys,-
12,,mountmgr.sys,-
12,,ndis.sys,-
12,,netio.sys,-
12,,scsiport.sys,-
12,,tdi.sys,-
12,,usbd.sys,-
12,,winebus.sys,-
12,,winehid.sys,-
12,,wineusb.sys,-
; skip .NET fake dlls in Wine Mono package ; skip .NET fake dlls in Wine Mono package
11,,aspnet_regiis.exe,- 11,,aspnet_regiis.exe,-
11,,ngen.exe,- 11,,ngen.exe,-
@ -2665,6 +2652,7 @@ HKLM,%CurrentVersion%\Telephony\Country List\998,"SameAreaRule",,"G"
16427,System\OLE DB,oledb32.dll 16427,System\OLE DB,oledb32.dll
16427,System\OLE DB,msdaps.dll 16427,System\OLE DB,msdaps.dll
16427,System\ADO,msado15.dll 16427,System\ADO,msado15.dll
12,,*.sys,-
11,,* 11,,*
[FakeDlls] [FakeDlls]
@ -2685,19 +2673,6 @@ HKLM,%CurrentVersion%\Telephony\Country List\998,"SameAreaRule",,"G"
11,,iexplore.exe 11,,iexplore.exe
11,,notepad.exe 11,,notepad.exe
11,,winetest.exe,- 11,,winetest.exe,-
12,,fltmgr.sys
12,,hidclass.sys
12,,http.sys
12,,ksecdd.sys
12,,mountmgr.sys
12,,ndis.sys
12,,netio.sys
12,,scsiport.sys
12,,tdi.sys
12,,usbd.sys
12,,winebus.sys
12,,winehid.sys
12,,wineusb.sys
; skip .NET fake dlls in Wine Mono package ; skip .NET fake dlls in Wine Mono package
11,,aspnet_regiis.exe,- 11,,aspnet_regiis.exe,-
11,,ngen.exe,- 11,,ngen.exe,-
@ -2732,6 +2707,7 @@ HKLM,%CurrentVersion%\Telephony\Country List\998,"SameAreaRule",,"G"
16427,System\OLE DB,oledb32.dll 16427,System\OLE DB,oledb32.dll
16427,System\OLE DB,msdaps.dll 16427,System\OLE DB,msdaps.dll
16427,System\ADO,msado15.dll 16427,System\ADO,msado15.dll
12,,*.sys,-
11,,* 11,,*
[SystemIni] [SystemIni]