1999-04-18 14:09:21 +02:00
|
|
|
/*
|
2003-09-25 22:33:41 +02:00
|
|
|
* Dlls load order support
|
1999-04-18 14:09:21 +02:00
|
|
|
*
|
|
|
|
* Copyright 1999 Bertho Stultiens
|
2003-09-25 22:33:41 +02:00
|
|
|
* Copyright 2003 Alexandre Julliard
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
1999-04-18 14:09:21 +02:00
|
|
|
*/
|
|
|
|
|
2001-10-14 18:18:52 +02:00
|
|
|
#include "config.h"
|
2002-08-29 01:42:34 +02:00
|
|
|
#include "wine/port.h"
|
2001-10-14 18:18:52 +02:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
1999-04-18 14:09:21 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "winbase.h"
|
2001-03-20 03:11:08 +01:00
|
|
|
#include "winerror.h"
|
2002-09-13 19:47:44 +02:00
|
|
|
#include "winternl.h"
|
2003-09-25 22:33:41 +02:00
|
|
|
#include "ntdll_misc.h"
|
2003-11-17 21:31:29 +01:00
|
|
|
#include "module.h"
|
2002-10-23 22:20:59 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2002-10-23 22:20:59 +02:00
|
|
|
#include "wine/unicode.h"
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(module);
|
1999-04-19 16:56:29 +02:00
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
#define LOADORDER_ALLOC_CLUSTER 32 /* Allocate with 32 entries at a time */
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
typedef struct module_loadorder
|
|
|
|
{
|
2003-09-27 05:50:40 +02:00
|
|
|
const WCHAR *modulename;
|
2001-03-20 03:11:08 +01:00
|
|
|
enum loadorder_type loadorder[LOADORDER_NTYPES];
|
|
|
|
} module_loadorder_t;
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
struct loadorder_list
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
int alloc;
|
|
|
|
module_loadorder_t *order;
|
|
|
|
};
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2003-09-27 05:50:40 +02:00
|
|
|
/* dll to load as builtins if not explicitly specified otherwise */
|
2001-03-20 03:11:08 +01:00
|
|
|
/* the list must remain sorted by dll name */
|
2004-01-05 22:19:22 +01:00
|
|
|
static const WCHAR default_builtins[][10] =
|
2001-03-20 03:11:08 +01:00
|
|
|
{
|
2003-09-27 05:50:40 +02:00
|
|
|
{ 'g','d','i','3','2',0 },
|
|
|
|
{ 'i','c','m','p',0 },
|
|
|
|
{ 'k','e','r','n','e','l','3','2',0 },
|
|
|
|
{ 'n','t','d','l','l',0 },
|
|
|
|
{ 'o','d','b','c','3','2',0 },
|
|
|
|
{ 't','t','y','d','r','v',0 },
|
|
|
|
{ 'u','s','e','r','3','2',0 },
|
|
|
|
{ 'w','3','2','s','k','r','n','l',0 },
|
|
|
|
{ 'w','i','n','e','d','o','s',0 },
|
|
|
|
{ 'w','i','n','e','p','s',0 },
|
|
|
|
{ 'w','i','n','m','m',0 },
|
|
|
|
{ 'w','n','a','s','p','i','3','2',0 },
|
|
|
|
{ 'w','o','w','3','2',0 },
|
|
|
|
{ 'w','s','2','_','3','2',0 },
|
|
|
|
{ 'w','s','o','c','k','3','2',0 },
|
|
|
|
{ 'x','1','1','d','r','v',0 }
|
2000-02-19 21:51:01 +01:00
|
|
|
};
|
|
|
|
|
2002-06-25 02:23:23 +02:00
|
|
|
/* default if nothing else specified */
|
|
|
|
static const enum loadorder_type default_loadorder[LOADORDER_NTYPES] =
|
|
|
|
{
|
2003-03-05 03:50:25 +01:00
|
|
|
LOADORDER_BI, LOADORDER_DLL, 0
|
2002-06-25 02:23:23 +02:00
|
|
|
};
|
|
|
|
|
2003-02-17 02:49:47 +01:00
|
|
|
/* default for modules with an explicit path */
|
|
|
|
static const enum loadorder_type default_path_loadorder[LOADORDER_NTYPES] =
|
|
|
|
{
|
2003-03-05 03:50:25 +01:00
|
|
|
LOADORDER_DLL, LOADORDER_BI, 0
|
2003-02-17 02:49:47 +01:00
|
|
|
};
|
|
|
|
|
2003-09-27 05:50:40 +02:00
|
|
|
static const WCHAR separatorsW[] = {',',' ','\t',0};
|
|
|
|
|
2003-09-25 22:33:41 +02:00
|
|
|
static int init_done;
|
|
|
|
static struct loadorder_list env_list;
|
2001-03-20 03:11:08 +01:00
|
|
|
|
|
|
|
|
1999-04-18 14:09:21 +02:00
|
|
|
/***************************************************************************
|
|
|
|
* cmp_sort_func (internal, static)
|
|
|
|
*
|
|
|
|
* Sorting and comparing function used in sort and search of loadorder
|
|
|
|
* entries.
|
|
|
|
*/
|
|
|
|
static int cmp_sort_func(const void *s1, const void *s2)
|
|
|
|
{
|
2004-06-15 02:47:00 +02:00
|
|
|
return strcmpiW(((const module_loadorder_t *)s1)->modulename, ((const module_loadorder_t *)s2)->modulename);
|
2003-09-27 05:50:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* strcmp_func
|
|
|
|
*/
|
|
|
|
static int strcmp_func(const void *s1, const void *s2)
|
|
|
|
{
|
2004-06-15 02:47:00 +02:00
|
|
|
return strcmpiW( (const WCHAR *)s1, (const WCHAR *)s2 );
|
1999-04-18 14:09:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-25 02:23:23 +02:00
|
|
|
/***************************************************************************
|
|
|
|
* get_basename
|
|
|
|
*
|
|
|
|
* Return the base name of a file name (i.e. remove the path components).
|
|
|
|
*/
|
2003-09-27 05:50:40 +02:00
|
|
|
static const WCHAR *get_basename( const WCHAR *name )
|
2002-06-25 02:23:23 +02:00
|
|
|
{
|
2003-09-27 05:50:40 +02:00
|
|
|
const WCHAR *ptr;
|
2002-06-25 02:23:23 +02:00
|
|
|
|
|
|
|
if (name[0] && name[1] == ':') name += 2; /* strip drive specification */
|
2003-09-27 05:50:40 +02:00
|
|
|
if ((ptr = strrchrW( name, '\\' ))) name = ptr + 1;
|
|
|
|
if ((ptr = strrchrW( name, '/' ))) name = ptr + 1;
|
2002-06-25 02:23:23 +02:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2003-09-27 05:50:40 +02:00
|
|
|
/***************************************************************************
|
|
|
|
* remove_dll_ext
|
|
|
|
*
|
|
|
|
* Remove extension if it is ".dll".
|
|
|
|
*/
|
|
|
|
static inline void remove_dll_ext( WCHAR *ext )
|
|
|
|
{
|
|
|
|
if (ext[0] == '.' &&
|
|
|
|
toupperW(ext[1]) == 'D' &&
|
|
|
|
toupperW(ext[2]) == 'L' &&
|
|
|
|
toupperW(ext[3]) == 'L' &&
|
|
|
|
!ext[4]) ext[0] = 0;
|
|
|
|
}
|
|
|
|
|
2002-06-25 02:23:23 +02:00
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* debugstr_loadorder
|
|
|
|
*
|
|
|
|
* Return a loadorder in printable form.
|
|
|
|
*/
|
|
|
|
static const char *debugstr_loadorder( enum loadorder_type lo[] )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char buffer[LOADORDER_NTYPES*3+1];
|
|
|
|
|
|
|
|
buffer[0] = 0;
|
|
|
|
for(i = 0; i < LOADORDER_NTYPES; i++)
|
|
|
|
{
|
|
|
|
if (lo[i] == LOADORDER_INVALID) break;
|
|
|
|
switch(lo[i])
|
|
|
|
{
|
|
|
|
case LOADORDER_DLL: strcat( buffer, "n," ); break;
|
|
|
|
case LOADORDER_BI: strcat( buffer, "b," ); break;
|
|
|
|
default: strcat( buffer, "?," ); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (buffer[0]) buffer[strlen(buffer)-1] = 0;
|
|
|
|
return debugstr_a(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-18 14:09:21 +02:00
|
|
|
/***************************************************************************
|
2003-09-25 22:33:41 +02:00
|
|
|
* append_load_order
|
1999-04-18 14:09:21 +02:00
|
|
|
*
|
2003-09-25 22:33:41 +02:00
|
|
|
* Append a load order to the list if necessary.
|
1999-04-18 14:09:21 +02:00
|
|
|
*/
|
2003-09-25 22:33:41 +02:00
|
|
|
static void append_load_order(enum loadorder_type lo[], enum loadorder_type append)
|
1999-04-18 14:09:21 +02:00
|
|
|
{
|
2003-09-25 22:33:41 +02:00
|
|
|
int i;
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2003-09-25 22:33:41 +02:00
|
|
|
for (i = 0; i < LOADORDER_NTYPES; i++)
|
|
|
|
{
|
|
|
|
if (lo[i] == LOADORDER_INVALID) /* append it here */
|
|
|
|
{
|
|
|
|
lo[i++] = append;
|
|
|
|
lo[i] = LOADORDER_INVALID;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (lo[i] == append) return; /* already in the list */
|
|
|
|
}
|
|
|
|
assert(0); /* cannot get here */
|
|
|
|
}
|
1999-04-18 14:09:21 +02:00
|
|
|
|
|
|
|
|
2003-09-25 22:33:41 +02:00
|
|
|
/***************************************************************************
|
|
|
|
* parse_load_order
|
|
|
|
*
|
|
|
|
* Parses the loadorder options from the configuration and puts it into
|
|
|
|
* a structure.
|
|
|
|
*/
|
2003-09-27 05:50:40 +02:00
|
|
|
static void parse_load_order( const WCHAR *order, enum loadorder_type lo[] )
|
2003-09-25 22:33:41 +02:00
|
|
|
{
|
|
|
|
lo[0] = LOADORDER_INVALID;
|
|
|
|
while (*order)
|
|
|
|
{
|
2003-09-27 05:50:40 +02:00
|
|
|
order += strspnW( order, separatorsW );
|
2003-09-25 22:33:41 +02:00
|
|
|
switch(*order)
|
|
|
|
{
|
|
|
|
case 'N': /* Native */
|
|
|
|
case 'n':
|
|
|
|
append_load_order( lo, LOADORDER_DLL );
|
|
|
|
break;
|
|
|
|
case 'B': /* Builtin */
|
|
|
|
case 'b':
|
|
|
|
append_load_order( lo, LOADORDER_BI );
|
|
|
|
break;
|
|
|
|
}
|
2003-09-27 05:50:40 +02:00
|
|
|
order += strcspnW( order, separatorsW );
|
2003-09-25 22:33:41 +02:00
|
|
|
}
|
1999-04-18 14:09:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
2003-09-25 22:33:41 +02:00
|
|
|
* add_load_order
|
1999-04-18 14:09:21 +02:00
|
|
|
*
|
2003-09-25 22:33:41 +02:00
|
|
|
* Adds an entry in the list of environment overrides.
|
1999-04-18 14:09:21 +02:00
|
|
|
*/
|
2003-09-25 22:33:41 +02:00
|
|
|
static void add_load_order( const module_loadorder_t *plo )
|
1999-04-18 14:09:21 +02:00
|
|
|
{
|
2003-09-25 22:33:41 +02:00
|
|
|
int i;
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2003-09-25 22:33:41 +02:00
|
|
|
for(i = 0; i < env_list.count; i++)
|
|
|
|
{
|
|
|
|
if(!cmp_sort_func(plo, &env_list.order[i] ))
|
|
|
|
{
|
|
|
|
/* replace existing option */
|
|
|
|
memcpy( env_list.order[i].loadorder, plo->loadorder, sizeof(plo->loadorder));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2003-09-25 22:33:41 +02:00
|
|
|
if (i >= env_list.alloc)
|
|
|
|
{
|
|
|
|
/* No space in current array, make it larger */
|
|
|
|
env_list.alloc += LOADORDER_ALLOC_CLUSTER;
|
|
|
|
if (env_list.order)
|
|
|
|
env_list.order = RtlReAllocateHeap(GetProcessHeap(), 0, env_list.order,
|
|
|
|
env_list.alloc * sizeof(module_loadorder_t));
|
|
|
|
else
|
|
|
|
env_list.order = RtlAllocateHeap(GetProcessHeap(), 0,
|
|
|
|
env_list.alloc * sizeof(module_loadorder_t));
|
|
|
|
if(!env_list.order)
|
|
|
|
{
|
|
|
|
MESSAGE("Virtual memory exhausted\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
memcpy(env_list.order[i].loadorder, plo->loadorder, sizeof(plo->loadorder));
|
2003-09-27 05:50:40 +02:00
|
|
|
env_list.order[i].modulename = plo->modulename;
|
2003-09-25 22:33:41 +02:00
|
|
|
env_list.count++;
|
1999-04-18 14:09:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
2003-09-25 22:33:41 +02:00
|
|
|
* add_load_order_set
|
1999-04-18 14:09:21 +02:00
|
|
|
*
|
2001-03-20 03:11:08 +01:00
|
|
|
* Adds a set of entries in the list of command-line overrides from the key parameter.
|
1999-04-18 14:09:21 +02:00
|
|
|
*/
|
2003-09-27 05:50:40 +02:00
|
|
|
static void add_load_order_set( WCHAR *entry )
|
1999-04-18 14:09:21 +02:00
|
|
|
{
|
2003-09-25 22:33:41 +02:00
|
|
|
module_loadorder_t ldo;
|
2003-09-27 05:50:40 +02:00
|
|
|
WCHAR *end = strchrW( entry, '=' );
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2003-09-25 22:33:41 +02:00
|
|
|
if (!end) return;
|
|
|
|
*end++ = 0;
|
|
|
|
parse_load_order( end, ldo.loadorder );
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2003-09-25 22:33:41 +02:00
|
|
|
while (*entry)
|
|
|
|
{
|
2003-09-27 05:50:40 +02:00
|
|
|
entry += strspnW( entry, separatorsW );
|
|
|
|
end = entry + strcspnW( entry, separatorsW );
|
2003-09-25 22:33:41 +02:00
|
|
|
if (*end) *end++ = 0;
|
|
|
|
if (*entry)
|
2003-09-27 05:50:40 +02:00
|
|
|
{
|
|
|
|
WCHAR *ext = strrchrW(entry, '.');
|
|
|
|
if (ext) remove_dll_ext( ext );
|
2003-09-25 22:33:41 +02:00
|
|
|
ldo.modulename = entry;
|
|
|
|
add_load_order( &ldo );
|
|
|
|
entry = end;
|
2003-09-27 05:50:40 +02:00
|
|
|
}
|
2003-09-25 22:33:41 +02:00
|
|
|
}
|
1999-04-18 14:09:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
2003-09-25 22:33:41 +02:00
|
|
|
* init_load_order
|
1999-04-18 14:09:21 +02:00
|
|
|
*/
|
2003-09-25 22:33:41 +02:00
|
|
|
static void init_load_order(void)
|
1999-04-18 14:09:21 +02:00
|
|
|
{
|
2003-09-25 22:33:41 +02:00
|
|
|
const char *order = getenv( "WINEDLLOVERRIDES" );
|
2003-09-27 05:50:40 +02:00
|
|
|
UNICODE_STRING strW;
|
|
|
|
WCHAR *entry, *next;
|
2001-03-20 03:11:08 +01:00
|
|
|
|
2003-09-25 22:33:41 +02:00
|
|
|
init_done = 1;
|
|
|
|
if (!order) return;
|
2001-03-20 03:11:08 +01:00
|
|
|
|
2003-09-25 22:33:41 +02:00
|
|
|
if (!strcmp( order, "help" ))
|
|
|
|
{
|
|
|
|
MESSAGE( "Syntax:\n"
|
|
|
|
" WINEDLLOVERRIDES=\"entry;entry;entry...\"\n"
|
|
|
|
" where each entry is of the form:\n"
|
|
|
|
" module[,module...]={native|builtin}[,{b|n}]\n"
|
|
|
|
"\n"
|
|
|
|
" Only the first letter of the override (native or builtin)\n"
|
|
|
|
" is significant.\n\n"
|
|
|
|
"Example:\n"
|
2004-01-05 22:19:22 +01:00
|
|
|
" WINEDLLOVERRIDES=\"comdlg32=n,b;shell32,shlwapi=b\"\n" );
|
2003-09-25 22:33:41 +02:00
|
|
|
exit(0);
|
|
|
|
}
|
2001-03-20 03:11:08 +01:00
|
|
|
|
2003-09-27 05:50:40 +02:00
|
|
|
RtlCreateUnicodeStringFromAsciiz( &strW, order );
|
|
|
|
entry = strW.Buffer;
|
2003-09-25 22:33:41 +02:00
|
|
|
while (*entry)
|
|
|
|
{
|
|
|
|
while (*entry && *entry == ';') entry++;
|
|
|
|
if (!*entry) break;
|
2003-09-27 05:50:40 +02:00
|
|
|
next = strchrW( entry, ';' );
|
2003-09-25 22:33:41 +02:00
|
|
|
if (next) *next++ = 0;
|
2003-09-27 05:50:40 +02:00
|
|
|
else next = entry + strlenW(entry);
|
2003-09-25 22:33:41 +02:00
|
|
|
add_load_order_set( entry );
|
|
|
|
entry = next;
|
|
|
|
}
|
2001-03-20 03:11:08 +01:00
|
|
|
|
|
|
|
/* sort the array for quick lookup */
|
2003-09-25 22:33:41 +02:00
|
|
|
if (env_list.count)
|
|
|
|
qsort(env_list.order, env_list.count, sizeof(env_list.order[0]), cmp_sort_func);
|
2003-09-27 05:50:40 +02:00
|
|
|
|
|
|
|
/* Note: we don't free the Unicode string because the
|
|
|
|
* stored module names point inside it */
|
1999-04-18 14:09:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
/***************************************************************************
|
2003-09-27 05:50:40 +02:00
|
|
|
* get_env_load_order
|
2001-03-20 03:11:08 +01:00
|
|
|
*
|
2003-09-27 05:50:40 +02:00
|
|
|
* Get the load order for a given module from the WINEDLLOVERRIDES environment variable.
|
2001-03-20 03:11:08 +01:00
|
|
|
*/
|
2003-09-27 05:50:40 +02:00
|
|
|
static inline BOOL get_env_load_order( const WCHAR *module, enum loadorder_type lo[] )
|
1999-04-18 14:09:21 +02:00
|
|
|
{
|
2001-08-11 00:29:21 +02:00
|
|
|
module_loadorder_t tmp, *res = NULL;
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
tmp.modulename = module;
|
2001-08-11 00:29:21 +02:00
|
|
|
/* some bsearch implementations (Solaris) are buggy when the number of items is 0 */
|
2003-09-27 05:50:40 +02:00
|
|
|
if (env_list.count &&
|
|
|
|
(res = bsearch(&tmp, env_list.order, env_list.count, sizeof(env_list.order[0]), cmp_sort_func)))
|
2001-03-20 03:11:08 +01:00
|
|
|
memcpy( lo, res->loadorder, sizeof(res->loadorder) );
|
|
|
|
return (res != NULL);
|
|
|
|
}
|
1999-04-18 14:09:21 +02:00
|
|
|
|
|
|
|
|
2003-09-27 05:50:40 +02:00
|
|
|
/***************************************************************************
|
|
|
|
* get_default_load_order
|
|
|
|
*
|
|
|
|
* Get the load order for a given module from the default list.
|
|
|
|
*/
|
|
|
|
static inline BOOL get_default_load_order( const WCHAR *module, enum loadorder_type lo[] )
|
|
|
|
{
|
|
|
|
const int count = sizeof(default_builtins) / sizeof(default_builtins[0]);
|
|
|
|
if (!bsearch( module, default_builtins, count, sizeof(default_builtins[0]), strcmp_func ))
|
|
|
|
return FALSE;
|
|
|
|
lo[0] = LOADORDER_BI;
|
|
|
|
lo[1] = LOADORDER_INVALID;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
/***************************************************************************
|
2002-06-25 02:23:23 +02:00
|
|
|
* open_app_key
|
2001-03-20 03:11:08 +01:00
|
|
|
*
|
2002-06-25 02:23:23 +02:00
|
|
|
* Open the registry key to the app-specific DllOverrides list.
|
2001-03-20 03:11:08 +01:00
|
|
|
*/
|
2005-06-17 15:58:33 +02:00
|
|
|
static HANDLE open_app_key( const WCHAR *app_name, const WCHAR *module )
|
2001-03-20 03:11:08 +01:00
|
|
|
{
|
2002-09-13 19:47:44 +02:00
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING nameW;
|
2005-06-17 15:58:33 +02:00
|
|
|
HANDLE root, hkey;
|
2003-09-25 22:33:41 +02:00
|
|
|
WCHAR *str;
|
2005-06-16 18:13:11 +02:00
|
|
|
static const WCHAR AppDefaultsW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\',
|
2003-09-25 22:33:41 +02:00
|
|
|
'A','p','p','D','e','f','a','u','l','t','s','\\',0};
|
|
|
|
static const WCHAR DllOverridesW[] = {'\\','D','l','l','O','v','e','r','r','i','d','e','s',0};
|
2001-03-20 03:11:08 +01:00
|
|
|
|
2003-09-25 22:33:41 +02:00
|
|
|
str = RtlAllocateHeap( GetProcessHeap(), 0,
|
|
|
|
sizeof(AppDefaultsW) + sizeof(DllOverridesW) +
|
|
|
|
strlenW(app_name) * sizeof(WCHAR) );
|
|
|
|
if (!str) return 0;
|
|
|
|
strcpyW( str, AppDefaultsW );
|
|
|
|
strcatW( str, app_name );
|
|
|
|
strcatW( str, DllOverridesW );
|
2001-03-20 03:11:08 +01:00
|
|
|
|
2003-09-27 05:50:40 +02:00
|
|
|
TRACE( "searching %s in %s\n", debugstr_w(module), debugstr_w(str) );
|
2001-03-20 03:11:08 +01:00
|
|
|
|
2005-06-16 18:13:11 +02:00
|
|
|
RtlOpenCurrentUser( KEY_ALL_ACCESS, &root );
|
2002-09-13 19:47:44 +02:00
|
|
|
attr.Length = sizeof(attr);
|
2005-06-16 18:13:11 +02:00
|
|
|
attr.RootDirectory = root;
|
2002-09-13 19:47:44 +02:00
|
|
|
attr.ObjectName = &nameW;
|
|
|
|
attr.Attributes = 0;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
2003-09-25 22:33:41 +02:00
|
|
|
RtlInitUnicodeString( &nameW, str );
|
|
|
|
|
2005-06-16 18:13:11 +02:00
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\DllOverrides */
|
2003-09-25 22:33:41 +02:00
|
|
|
if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) hkey = 0;
|
2005-06-16 18:13:11 +02:00
|
|
|
NtClose( root );
|
2003-09-25 22:33:41 +02:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, str );
|
|
|
|
return hkey;
|
2001-03-20 03:11:08 +01:00
|
|
|
}
|
1999-04-25 11:15:25 +02:00
|
|
|
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
/***************************************************************************
|
2002-06-25 02:23:23 +02:00
|
|
|
* get_registry_value
|
2001-03-20 03:11:08 +01:00
|
|
|
*
|
2002-06-25 02:23:23 +02:00
|
|
|
* Load the registry loadorder value for a given module.
|
2001-03-20 03:11:08 +01:00
|
|
|
*/
|
2005-06-17 15:58:33 +02:00
|
|
|
static BOOL get_registry_value( HANDLE hkey, const WCHAR *module, enum loadorder_type lo[] )
|
2001-03-20 03:11:08 +01:00
|
|
|
{
|
2002-09-13 19:47:44 +02:00
|
|
|
UNICODE_STRING valueW;
|
2001-03-20 03:11:08 +01:00
|
|
|
char buffer[80];
|
2002-09-13 19:47:44 +02:00
|
|
|
DWORD count;
|
|
|
|
BOOL ret;
|
|
|
|
|
2003-09-27 05:50:40 +02:00
|
|
|
RtlInitUnicodeString( &valueW, module );
|
2002-09-13 19:47:44 +02:00
|
|
|
|
|
|
|
if ((ret = !NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation,
|
|
|
|
buffer, sizeof(buffer), &count )))
|
|
|
|
{
|
|
|
|
int i, n = 0;
|
|
|
|
WCHAR *str = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)buffer)->Data;
|
2001-03-20 03:11:08 +01:00
|
|
|
|
2002-09-13 19:47:44 +02:00
|
|
|
while (*str)
|
|
|
|
{
|
|
|
|
enum loadorder_type type = LOADORDER_INVALID;
|
|
|
|
|
|
|
|
while (*str == ',' || isspaceW(*str)) str++;
|
|
|
|
if (!*str) break;
|
|
|
|
|
|
|
|
switch(tolowerW(*str))
|
|
|
|
{
|
|
|
|
case 'n': type = LOADORDER_DLL; break;
|
|
|
|
case 'b': type = LOADORDER_BI; break;
|
2003-04-27 02:40:23 +02:00
|
|
|
case 's': break; /* no longer supported, ignore */
|
2002-09-13 19:47:44 +02:00
|
|
|
case 0: break; /* end of string */
|
|
|
|
default:
|
|
|
|
ERR("Invalid load order module-type %s, ignored\n", debugstr_w(str));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (type != LOADORDER_INVALID)
|
|
|
|
{
|
|
|
|
for (i = 0; i < n; i++) if (lo[i] == type) break; /* already specified */
|
|
|
|
if (i == n) lo[n++] = type;
|
|
|
|
}
|
|
|
|
while (*str && *str != ',' && !isspaceW(*str)) str++;
|
|
|
|
}
|
|
|
|
lo[n] = LOADORDER_INVALID;
|
|
|
|
}
|
|
|
|
return ret;
|
2001-03-20 03:11:08 +01:00
|
|
|
}
|
1999-04-18 14:09:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
2003-09-27 05:50:40 +02:00
|
|
|
* MODULE_GetLoadOrderW (internal)
|
1999-04-18 14:09:21 +02:00
|
|
|
*
|
2005-05-27 21:26:34 +02:00
|
|
|
* Return the loadorder of a module.
|
|
|
|
* The system directory and '.dll' extension is stripped from the path.
|
1999-04-18 14:09:21 +02:00
|
|
|
*/
|
2003-09-27 05:50:40 +02:00
|
|
|
void MODULE_GetLoadOrderW( enum loadorder_type loadorder[], const WCHAR *app_name,
|
2003-11-25 02:03:04 +01:00
|
|
|
const WCHAR *path )
|
1999-04-18 14:09:21 +02:00
|
|
|
{
|
2005-06-16 18:13:11 +02:00
|
|
|
static const WCHAR DllOverridesW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\',
|
2002-09-13 19:47:44 +02:00
|
|
|
'D','l','l','O','v','e','r','r','i','d','e','s',0};
|
|
|
|
|
2005-06-17 15:58:33 +02:00
|
|
|
static HANDLE std_key = (HANDLE)-1; /* key to standard section, cached */
|
2003-11-25 02:03:04 +01:00
|
|
|
|
2005-06-17 15:58:33 +02:00
|
|
|
HANDLE app_key = 0;
|
2003-09-27 05:50:40 +02:00
|
|
|
WCHAR *module, *basename;
|
2003-11-25 02:03:04 +01:00
|
|
|
UNICODE_STRING path_str;
|
2002-06-25 02:23:23 +02:00
|
|
|
int len;
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2003-09-25 22:33:41 +02:00
|
|
|
if (!init_done) init_load_order();
|
|
|
|
|
2003-09-27 05:50:40 +02:00
|
|
|
TRACE("looking for %s\n", debugstr_w(path));
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2002-06-25 02:23:23 +02:00
|
|
|
loadorder[0] = LOADORDER_INVALID; /* in case something bad happens below */
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2003-08-24 01:07:10 +02:00
|
|
|
/* Strip path information if the module resides in the system directory
|
|
|
|
*/
|
2003-11-25 02:03:04 +01:00
|
|
|
RtlInitUnicodeString( &path_str, path );
|
2004-07-16 00:07:21 +02:00
|
|
|
if (RtlPrefixUnicodeString( &system_dir, &path_str, TRUE ))
|
2002-06-25 02:23:23 +02:00
|
|
|
{
|
2004-07-16 00:07:21 +02:00
|
|
|
const WCHAR *p = path + system_dir.Length / sizeof(WCHAR);
|
2003-11-25 02:03:04 +01:00
|
|
|
while (*p == '\\' || *p == '/') p++;
|
|
|
|
if (!strchrW( p, '\\' ) && !strchrW( p, '/' )) path = p;
|
2002-06-25 02:23:23 +02:00
|
|
|
}
|
|
|
|
|
2003-09-27 05:50:40 +02:00
|
|
|
if (!(len = strlenW(path))) return;
|
|
|
|
if (!(module = RtlAllocateHeap( GetProcessHeap(), 0, (len + 2) * sizeof(WCHAR) ))) return;
|
|
|
|
strcpyW( module+1, path ); /* reserve module[0] for the wildcard char */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-09-27 05:50:40 +02:00
|
|
|
if (len >= 4) remove_dll_ext( module + 1 + len - 4 );
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-09-25 22:33:41 +02:00
|
|
|
/* check environment variable first */
|
2003-09-27 05:50:40 +02:00
|
|
|
if (get_env_load_order( module+1, loadorder ))
|
2002-06-25 02:23:23 +02:00
|
|
|
{
|
2003-09-25 22:33:41 +02:00
|
|
|
TRACE( "got environment %s for %s\n",
|
2003-09-27 05:50:40 +02:00
|
|
|
debugstr_loadorder(loadorder), debugstr_w(path) );
|
2002-06-25 02:23:23 +02:00
|
|
|
goto done;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-06-25 02:23:23 +02:00
|
|
|
/* then explicit module name in AppDefaults */
|
2003-09-25 22:33:41 +02:00
|
|
|
if (app_name)
|
2002-06-25 02:23:23 +02:00
|
|
|
{
|
2003-09-25 22:33:41 +02:00
|
|
|
app_key = open_app_key( app_name, module+1 );
|
|
|
|
if (app_key && get_registry_value( app_key, module+1, loadorder ))
|
|
|
|
{
|
|
|
|
TRACE( "got app defaults %s for %s\n",
|
2003-09-27 05:50:40 +02:00
|
|
|
debugstr_loadorder(loadorder), debugstr_w(path) );
|
2003-09-25 22:33:41 +02:00
|
|
|
goto done;
|
|
|
|
}
|
2002-06-25 02:23:23 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-06-25 02:23:23 +02:00
|
|
|
/* then explicit module name in standard section */
|
2005-06-17 15:58:33 +02:00
|
|
|
if (std_key == (HANDLE)-1)
|
2002-09-13 19:47:44 +02:00
|
|
|
{
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING nameW;
|
2005-06-17 15:58:33 +02:00
|
|
|
HANDLE root;
|
2002-09-13 19:47:44 +02:00
|
|
|
|
2005-06-16 18:13:11 +02:00
|
|
|
RtlOpenCurrentUser( KEY_ALL_ACCESS, &root );
|
2002-09-13 19:47:44 +02:00
|
|
|
attr.Length = sizeof(attr);
|
2005-06-16 18:13:11 +02:00
|
|
|
attr.RootDirectory = root;
|
2002-09-13 19:47:44 +02:00
|
|
|
attr.ObjectName = &nameW;
|
|
|
|
attr.Attributes = 0;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
RtlInitUnicodeString( &nameW, DllOverridesW );
|
|
|
|
|
2005-06-16 18:13:11 +02:00
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\DllOverrides */
|
2002-09-13 19:47:44 +02:00
|
|
|
if (NtOpenKey( &std_key, KEY_ALL_ACCESS, &attr )) std_key = 0;
|
2005-06-16 18:13:11 +02:00
|
|
|
NtClose( root );
|
2002-09-13 19:47:44 +02:00
|
|
|
}
|
2002-06-25 02:23:23 +02:00
|
|
|
|
|
|
|
if (std_key && get_registry_value( std_key, module+1, loadorder ))
|
|
|
|
{
|
|
|
|
TRACE( "got standard entry %s for %s\n",
|
2003-09-27 05:50:40 +02:00
|
|
|
debugstr_loadorder(loadorder), debugstr_w(path) );
|
2002-06-25 02:23:23 +02:00
|
|
|
goto done;
|
|
|
|
}
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2004-09-24 02:21:02 +02:00
|
|
|
/* then module basename preceded by '*' in environment */
|
2003-09-27 05:50:40 +02:00
|
|
|
basename = (WCHAR *)get_basename( module+1 );
|
2002-06-25 02:23:23 +02:00
|
|
|
basename[-1] = '*';
|
2004-09-24 02:21:02 +02:00
|
|
|
if (get_env_load_order( basename-1, loadorder ))
|
|
|
|
{
|
|
|
|
TRACE( "got environment basename %s for %s\n",
|
|
|
|
debugstr_loadorder(loadorder), debugstr_w(path) );
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* then module basename preceded by '*' in AppDefaults */
|
2002-06-25 02:23:23 +02:00
|
|
|
if (app_key && get_registry_value( app_key, basename-1, loadorder ))
|
|
|
|
{
|
|
|
|
TRACE( "got app defaults basename %s for %s\n",
|
2003-09-27 05:50:40 +02:00
|
|
|
debugstr_loadorder(loadorder), debugstr_w(path) );
|
2002-06-25 02:23:23 +02:00
|
|
|
goto done;
|
|
|
|
}
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2002-06-25 02:23:23 +02:00
|
|
|
/* then module name preceded by '*' in standard section */
|
|
|
|
if (std_key && get_registry_value( std_key, basename-1, loadorder ))
|
|
|
|
{
|
|
|
|
TRACE( "got standard base name %s for %s\n",
|
2003-09-27 05:50:40 +02:00
|
|
|
debugstr_loadorder(loadorder), debugstr_w(path) );
|
2002-06-25 02:23:23 +02:00
|
|
|
goto done;
|
|
|
|
}
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2004-02-24 02:26:31 +01:00
|
|
|
if (basename == module+1) /* module doesn't contain a path */
|
2002-06-25 02:23:23 +02:00
|
|
|
{
|
2003-09-27 05:50:40 +02:00
|
|
|
static const WCHAR wildcardW[] = {'*',0};
|
|
|
|
|
2004-02-24 02:26:31 +01:00
|
|
|
/* then base name matching compiled-in defaults */
|
|
|
|
if (get_default_load_order( basename, loadorder ))
|
|
|
|
{
|
|
|
|
TRACE( "got compiled-in default %s for %s\n",
|
|
|
|
debugstr_loadorder(loadorder), debugstr_w(path) );
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2002-06-25 02:23:23 +02:00
|
|
|
/* then wildcard entry in AppDefaults (only if no explicit path) */
|
2003-09-27 05:50:40 +02:00
|
|
|
if (app_key && get_registry_value( app_key, wildcardW, loadorder ))
|
2001-03-21 21:33:11 +01:00
|
|
|
{
|
2002-06-25 02:23:23 +02:00
|
|
|
TRACE( "got app defaults wildcard %s for %s\n",
|
2003-09-27 05:50:40 +02:00
|
|
|
debugstr_loadorder(loadorder), debugstr_w(path) );
|
2002-06-25 02:23:23 +02:00
|
|
|
goto done;
|
2001-03-21 21:33:11 +01:00
|
|
|
}
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2002-06-25 02:23:23 +02:00
|
|
|
/* then wildcard entry in standard section (only if no explicit path) */
|
2003-09-27 05:50:40 +02:00
|
|
|
if (std_key && get_registry_value( std_key, wildcardW, loadorder ))
|
2001-03-21 21:33:11 +01:00
|
|
|
{
|
2002-06-25 02:23:23 +02:00
|
|
|
TRACE( "got standard wildcard %s for %s\n",
|
2003-09-27 05:50:40 +02:00
|
|
|
debugstr_loadorder(loadorder), debugstr_w(path) );
|
2002-06-25 02:23:23 +02:00
|
|
|
goto done;
|
2001-03-21 21:33:11 +01:00
|
|
|
}
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2003-02-17 02:49:47 +01:00
|
|
|
/* and last the hard-coded default */
|
|
|
|
memcpy( loadorder, default_loadorder, sizeof(default_loadorder) );
|
|
|
|
TRACE( "got hardcoded default %s for %s\n",
|
2003-09-27 05:50:40 +02:00
|
|
|
debugstr_loadorder(loadorder), debugstr_w(path) );
|
2003-02-17 02:49:47 +01:00
|
|
|
}
|
|
|
|
else /* module contains an explicit path */
|
|
|
|
{
|
2004-02-24 02:26:31 +01:00
|
|
|
/* then base name without '*' in AppDefaults */
|
|
|
|
if (app_key && get_registry_value( app_key, basename, loadorder ))
|
|
|
|
{
|
|
|
|
TRACE( "got basename app defaults %s for %s\n",
|
|
|
|
debugstr_loadorder(loadorder), debugstr_w(path) );
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* then base name without '*' in standard section */
|
|
|
|
if (std_key && get_registry_value( std_key, basename, loadorder ))
|
|
|
|
{
|
|
|
|
TRACE( "got basename standard entry %s for %s\n",
|
|
|
|
debugstr_loadorder(loadorder), debugstr_w(path) );
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* then base name matching compiled-in defaults */
|
|
|
|
if (get_default_load_order( basename, loadorder ))
|
|
|
|
{
|
|
|
|
TRACE( "got compiled-in default %s for %s\n",
|
|
|
|
debugstr_loadorder(loadorder), debugstr_w(path) );
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* and last the hard-coded default */
|
2003-02-17 02:49:47 +01:00
|
|
|
memcpy( loadorder, default_path_loadorder, sizeof(default_path_loadorder) );
|
|
|
|
TRACE( "got hardcoded path default %s for %s\n",
|
2003-09-27 05:50:40 +02:00
|
|
|
debugstr_loadorder(loadorder), debugstr_w(path) );
|
2003-02-17 02:49:47 +01:00
|
|
|
}
|
2001-03-20 03:11:08 +01:00
|
|
|
|
|
|
|
done:
|
2002-09-13 19:47:44 +02:00
|
|
|
if (app_key) NtClose( app_key );
|
2003-09-25 22:33:41 +02:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, module );
|
2001-03-20 03:11:08 +01:00
|
|
|
}
|