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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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"
|
2002-09-13 19:47:44 +02:00
|
|
|
#include "winternl.h"
|
2003-09-25 22:33:41 +02:00
|
|
|
#include "ntdll_misc.h"
|
2002-10-23 22:20:59 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.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;
|
2006-02-22 16:30:05 +01:00
|
|
|
enum loadorder loadorder;
|
2001-03-20 03:11:08 +01:00
|
|
|
} 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
|
|
|
static const WCHAR separatorsW[] = {',',' ','\t',0};
|
|
|
|
|
2013-10-29 21:54:12 +01:00
|
|
|
static BOOL init_done;
|
2003-09-25 22:33:41 +02:00
|
|
|
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)
|
|
|
|
{
|
2020-03-27 13:38:09 +01:00
|
|
|
return wcsicmp(((const module_loadorder_t *)s1)->modulename, ((const module_loadorder_t *)s2)->modulename);
|
2003-09-27 05:50:40 +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 */
|
2020-03-31 11:47:47 +02:00
|
|
|
if ((ptr = wcsrchr( name, '\\' ))) name = ptr + 1;
|
|
|
|
if ((ptr = wcsrchr( 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".
|
|
|
|
*/
|
2020-03-30 12:05:16 +02:00
|
|
|
static inline void remove_dll_ext( WCHAR *name )
|
2003-09-27 05:50:40 +02:00
|
|
|
{
|
2020-03-30 12:05:16 +02:00
|
|
|
static const WCHAR dllW[] = {'.','d','l','l',0};
|
2020-03-31 11:47:47 +02:00
|
|
|
WCHAR *p = wcsrchr( name, '.' );
|
2020-03-30 12:05:16 +02:00
|
|
|
|
|
|
|
if (p && !wcsicmp( p, dllW )) *p = 0;
|
2003-09-27 05:50:40 +02:00
|
|
|
}
|
|
|
|
|
2002-06-25 02:23:23 +02:00
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* debugstr_loadorder
|
|
|
|
*
|
|
|
|
* Return a loadorder in printable form.
|
|
|
|
*/
|
2006-02-22 16:30:05 +01:00
|
|
|
static const char *debugstr_loadorder( enum loadorder lo )
|
1999-04-18 14:09:21 +02:00
|
|
|
{
|
2006-02-22 16:30:05 +01:00
|
|
|
switch(lo)
|
2003-09-25 22:33:41 +02:00
|
|
|
{
|
2006-02-22 16:30:05 +01:00
|
|
|
case LO_DISABLED: return "";
|
|
|
|
case LO_NATIVE: return "n";
|
|
|
|
case LO_BUILTIN: return "b";
|
|
|
|
case LO_NATIVE_BUILTIN: return "n,b";
|
|
|
|
case LO_BUILTIN_NATIVE: return "b,n";
|
|
|
|
case LO_DEFAULT: return "default";
|
|
|
|
default: return "??";
|
2003-09-25 22:33:41 +02:00
|
|
|
}
|
|
|
|
}
|
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.
|
|
|
|
*/
|
2006-02-22 16:30:05 +01:00
|
|
|
static enum loadorder parse_load_order( const WCHAR *order )
|
2003-09-25 22:33:41 +02:00
|
|
|
{
|
2006-02-22 16:30:05 +01:00
|
|
|
enum loadorder ret = LO_DISABLED;
|
|
|
|
|
2003-09-25 22:33:41 +02:00
|
|
|
while (*order)
|
|
|
|
{
|
2020-03-31 11:53:34 +02:00
|
|
|
order += wcsspn( order, separatorsW );
|
2003-09-25 22:33:41 +02:00
|
|
|
switch(*order)
|
|
|
|
{
|
2006-02-22 16:30:05 +01:00
|
|
|
case 'N': /* native */
|
2003-09-25 22:33:41 +02:00
|
|
|
case 'n':
|
2006-02-22 16:30:05 +01:00
|
|
|
if (ret == LO_DISABLED) ret = LO_NATIVE;
|
|
|
|
else if (ret == LO_BUILTIN) return LO_BUILTIN_NATIVE;
|
2003-09-25 22:33:41 +02:00
|
|
|
break;
|
2006-02-22 16:30:05 +01:00
|
|
|
case 'B': /* builtin */
|
2003-09-25 22:33:41 +02:00
|
|
|
case 'b':
|
2006-02-22 16:30:05 +01:00
|
|
|
if (ret == LO_DISABLED) ret = LO_BUILTIN;
|
|
|
|
else if (ret == LO_NATIVE) return LO_NATIVE_BUILTIN;
|
2003-09-25 22:33:41 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-03-31 11:52:07 +02:00
|
|
|
order += wcscspn( order, separatorsW );
|
2003-09-25 22:33:41 +02:00
|
|
|
}
|
2006-02-22 16:30:05 +01:00
|
|
|
return ret;
|
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 */
|
2006-02-22 16:30:05 +01:00
|
|
|
env_list.order[i].loadorder = plo->loadorder;
|
2003-09-25 22:33:41 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2006-02-22 16:30:05 +01:00
|
|
|
env_list.order[i].loadorder = 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;
|
2020-03-31 11:43:50 +02:00
|
|
|
WCHAR *end = wcschr( entry, '=' );
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2003-09-25 22:33:41 +02:00
|
|
|
if (!end) return;
|
|
|
|
*end++ = 0;
|
2006-02-22 16:30:05 +01:00
|
|
|
ldo.loadorder = parse_load_order( end );
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2003-09-25 22:33:41 +02:00
|
|
|
while (*entry)
|
|
|
|
{
|
2020-03-31 11:53:34 +02:00
|
|
|
entry += wcsspn( entry, separatorsW );
|
2020-03-31 11:52:07 +02:00
|
|
|
end = entry + wcscspn( entry, separatorsW );
|
2003-09-25 22:33:41 +02:00
|
|
|
if (*end) *end++ = 0;
|
|
|
|
if (*entry)
|
2003-09-27 05:50:40 +02:00
|
|
|
{
|
2020-03-30 12:05:16 +02:00
|
|
|
remove_dll_ext( entry );
|
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
|
|
|
|
2013-10-29 21:54:12 +01:00
|
|
|
init_done = TRUE;
|
2003-09-25 22:33:41 +02:00
|
|
|
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)
|
|
|
|
{
|
2017-10-12 15:14:53 +02:00
|
|
|
while (*entry == ';') entry++;
|
2003-09-25 22:33:41 +02:00
|
|
|
if (!*entry) break;
|
2020-03-31 11:43:50 +02:00
|
|
|
next = wcschr( entry, ';' );
|
2003-09-25 22:33:41 +02:00
|
|
|
if (next) *next++ = 0;
|
2020-03-31 11:50:16 +02:00
|
|
|
else next = entry + wcslen(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
|
|
|
*/
|
2006-02-22 16:30:05 +01:00
|
|
|
static inline enum loadorder get_env_load_order( const WCHAR *module )
|
1999-04-18 14:09:21 +02:00
|
|
|
{
|
2006-02-22 16:30:05 +01:00
|
|
|
module_loadorder_t tmp, *res;
|
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)))
|
2006-02-22 16:30:05 +01:00
|
|
|
return res->loadorder;
|
|
|
|
return LO_INVALID;
|
2001-03-20 03:11:08 +01:00
|
|
|
}
|
1999-04-18 14:09:21 +02:00
|
|
|
|
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
/***************************************************************************
|
2006-02-04 17:06:41 +01:00
|
|
|
* get_standard_key
|
2001-03-20 03:11:08 +01:00
|
|
|
*
|
2006-02-04 17:06:41 +01:00
|
|
|
* Return a handle to the standard DllOverrides registry section.
|
2001-03-20 03:11:08 +01:00
|
|
|
*/
|
2006-02-04 17:06:41 +01:00
|
|
|
static HANDLE get_standard_key(void)
|
|
|
|
{
|
|
|
|
static const WCHAR DllOverridesW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\',
|
|
|
|
'D','l','l','O','v','e','r','r','i','d','e','s',0};
|
|
|
|
static HANDLE std_key = (HANDLE)-1;
|
|
|
|
|
|
|
|
if (std_key == (HANDLE)-1)
|
|
|
|
{
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING nameW;
|
|
|
|
HANDLE root;
|
|
|
|
|
|
|
|
RtlOpenCurrentUser( KEY_ALL_ACCESS, &root );
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = root;
|
|
|
|
attr.ObjectName = &nameW;
|
|
|
|
attr.Attributes = 0;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
RtlInitUnicodeString( &nameW, DllOverridesW );
|
|
|
|
|
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\DllOverrides */
|
|
|
|
if (NtOpenKey( &std_key, KEY_ALL_ACCESS, &attr )) std_key = 0;
|
|
|
|
NtClose( root );
|
|
|
|
}
|
|
|
|
return std_key;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* get_app_key
|
|
|
|
*
|
|
|
|
* Get the registry key for the app-specific DllOverrides list.
|
|
|
|
*/
|
|
|
|
static HANDLE get_app_key( const WCHAR *app_name )
|
2001-03-20 03:11:08 +01:00
|
|
|
{
|
2002-09-13 19:47:44 +02:00
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING nameW;
|
2006-02-04 17:06:41 +01:00
|
|
|
HANDLE root;
|
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};
|
2006-02-04 17:06:41 +01:00
|
|
|
static HANDLE app_key = (HANDLE)-1;
|
|
|
|
|
|
|
|
if (app_key != (HANDLE)-1) return app_key;
|
2001-03-20 03:11:08 +01:00
|
|
|
|
2003-09-25 22:33:41 +02:00
|
|
|
str = RtlAllocateHeap( GetProcessHeap(), 0,
|
|
|
|
sizeof(AppDefaultsW) + sizeof(DllOverridesW) +
|
2020-03-31 11:50:16 +02:00
|
|
|
wcslen(app_name) * sizeof(WCHAR) );
|
2003-09-25 22:33:41 +02:00
|
|
|
if (!str) return 0;
|
2020-03-31 11:37:58 +02:00
|
|
|
wcscpy( str, AppDefaultsW );
|
2020-03-31 11:41:22 +02:00
|
|
|
wcscat( str, app_name );
|
|
|
|
wcscat( str, DllOverridesW );
|
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 */
|
2006-02-04 17:06:41 +01:00
|
|
|
if (NtOpenKey( &app_key, KEY_ALL_ACCESS, &attr )) app_key = 0;
|
2005-06-16 18:13:11 +02:00
|
|
|
NtClose( root );
|
2003-09-25 22:33:41 +02:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, str );
|
2006-02-04 17:06:41 +01:00
|
|
|
return app_key;
|
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
|
|
|
*/
|
2006-02-22 16:30:05 +01:00
|
|
|
static enum loadorder get_registry_value( HANDLE hkey, const WCHAR *module )
|
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;
|
|
|
|
|
2003-09-27 05:50:40 +02:00
|
|
|
RtlInitUnicodeString( &valueW, module );
|
2002-09-13 19:47:44 +02:00
|
|
|
|
2008-04-22 23:05:03 +02:00
|
|
|
if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation,
|
|
|
|
buffer, sizeof(buffer), &count ))
|
2002-09-13 19:47:44 +02:00
|
|
|
{
|
|
|
|
WCHAR *str = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)buffer)->Data;
|
2006-02-22 16:30:05 +01:00
|
|
|
return parse_load_order( str );
|
2002-09-13 19:47:44 +02:00
|
|
|
}
|
2006-02-22 16:30:05 +01:00
|
|
|
return LO_INVALID;
|
2001-03-20 03:11:08 +01:00
|
|
|
}
|
1999-04-18 14:09:21 +02:00
|
|
|
|
|
|
|
|
2006-02-04 17:06:41 +01:00
|
|
|
/***************************************************************************
|
|
|
|
* get_load_order_value
|
|
|
|
*
|
|
|
|
* Get the load order for the exact specified module string, looking in:
|
|
|
|
* 1. The WINEDLLOVERRIDES environment variable
|
|
|
|
* 2. The per-application DllOverrides key
|
|
|
|
* 3. The standard DllOverrides key
|
|
|
|
*/
|
2006-02-22 16:30:05 +01:00
|
|
|
static enum loadorder get_load_order_value( HANDLE std_key, HANDLE app_key, const WCHAR *module )
|
2006-02-04 17:06:41 +01:00
|
|
|
{
|
2006-02-22 16:30:05 +01:00
|
|
|
enum loadorder ret;
|
|
|
|
|
|
|
|
if ((ret = get_env_load_order( module )) != LO_INVALID)
|
2006-02-04 17:06:41 +01:00
|
|
|
{
|
2006-02-22 16:30:05 +01:00
|
|
|
TRACE( "got environment %s for %s\n", debugstr_loadorder(ret), debugstr_w(module) );
|
|
|
|
return ret;
|
2006-02-04 17:06:41 +01:00
|
|
|
}
|
|
|
|
|
2006-02-22 16:30:05 +01:00
|
|
|
if (app_key && ((ret = get_registry_value( app_key, module )) != LO_INVALID))
|
2006-02-04 17:06:41 +01:00
|
|
|
{
|
2006-02-22 16:30:05 +01:00
|
|
|
TRACE( "got app defaults %s for %s\n", debugstr_loadorder(ret), debugstr_w(module) );
|
|
|
|
return ret;
|
2006-02-04 17:06:41 +01:00
|
|
|
}
|
|
|
|
|
2006-02-22 16:30:05 +01:00
|
|
|
if (std_key && ((ret = get_registry_value( std_key, module )) != LO_INVALID))
|
2006-02-04 17:06:41 +01:00
|
|
|
{
|
2006-02-22 16:30:05 +01:00
|
|
|
TRACE( "got standard key %s for %s\n", debugstr_loadorder(ret), debugstr_w(module) );
|
|
|
|
return ret;
|
2006-02-04 17:06:41 +01:00
|
|
|
}
|
2006-02-22 16:30:05 +01:00
|
|
|
|
|
|
|
return ret;
|
2006-02-04 17:06:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-18 14:09:21 +02:00
|
|
|
/***************************************************************************
|
2006-02-22 16:30:05 +01:00
|
|
|
* get_load_order (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
|
|
|
*/
|
2019-02-08 22:07:54 +01:00
|
|
|
enum loadorder get_load_order( const WCHAR *app_name, const UNICODE_STRING *nt_name )
|
1999-04-18 14:09:21 +02:00
|
|
|
{
|
2019-02-08 22:07:54 +01:00
|
|
|
static const WCHAR nt_prefixW[] = {'\\','?','?','\\',0};
|
2006-02-22 16:30:05 +01:00
|
|
|
enum loadorder ret = LO_INVALID;
|
2006-02-04 17:06:41 +01:00
|
|
|
HANDLE std_key, app_key = 0;
|
2019-02-08 22:07:54 +01:00
|
|
|
const WCHAR *path = nt_name->Buffer;
|
2003-09-27 05:50:40 +02:00
|
|
|
WCHAR *module, *basename;
|
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();
|
2006-02-04 17:06:41 +01:00
|
|
|
std_key = get_standard_key();
|
|
|
|
if (app_name) app_key = get_app_key( app_name );
|
2020-03-31 11:55:51 +02:00
|
|
|
if (!wcsncmp( path, nt_prefixW, 4 )) path += 4;
|
2003-09-25 22:33:41 +02:00
|
|
|
|
2003-09-27 05:50:40 +02:00
|
|
|
TRACE("looking for %s\n", debugstr_w(path));
|
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
|
|
|
|
*/
|
2020-03-31 11:50:16 +02:00
|
|
|
if (!wcsnicmp( system_dir, path, wcslen( system_dir )))
|
2002-06-25 02:23:23 +02:00
|
|
|
{
|
2020-03-31 11:50:16 +02:00
|
|
|
const WCHAR *p = path + wcslen( system_dir );
|
2003-11-25 02:03:04 +01:00
|
|
|
while (*p == '\\' || *p == '/') p++;
|
2020-03-31 11:43:50 +02:00
|
|
|
if (!wcschr( p, '\\' ) && !wcschr( p, '/' )) path = p;
|
2002-06-25 02:23:23 +02:00
|
|
|
}
|
|
|
|
|
2020-03-31 11:50:16 +02:00
|
|
|
if (!(len = wcslen(path))) return ret;
|
2006-02-22 16:30:05 +01:00
|
|
|
if (!(module = RtlAllocateHeap( GetProcessHeap(), 0, (len + 2) * sizeof(WCHAR) ))) return ret;
|
2020-03-31 11:37:58 +02:00
|
|
|
wcscpy( module+1, path ); /* reserve module[0] for the wildcard char */
|
2020-03-30 12:05:16 +02:00
|
|
|
remove_dll_ext( module + 1 );
|
2006-02-04 17:06:41 +01:00
|
|
|
basename = (WCHAR *)get_basename( module+1 );
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-02-04 17:06:41 +01:00
|
|
|
/* first explicit module name */
|
2006-02-22 16:30:05 +01:00
|
|
|
if ((ret = get_load_order_value( std_key, app_key, module+1 )) != LO_INVALID)
|
2002-06-25 02:23:23 +02:00
|
|
|
goto done;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-02-04 17:06:41 +01:00
|
|
|
/* then module basename preceded by '*' */
|
2002-06-25 02:23:23 +02:00
|
|
|
basename[-1] = '*';
|
2006-02-22 16:30:05 +01:00
|
|
|
if ((ret = get_load_order_value( std_key, app_key, basename-1 )) != LO_INVALID)
|
2004-09-24 02:21:02 +02:00
|
|
|
goto done;
|
|
|
|
|
2006-02-04 17:06:41 +01:00
|
|
|
/* then module basename without '*' (only if explicit path) */
|
2006-02-22 16:30:05 +01:00
|
|
|
if (basename != module+1 && ((ret = get_load_order_value( std_key, app_key, basename )) != LO_INVALID))
|
2002-06-25 02:23:23 +02:00
|
|
|
goto done;
|
1999-04-18 14:09:21 +02:00
|
|
|
|
2006-08-15 19:48:08 +02:00
|
|
|
/* if loading the main exe with an explicit path, try native first */
|
|
|
|
if (!app_name && basename != module+1)
|
|
|
|
{
|
|
|
|
ret = LO_NATIVE_BUILTIN;
|
|
|
|
TRACE( "got main exe default %s for %s\n", debugstr_loadorder(ret), debugstr_w(path) );
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2005-07-07 20:26:11 +02:00
|
|
|
/* and last the hard-coded default */
|
2006-02-22 16:30:05 +01:00
|
|
|
ret = LO_DEFAULT;
|
2006-08-15 19:48:08 +02:00
|
|
|
TRACE( "got hardcoded %s for %s\n", debugstr_loadorder(ret), debugstr_w(path) );
|
2005-07-07 20:26:11 +02:00
|
|
|
|
2001-03-20 03:11:08 +01:00
|
|
|
done:
|
2003-09-25 22:33:41 +02:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, module );
|
2006-02-22 16:30:05 +01:00
|
|
|
return ret;
|
2001-03-20 03:11:08 +01:00
|
|
|
}
|