2004-04-06 00:21:27 +02:00
|
|
|
/*
|
|
|
|
* File path.c - managing path in debugging environments
|
|
|
|
*
|
2008-08-29 21:50:46 +02:00
|
|
|
* Copyright (C) 2004,2008, Eric Pouech
|
2004-04-06 00:21:27 +02: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
|
2004-04-06 00:21:27 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "dbghelp_private.h"
|
2020-03-24 01:54:19 +01:00
|
|
|
#include "image_private.h"
|
2005-03-29 15:14:08 +02:00
|
|
|
#include "winnls.h"
|
|
|
|
#include "winternl.h"
|
2004-04-06 00:21:27 +02:00
|
|
|
#include "wine/debug.h"
|
2020-03-17 17:21:17 +01:00
|
|
|
#include "wine/heap.h"
|
2004-04-06 00:21:27 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
|
|
|
|
|
2020-03-23 16:15:31 +01:00
|
|
|
static inline BOOL is_sepA(char ch) {return ch == '/' || ch == '\\';}
|
|
|
|
static inline BOOL is_sep(WCHAR ch) {return ch == '/' || ch == '\\';}
|
2004-06-14 19:58:31 +02:00
|
|
|
|
2020-03-23 16:15:44 +01:00
|
|
|
const char* file_nameA(const char* str)
|
2004-06-14 19:58:31 +02:00
|
|
|
{
|
2006-01-23 16:37:48 +01:00
|
|
|
const char* p;
|
2004-06-14 19:58:31 +02:00
|
|
|
|
2020-03-23 16:15:31 +01:00
|
|
|
for (p = str + strlen(str) - 1; p >= str && !is_sepA(*p); p--);
|
2004-06-14 19:58:31 +02:00
|
|
|
return p + 1;
|
|
|
|
}
|
|
|
|
|
2020-03-23 16:15:44 +01:00
|
|
|
const WCHAR* file_name(const WCHAR* str)
|
2007-02-21 21:55:46 +01:00
|
|
|
{
|
|
|
|
const WCHAR* p;
|
|
|
|
|
2020-04-06 19:43:35 +02:00
|
|
|
for (p = str + lstrlenW(str) - 1; p >= str && !is_sep(*p); p--);
|
2007-02-21 21:55:46 +01:00
|
|
|
return p + 1;
|
|
|
|
}
|
|
|
|
|
2018-11-05 22:20:33 +01:00
|
|
|
static inline void file_pathW(const WCHAR *src, WCHAR *dst)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
2020-04-06 19:43:35 +02:00
|
|
|
for (len = lstrlenW(src) - 1; (len > 0) && (!is_sep(src[len])); len--);
|
2018-11-05 22:20:33 +01:00
|
|
|
memcpy( dst, src, len * sizeof(WCHAR) );
|
|
|
|
dst[len] = 0;
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/******************************************************************
|
|
|
|
* FindDebugInfoFile (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
2006-01-23 16:37:48 +01:00
|
|
|
HANDLE WINAPI FindDebugInfoFile(PCSTR FileName, PCSTR SymbolPath, PSTR DebugFilePath)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
|
|
|
HANDLE h;
|
|
|
|
|
2008-01-17 23:21:00 +01:00
|
|
|
h = CreateFileA(FileName, GENERIC_READ, FILE_SHARE_READ, NULL,
|
2004-04-06 00:21:27 +02:00
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if (h == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2020-03-23 16:15:31 +01:00
|
|
|
if (!SearchPathA(SymbolPath, file_nameA(FileName), NULL, MAX_PATH, DebugFilePath, NULL))
|
2004-04-06 00:21:27 +02:00
|
|
|
return NULL;
|
|
|
|
h = CreateFileA(DebugFilePath, GENERIC_READ, FILE_SHARE_READ, NULL,
|
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
}
|
|
|
|
return (h == INVALID_HANDLE_VALUE) ? NULL : h;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* FindDebugInfoFileEx (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
2006-01-23 16:37:48 +01:00
|
|
|
HANDLE WINAPI FindDebugInfoFileEx(PCSTR FileName, PCSTR SymbolPath,
|
2004-04-06 00:21:27 +02:00
|
|
|
PSTR DebugFilePath,
|
|
|
|
PFIND_DEBUG_FILE_CALLBACK Callback,
|
|
|
|
PVOID CallerData)
|
|
|
|
{
|
2012-03-21 23:34:22 +01:00
|
|
|
FIXME("(%s %s %s %p %p): stub\n", debugstr_a(FileName), debugstr_a(SymbolPath),
|
|
|
|
debugstr_a(DebugFilePath), Callback, CallerData);
|
2004-04-06 00:21:27 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
2007-02-21 21:55:10 +01:00
|
|
|
* FindExecutableImageExW (DBGHELP.@)
|
2004-04-06 00:21:27 +02:00
|
|
|
*
|
|
|
|
*/
|
2007-02-21 21:55:10 +01:00
|
|
|
HANDLE WINAPI FindExecutableImageExW(PCWSTR FileName, PCWSTR SymbolPath, PWSTR ImageFilePath,
|
2007-08-03 00:51:09 +02:00
|
|
|
PFIND_EXE_FILE_CALLBACKW Callback, PVOID user)
|
2007-02-21 21:55:10 +01:00
|
|
|
{
|
|
|
|
HANDLE h;
|
|
|
|
|
|
|
|
if (Callback) FIXME("Unsupported callback yet\n");
|
|
|
|
if (!SearchPathW(SymbolPath, FileName, NULL, MAX_PATH, ImageFilePath, NULL))
|
|
|
|
return NULL;
|
|
|
|
h = CreateFileW(ImageFilePath, GENERIC_READ, FILE_SHARE_READ, NULL,
|
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
return (h == INVALID_HANDLE_VALUE) ? NULL : h;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* FindExecutableImageEx (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI FindExecutableImageEx(PCSTR FileName, PCSTR SymbolPath, PSTR ImageFilePath,
|
2007-08-03 00:51:09 +02:00
|
|
|
PFIND_EXE_FILE_CALLBACK Callback, PVOID user)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
|
|
|
HANDLE h;
|
2007-02-21 21:55:10 +01:00
|
|
|
|
|
|
|
if (Callback) FIXME("Unsupported callback yet\n");
|
2004-04-06 00:21:27 +02:00
|
|
|
if (!SearchPathA(SymbolPath, FileName, NULL, MAX_PATH, ImageFilePath, NULL))
|
|
|
|
return NULL;
|
2007-02-21 21:55:10 +01:00
|
|
|
h = CreateFileA(ImageFilePath, GENERIC_READ, FILE_SHARE_READ, NULL,
|
2004-04-06 00:21:27 +02:00
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
return (h == INVALID_HANDLE_VALUE) ? NULL : h;
|
|
|
|
}
|
|
|
|
|
2007-02-21 21:55:10 +01:00
|
|
|
/******************************************************************
|
|
|
|
* FindExecutableImage (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI FindExecutableImage(PCSTR FileName, PCSTR SymbolPath, PSTR ImageFilePath)
|
|
|
|
{
|
|
|
|
return FindExecutableImageEx(FileName, SymbolPath, ImageFilePath, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* MakeSureDirectoryPathExists (DBGHELP.@)
|
|
|
|
*/
|
2007-08-03 00:51:09 +02:00
|
|
|
BOOL WINAPI MakeSureDirectoryPathExists(PCSTR DirPath)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2004-10-05 04:05:28 +02:00
|
|
|
char path[MAX_PATH];
|
|
|
|
const char *p = DirPath;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if (p[0] && p[1] == ':') p += 2;
|
|
|
|
while (*p == '\\') p++; /* skip drive root */
|
|
|
|
while ((p = strchr(p, '\\')) != NULL)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2004-10-05 04:05:28 +02:00
|
|
|
n = p - DirPath + 1;
|
|
|
|
memcpy(path, DirPath, n);
|
|
|
|
path[n] = '\0';
|
|
|
|
if( !CreateDirectoryA(path, NULL) &&
|
|
|
|
(GetLastError() != ERROR_ALREADY_EXISTS))
|
|
|
|
return FALSE;
|
|
|
|
p++;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
2004-10-05 04:05:28 +02:00
|
|
|
if (GetLastError() == ERROR_ALREADY_EXISTS)
|
|
|
|
SetLastError(ERROR_SUCCESS);
|
|
|
|
|
|
|
|
return TRUE;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
|
2007-02-21 21:55:30 +01:00
|
|
|
/******************************************************************
|
|
|
|
* SymMatchFileNameW (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
2007-08-03 00:51:09 +02:00
|
|
|
BOOL WINAPI SymMatchFileNameW(PCWSTR file, PCWSTR match,
|
|
|
|
PWSTR* filestop, PWSTR* matchstop)
|
2007-02-21 21:55:30 +01:00
|
|
|
{
|
2007-08-03 00:51:09 +02:00
|
|
|
PCWSTR fptr;
|
|
|
|
PCWSTR mptr;
|
2007-02-21 21:55:30 +01:00
|
|
|
|
|
|
|
TRACE("(%s %s %p %p)\n",
|
|
|
|
debugstr_w(file), debugstr_w(match), filestop, matchstop);
|
|
|
|
|
2020-04-06 19:43:35 +02:00
|
|
|
fptr = file + lstrlenW(file) - 1;
|
|
|
|
mptr = match + lstrlenW(match) - 1;
|
2007-02-21 21:55:30 +01:00
|
|
|
|
|
|
|
while (fptr >= file && mptr >= match)
|
|
|
|
{
|
2020-04-06 19:43:35 +02:00
|
|
|
if (towupper(*fptr) != towupper(*mptr) && !(is_sep(*fptr) && is_sep(*mptr)))
|
2007-02-21 21:55:30 +01:00
|
|
|
break;
|
|
|
|
fptr--; mptr--;
|
|
|
|
}
|
2007-08-03 00:51:09 +02:00
|
|
|
if (filestop) *filestop = (PWSTR)fptr;
|
|
|
|
if (matchstop) *matchstop = (PWSTR)mptr;
|
2007-02-21 21:55:30 +01:00
|
|
|
|
|
|
|
return mptr == match - 1;
|
|
|
|
}
|
|
|
|
|
2004-06-14 19:58:31 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SymMatchFileName (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
2007-08-03 00:51:09 +02:00
|
|
|
BOOL WINAPI SymMatchFileName(PCSTR file, PCSTR match,
|
|
|
|
PSTR* filestop, PSTR* matchstop)
|
2004-06-14 19:58:31 +02:00
|
|
|
{
|
2007-08-03 00:51:09 +02:00
|
|
|
PCSTR fptr;
|
|
|
|
PCSTR mptr;
|
2004-06-14 19:58:31 +02:00
|
|
|
|
2008-01-17 23:21:00 +01:00
|
|
|
TRACE("(%s %s %p %p)\n", debugstr_a(file), debugstr_a(match), filestop, matchstop);
|
2004-06-14 19:58:31 +02:00
|
|
|
|
|
|
|
fptr = file + strlen(file) - 1;
|
|
|
|
mptr = match + strlen(match) - 1;
|
|
|
|
|
|
|
|
while (fptr >= file && mptr >= match)
|
|
|
|
{
|
2020-03-23 16:15:31 +01:00
|
|
|
if (toupper(*fptr) != toupper(*mptr) && !(is_sepA(*fptr) && is_sepA(*mptr)))
|
2004-06-14 19:58:31 +02:00
|
|
|
break;
|
|
|
|
fptr--; mptr--;
|
|
|
|
}
|
2007-08-03 00:51:09 +02:00
|
|
|
if (filestop) *filestop = (PSTR)fptr;
|
|
|
|
if (matchstop) *matchstop = (PSTR)mptr;
|
2004-06-14 19:58:31 +02:00
|
|
|
|
|
|
|
return mptr == match - 1;
|
|
|
|
}
|
|
|
|
|
2007-08-03 00:51:09 +02:00
|
|
|
static BOOL do_searchW(PCWSTR file, PWSTR buffer, BOOL recurse,
|
|
|
|
PENUMDIRTREE_CALLBACKW cb, PVOID user)
|
2007-02-21 21:55:35 +01:00
|
|
|
{
|
|
|
|
HANDLE h;
|
|
|
|
WIN32_FIND_DATAW fd;
|
|
|
|
unsigned pos;
|
|
|
|
BOOL found = FALSE;
|
|
|
|
static const WCHAR S_AllW[] = {'*','.','*','\0'};
|
|
|
|
static const WCHAR S_DotW[] = {'.','\0'};
|
2008-01-17 23:21:00 +01:00
|
|
|
static const WCHAR S_DotDotW[] = {'.','.','\0'};
|
2007-02-21 21:55:35 +01:00
|
|
|
|
2020-04-06 19:43:35 +02:00
|
|
|
pos = lstrlenW(buffer);
|
2019-08-29 12:36:58 +02:00
|
|
|
if (pos == 0) return FALSE;
|
2007-02-21 21:55:35 +01:00
|
|
|
if (buffer[pos - 1] != '\\') buffer[pos++] = '\\';
|
2020-04-06 19:43:35 +02:00
|
|
|
lstrcpyW(buffer + pos, S_AllW);
|
2007-02-21 21:55:35 +01:00
|
|
|
if ((h = FindFirstFileW(buffer, &fd)) == INVALID_HANDLE_VALUE)
|
|
|
|
return FALSE;
|
|
|
|
/* doc doesn't specify how the tree is enumerated...
|
|
|
|
* doing a depth first based on, but may be wrong
|
|
|
|
*/
|
|
|
|
do
|
|
|
|
{
|
2020-04-06 19:43:35 +02:00
|
|
|
if (!wcscmp(fd.cFileName, S_DotW) || !wcscmp(fd.cFileName, S_DotDotW)) continue;
|
2007-02-21 21:55:35 +01:00
|
|
|
|
2020-04-06 19:43:35 +02:00
|
|
|
lstrcpyW(buffer + pos, fd.cFileName);
|
2007-02-21 21:55:35 +01:00
|
|
|
if (recurse && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
|
|
|
|
found = do_searchW(file, buffer, TRUE, cb, user);
|
2009-01-19 10:24:06 +01:00
|
|
|
else if (SymMatchFileNameW(buffer, file, NULL, NULL))
|
2007-02-21 21:55:35 +01:00
|
|
|
{
|
|
|
|
if (!cb || cb(buffer, user)) found = TRUE;
|
|
|
|
}
|
|
|
|
} while (!found && FindNextFileW(h, &fd));
|
|
|
|
if (!found) buffer[--pos] = '\0';
|
|
|
|
FindClose(h);
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2007-02-21 21:55:41 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SearchTreeForFileW (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SearchTreeForFileW(PCWSTR root, PCWSTR file, PWSTR buffer)
|
|
|
|
{
|
|
|
|
TRACE("(%s, %s, %p)\n",
|
|
|
|
debugstr_w(root), debugstr_w(file), buffer);
|
2020-04-06 19:43:35 +02:00
|
|
|
lstrcpyW(buffer, root);
|
2007-02-21 21:55:41 +01:00
|
|
|
return do_searchW(file, buffer, TRUE, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SearchTreeForFile (DBGHELP.@)
|
|
|
|
*/
|
2006-01-23 16:37:48 +01:00
|
|
|
BOOL WINAPI SearchTreeForFile(PCSTR root, PCSTR file, PSTR buffer)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2007-02-21 21:55:41 +01:00
|
|
|
WCHAR rootW[MAX_PATH];
|
|
|
|
WCHAR fileW[MAX_PATH];
|
|
|
|
WCHAR bufferW[MAX_PATH];
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, root, -1, rootW, MAX_PATH);
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, file, -1, fileW, MAX_PATH);
|
|
|
|
ret = SearchTreeForFileW(rootW, fileW, bufferW);
|
|
|
|
if (ret)
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, bufferW, -1, buffer, MAX_PATH, NULL, NULL);
|
|
|
|
return ret;
|
2004-06-14 19:58:31 +02:00
|
|
|
}
|
|
|
|
|
2007-02-21 21:55:35 +01:00
|
|
|
/******************************************************************
|
|
|
|
* EnumDirTreeW (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI EnumDirTreeW(HANDLE hProcess, PCWSTR root, PCWSTR file,
|
2007-08-03 00:51:09 +02:00
|
|
|
PWSTR buffer, PENUMDIRTREE_CALLBACKW cb, PVOID user)
|
2007-02-21 21:55:35 +01:00
|
|
|
{
|
|
|
|
TRACE("(%p %s %s %p %p %p)\n",
|
|
|
|
hProcess, debugstr_w(root), debugstr_w(file), buffer, cb, user);
|
|
|
|
|
2020-04-06 19:43:35 +02:00
|
|
|
lstrcpyW(buffer, root);
|
2007-02-21 21:55:35 +01:00
|
|
|
return do_searchW(file, buffer, TRUE, cb, user);
|
|
|
|
}
|
|
|
|
|
2004-06-14 19:58:31 +02:00
|
|
|
/******************************************************************
|
|
|
|
* EnumDirTree (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2007-02-21 21:55:35 +01:00
|
|
|
struct enum_dir_treeWA
|
|
|
|
{
|
|
|
|
PENUMDIRTREE_CALLBACK cb;
|
|
|
|
void* user;
|
|
|
|
char name[MAX_PATH];
|
|
|
|
};
|
|
|
|
|
2007-08-03 00:51:09 +02:00
|
|
|
static BOOL CALLBACK enum_dir_treeWA(PCWSTR name, PVOID user)
|
2007-02-21 21:55:35 +01:00
|
|
|
{
|
|
|
|
struct enum_dir_treeWA* edt = user;
|
|
|
|
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, name, -1, edt->name, MAX_PATH, NULL, NULL);
|
|
|
|
return edt->cb(edt->name, edt->user);
|
|
|
|
}
|
|
|
|
|
2004-06-14 19:58:31 +02:00
|
|
|
BOOL WINAPI EnumDirTree(HANDLE hProcess, PCSTR root, PCSTR file,
|
2007-08-03 00:51:09 +02:00
|
|
|
PSTR buffer, PENUMDIRTREE_CALLBACK cb, PVOID user)
|
2004-06-14 19:58:31 +02:00
|
|
|
{
|
2007-02-21 21:55:35 +01:00
|
|
|
WCHAR rootW[MAX_PATH];
|
|
|
|
WCHAR fileW[MAX_PATH];
|
|
|
|
WCHAR bufferW[MAX_PATH];
|
|
|
|
struct enum_dir_treeWA edt;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
edt.cb = cb;
|
|
|
|
edt.user = user;
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, root, -1, rootW, MAX_PATH);
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, file, -1, fileW, MAX_PATH);
|
|
|
|
if ((ret = EnumDirTreeW(hProcess, rootW, fileW, bufferW, enum_dir_treeWA, &edt)))
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, bufferW, -1, buffer, MAX_PATH, NULL, NULL);
|
|
|
|
return ret;
|
2004-06-14 19:58:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct sffip
|
|
|
|
{
|
2007-02-21 21:55:46 +01:00
|
|
|
PFINDFILEINPATHCALLBACKW cb;
|
2004-06-14 19:58:31 +02:00
|
|
|
void* user;
|
|
|
|
};
|
|
|
|
|
2006-02-20 11:14:34 +01:00
|
|
|
/* checks that buffer (as found by matching the name) matches the info
|
|
|
|
* (information is based on file type)
|
|
|
|
* returns TRUE when file is found, FALSE to continue searching
|
2007-08-03 00:51:09 +02:00
|
|
|
* (NB this is the opposite convention of SymFindFileInPathProc)
|
2006-02-20 11:14:34 +01:00
|
|
|
*/
|
2007-08-03 00:51:09 +02:00
|
|
|
static BOOL CALLBACK sffip_cb(PCWSTR buffer, PVOID user)
|
2004-06-14 19:58:31 +02:00
|
|
|
{
|
2009-01-19 10:24:06 +01:00
|
|
|
struct sffip* s = user;
|
2006-02-20 11:14:34 +01:00
|
|
|
|
2008-08-29 21:50:59 +02:00
|
|
|
if (!s->cb) return TRUE;
|
2005-03-29 15:14:08 +02:00
|
|
|
/* yes, EnumDirTree/do_search and SymFindFileInPath callbacks use the opposite
|
2004-06-14 19:58:31 +02:00
|
|
|
* convention to stop/continue enumeration. sigh.
|
|
|
|
*/
|
2009-01-19 10:24:06 +01:00
|
|
|
return !(s->cb)(buffer, s->user);
|
2004-06-14 19:58:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
2007-02-21 21:55:46 +01:00
|
|
|
* SymFindFileInPathW (DBGHELP.@)
|
2004-06-14 19:58:31 +02:00
|
|
|
*
|
|
|
|
*/
|
2007-02-21 21:55:46 +01:00
|
|
|
BOOL WINAPI SymFindFileInPathW(HANDLE hProcess, PCWSTR searchPath, PCWSTR full_path,
|
|
|
|
PVOID id, DWORD two, DWORD three, DWORD flags,
|
2007-08-03 00:51:09 +02:00
|
|
|
PWSTR buffer, PFINDFILEINPATHCALLBACKW cb,
|
2007-02-21 21:55:46 +01:00
|
|
|
PVOID user)
|
2004-06-14 19:58:31 +02:00
|
|
|
{
|
|
|
|
struct sffip s;
|
|
|
|
struct process* pcs = process_find_by_handle(hProcess);
|
2007-02-21 21:55:46 +01:00
|
|
|
WCHAR tmp[MAX_PATH];
|
|
|
|
WCHAR* ptr;
|
|
|
|
const WCHAR* filename;
|
2004-06-14 19:58:31 +02:00
|
|
|
|
2008-01-17 23:21:00 +01:00
|
|
|
TRACE("(hProcess = %p, searchPath = %s, full_path = %s, id = %p, two = 0x%08x, three = 0x%08x, flags = 0x%08x, buffer = %p, cb = %p, user = %p)\n",
|
2007-02-21 21:55:46 +01:00
|
|
|
hProcess, debugstr_w(searchPath), debugstr_w(full_path),
|
|
|
|
id, two, three, flags, buffer, cb, user);
|
2004-06-14 19:58:31 +02:00
|
|
|
|
|
|
|
if (!pcs) return FALSE;
|
2007-02-21 21:55:46 +01:00
|
|
|
if (!searchPath) searchPath = pcs->search_path;
|
2004-06-14 19:58:31 +02:00
|
|
|
|
|
|
|
s.cb = cb;
|
|
|
|
s.user = user;
|
|
|
|
|
2020-03-23 16:15:31 +01:00
|
|
|
filename = file_name(full_path);
|
2005-03-29 15:14:08 +02:00
|
|
|
|
|
|
|
/* first check full path to file */
|
|
|
|
if (sffip_cb(full_path, &s))
|
|
|
|
{
|
2020-04-06 19:43:35 +02:00
|
|
|
lstrcpyW(buffer, full_path);
|
2005-03-29 15:14:08 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2004-06-14 19:58:31 +02:00
|
|
|
|
|
|
|
while (searchPath)
|
|
|
|
{
|
2020-04-06 19:43:35 +02:00
|
|
|
ptr = wcschr(searchPath, ';');
|
2004-06-14 19:58:31 +02:00
|
|
|
if (ptr)
|
|
|
|
{
|
2007-02-21 21:55:46 +01:00
|
|
|
memcpy(tmp, searchPath, (ptr - searchPath) * sizeof(WCHAR));
|
2004-06-14 19:58:31 +02:00
|
|
|
tmp[ptr - searchPath] = 0;
|
|
|
|
searchPath = ptr + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-06 19:43:35 +02:00
|
|
|
lstrcpyW(tmp, searchPath);
|
2004-06-14 19:58:31 +02:00
|
|
|
searchPath = NULL;
|
|
|
|
}
|
2007-02-21 21:55:46 +01:00
|
|
|
if (do_searchW(filename, tmp, FALSE, sffip_cb, &s))
|
2006-02-20 11:14:34 +01:00
|
|
|
{
|
2020-04-06 19:43:35 +02:00
|
|
|
lstrcpyW(buffer, tmp);
|
2005-05-18 11:42:17 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2004-06-14 19:58:31 +02:00
|
|
|
}
|
2004-04-06 00:21:27 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2007-02-21 21:55:46 +01:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymFindFileInPath (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymFindFileInPath(HANDLE hProcess, PCSTR searchPath, PCSTR full_path,
|
|
|
|
PVOID id, DWORD two, DWORD three, DWORD flags,
|
2007-08-03 00:51:09 +02:00
|
|
|
PSTR buffer, PFINDFILEINPATHCALLBACK cb,
|
2007-02-21 21:55:46 +01:00
|
|
|
PVOID user)
|
|
|
|
{
|
|
|
|
WCHAR searchPathW[MAX_PATH];
|
|
|
|
WCHAR full_pathW[MAX_PATH];
|
|
|
|
WCHAR bufferW[MAX_PATH];
|
|
|
|
struct enum_dir_treeWA edt;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
/* a PFINDFILEINPATHCALLBACK and a PENUMDIRTREE_CALLBACK have actually the
|
|
|
|
* same signature & semantics, hence we can reuse the EnumDirTree W->A
|
|
|
|
* conversion helper
|
|
|
|
*/
|
|
|
|
edt.cb = cb;
|
|
|
|
edt.user = user;
|
|
|
|
if (searchPath)
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, searchPath, -1, searchPathW, MAX_PATH);
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, full_path, -1, full_pathW, MAX_PATH);
|
|
|
|
if ((ret = SymFindFileInPathW(hProcess, searchPath ? searchPathW : NULL, full_pathW,
|
|
|
|
id, two, three, flags,
|
|
|
|
bufferW, enum_dir_treeWA, &edt)))
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, bufferW, -1, buffer, MAX_PATH, NULL, NULL);
|
|
|
|
return ret;
|
|
|
|
}
|
2008-08-29 21:50:46 +02:00
|
|
|
|
|
|
|
struct module_find
|
|
|
|
{
|
|
|
|
enum module_type kind;
|
|
|
|
/* pe: dw1 DWORD:timestamp
|
|
|
|
* dw2 size of image (from PE header)
|
|
|
|
* pdb: guid PDB guid (if DS PDB file)
|
|
|
|
* or dw1 PDB timestamp (if JG PDB file)
|
|
|
|
* dw2 PDB age
|
|
|
|
* elf: dw1 DWORD:CRC 32 of ELF image (Wine only)
|
|
|
|
*/
|
|
|
|
const GUID* guid;
|
|
|
|
DWORD dw1;
|
|
|
|
DWORD dw2;
|
|
|
|
WCHAR filename[MAX_PATH];
|
|
|
|
unsigned matched;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* checks that buffer (as found by matching the name) matches the info
|
|
|
|
* (information is based on file type)
|
|
|
|
* returns TRUE when file is found, FALSE to continue searching
|
|
|
|
* (NB this is the opposite convention of SymFindFileInPathProc)
|
|
|
|
*/
|
|
|
|
static BOOL CALLBACK module_find_cb(PCWSTR buffer, PVOID user)
|
|
|
|
{
|
2009-01-19 10:24:06 +01:00
|
|
|
struct module_find* mf = user;
|
2020-03-26 16:51:20 +01:00
|
|
|
DWORD size, timestamp;
|
2008-08-29 21:50:46 +02:00
|
|
|
unsigned matched = 0;
|
|
|
|
|
|
|
|
/* the matching weights:
|
|
|
|
* +1 if a file with same name is found and is a decent file of expected type
|
|
|
|
* +1 if first parameter and second parameter match
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* FIXME: should check that id/two match the file pointed
|
|
|
|
* by buffer
|
|
|
|
*/
|
|
|
|
switch (mf->kind)
|
|
|
|
{
|
|
|
|
case DMT_PE:
|
|
|
|
{
|
|
|
|
HANDLE hFile, hMap;
|
|
|
|
void* mapping;
|
|
|
|
|
|
|
|
timestamp = ~mf->dw1;
|
|
|
|
size = ~mf->dw2;
|
|
|
|
hFile = CreateFileW(buffer, GENERIC_READ, FILE_SHARE_READ, NULL,
|
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE) return FALSE;
|
|
|
|
if ((hMap = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != NULL)
|
|
|
|
{
|
|
|
|
if ((mapping = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) != NULL)
|
|
|
|
{
|
|
|
|
IMAGE_NT_HEADERS* nth = RtlImageNtHeader(mapping);
|
2015-11-10 19:22:03 +01:00
|
|
|
if (!nth)
|
|
|
|
{
|
|
|
|
UnmapViewOfFile(mapping);
|
|
|
|
CloseHandle(hMap);
|
|
|
|
CloseHandle(hFile);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-08-29 21:50:46 +02:00
|
|
|
matched++;
|
|
|
|
timestamp = nth->FileHeader.TimeDateStamp;
|
|
|
|
size = nth->OptionalHeader.SizeOfImage;
|
|
|
|
UnmapViewOfFile(mapping);
|
|
|
|
}
|
|
|
|
CloseHandle(hMap);
|
|
|
|
}
|
|
|
|
CloseHandle(hFile);
|
|
|
|
if (timestamp != mf->dw1)
|
|
|
|
WARN("Found %s, but wrong timestamp\n", debugstr_w(buffer));
|
|
|
|
if (size != mf->dw2)
|
|
|
|
WARN("Found %s, but wrong size\n", debugstr_w(buffer));
|
|
|
|
if (timestamp == mf->dw1 && size == mf->dw2) matched++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DMT_PDB:
|
|
|
|
{
|
2011-01-08 14:04:01 +01:00
|
|
|
struct pdb_lookup pdb_lookup;
|
|
|
|
char fn[MAX_PATH];
|
2008-08-29 21:50:46 +02:00
|
|
|
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, buffer, -1, fn, MAX_PATH, NULL, NULL);
|
|
|
|
pdb_lookup.filename = fn;
|
|
|
|
|
2011-01-08 14:04:01 +01:00
|
|
|
if (mf->guid)
|
2008-08-29 21:50:46 +02:00
|
|
|
{
|
2011-01-08 14:04:01 +01:00
|
|
|
pdb_lookup.kind = PDB_DS;
|
|
|
|
pdb_lookup.timestamp = 0;
|
|
|
|
pdb_lookup.guid = *mf->guid;
|
2008-08-29 21:50:46 +02:00
|
|
|
}
|
2011-01-08 14:04:01 +01:00
|
|
|
else
|
2008-08-29 21:50:46 +02:00
|
|
|
{
|
2011-01-08 14:04:01 +01:00
|
|
|
pdb_lookup.kind = PDB_JG;
|
|
|
|
pdb_lookup.timestamp = mf->dw1;
|
|
|
|
/* pdb_loopkup.guid = */
|
2008-08-29 21:50:46 +02:00
|
|
|
}
|
2011-01-08 14:04:01 +01:00
|
|
|
pdb_lookup.age = mf->dw2;
|
|
|
|
|
|
|
|
if (!pdb_fetch_file_info(&pdb_lookup, &matched)) return FALSE;
|
2008-08-29 21:50:46 +02:00
|
|
|
}
|
|
|
|
break;
|
2008-08-29 21:50:53 +02:00
|
|
|
case DMT_DBG:
|
|
|
|
{
|
|
|
|
HANDLE hFile, hMap;
|
|
|
|
void* mapping;
|
|
|
|
|
|
|
|
timestamp = ~mf->dw1;
|
|
|
|
hFile = CreateFileW(buffer, GENERIC_READ, FILE_SHARE_READ, NULL,
|
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE) return FALSE;
|
|
|
|
if ((hMap = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != NULL)
|
|
|
|
{
|
|
|
|
if ((mapping = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) != NULL)
|
|
|
|
{
|
|
|
|
const IMAGE_SEPARATE_DEBUG_HEADER* hdr;
|
2009-01-19 10:24:06 +01:00
|
|
|
hdr = mapping;
|
2008-08-29 21:50:53 +02:00
|
|
|
|
|
|
|
if (hdr->Signature == IMAGE_SEPARATE_DEBUG_SIGNATURE)
|
|
|
|
{
|
|
|
|
matched++;
|
|
|
|
timestamp = hdr->TimeDateStamp;
|
|
|
|
}
|
|
|
|
UnmapViewOfFile(mapping);
|
|
|
|
}
|
|
|
|
CloseHandle(hMap);
|
|
|
|
}
|
|
|
|
CloseHandle(hFile);
|
|
|
|
if (timestamp == mf->dw1) matched++;
|
|
|
|
else WARN("Found %s, but wrong timestamp\n", debugstr_w(buffer));
|
|
|
|
}
|
|
|
|
break;
|
2008-08-29 21:50:46 +02:00
|
|
|
default:
|
|
|
|
FIXME("What the heck??\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (matched > mf->matched)
|
|
|
|
{
|
2020-04-06 19:43:35 +02:00
|
|
|
lstrcpyW(mf->filename, buffer);
|
2008-08-29 21:50:46 +02:00
|
|
|
mf->matched = matched;
|
|
|
|
}
|
|
|
|
/* yes, EnumDirTree/do_search and SymFindFileInPath callbacks use the opposite
|
|
|
|
* convention to stop/continue enumeration. sigh.
|
|
|
|
*/
|
|
|
|
return mf->matched == 2;
|
|
|
|
}
|
|
|
|
|
2018-11-05 22:20:33 +01:00
|
|
|
BOOL path_find_symbol_file(const struct process* pcs, const struct module* module,
|
2020-03-25 17:41:26 +01:00
|
|
|
PCSTR full_path, enum module_type type, const GUID* guid, DWORD dw1, DWORD dw2,
|
2018-11-15 14:24:58 +01:00
|
|
|
WCHAR *buffer, BOOL* is_unmatched)
|
2008-08-29 21:50:46 +02:00
|
|
|
{
|
|
|
|
struct module_find mf;
|
|
|
|
WCHAR full_pathW[MAX_PATH];
|
|
|
|
WCHAR* ptr;
|
|
|
|
const WCHAR* filename;
|
|
|
|
WCHAR* searchPath = pcs->search_path;
|
|
|
|
|
|
|
|
TRACE("(pcs = %p, full_path = %s, guid = %s, dw1 = 0x%08x, dw2 = 0x%08x, buffer = %p)\n",
|
|
|
|
pcs, debugstr_a(full_path), debugstr_guid(guid), dw1, dw2, buffer);
|
|
|
|
|
|
|
|
mf.guid = guid;
|
|
|
|
mf.dw1 = dw1;
|
|
|
|
mf.dw2 = dw2;
|
|
|
|
mf.matched = 0;
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, full_path, -1, full_pathW, MAX_PATH);
|
2020-03-23 16:15:31 +01:00
|
|
|
filename = file_name(full_pathW);
|
2020-03-25 17:41:26 +01:00
|
|
|
mf.kind = type;
|
2008-10-18 09:15:03 +02:00
|
|
|
*is_unmatched = FALSE;
|
2008-08-29 21:50:46 +02:00
|
|
|
|
|
|
|
/* first check full path to file */
|
|
|
|
if (module_find_cb(full_pathW, &mf))
|
|
|
|
{
|
2020-04-06 19:43:35 +02:00
|
|
|
lstrcpyW( buffer, full_pathW );
|
2008-08-29 21:50:46 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-11-05 22:20:33 +01:00
|
|
|
/* FIXME: Use Environment-Variables (see MS docs)
|
|
|
|
_NT_SYMBOL_PATH and _NT_ALT_SYMBOL_PATH
|
|
|
|
FIXME: Implement "Standard Path Elements" (Path) ... (see MS docs)
|
|
|
|
do a search for (every?) path-element like this ...
|
|
|
|
<path>
|
|
|
|
<path>\dll
|
|
|
|
<path>\symbols\dll
|
|
|
|
(dll may be exe, or sys depending on the file extension) */
|
|
|
|
|
|
|
|
/* 2. check module-path */
|
2018-11-15 14:24:58 +01:00
|
|
|
file_pathW(module->module.LoadedImageName, buffer);
|
|
|
|
if (do_searchW(filename, buffer, FALSE, module_find_cb, &mf)) return TRUE;
|
2020-03-10 14:54:42 +01:00
|
|
|
if (module->real_path)
|
|
|
|
{
|
|
|
|
file_pathW(module->real_path, buffer);
|
|
|
|
if (do_searchW(filename, buffer, FALSE, module_find_cb, &mf)) return TRUE;
|
|
|
|
}
|
2018-11-05 22:20:33 +01:00
|
|
|
|
2008-08-29 21:50:46 +02:00
|
|
|
while (searchPath)
|
|
|
|
{
|
2020-04-06 19:43:35 +02:00
|
|
|
ptr = wcschr(searchPath, ';');
|
2008-08-29 21:50:46 +02:00
|
|
|
if (ptr)
|
|
|
|
{
|
2018-11-15 14:24:58 +01:00
|
|
|
memcpy(buffer, searchPath, (ptr - searchPath) * sizeof(WCHAR));
|
|
|
|
buffer[ptr - searchPath] = '\0';
|
2008-08-29 21:50:46 +02:00
|
|
|
searchPath = ptr + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-06 19:43:35 +02:00
|
|
|
lstrcpyW(buffer, searchPath);
|
2008-08-29 21:50:46 +02:00
|
|
|
searchPath = NULL;
|
|
|
|
}
|
2018-11-15 14:24:58 +01:00
|
|
|
/* return first fully matched file */
|
|
|
|
if (do_searchW(filename, buffer, FALSE, module_find_cb, &mf)) return TRUE;
|
2008-08-29 21:50:46 +02:00
|
|
|
}
|
|
|
|
/* if no fully matching file is found, return the best matching file if any */
|
|
|
|
if ((dbghelp_options & SYMOPT_LOAD_ANYTHING) && mf.matched)
|
|
|
|
{
|
2020-04-06 19:43:35 +02:00
|
|
|
lstrcpyW( buffer, mf.filename );
|
2008-10-18 09:15:03 +02:00
|
|
|
*is_unmatched = TRUE;
|
2008-08-29 21:50:46 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-03-17 17:21:17 +01:00
|
|
|
|
|
|
|
WCHAR *get_dos_file_name(const WCHAR *filename)
|
|
|
|
{
|
|
|
|
WCHAR *dos_path;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (*filename == '/')
|
|
|
|
{
|
|
|
|
char *unix_path;
|
|
|
|
len = WideCharToMultiByte(CP_UNIXCP, 0, filename, -1, NULL, 0, NULL, NULL);
|
|
|
|
unix_path = heap_alloc(len * sizeof(WCHAR));
|
|
|
|
WideCharToMultiByte(CP_UNIXCP, 0, filename, -1, unix_path, len, NULL, NULL);
|
|
|
|
dos_path = wine_get_dos_file_name(unix_path);
|
|
|
|
heap_free(unix_path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
len = lstrlenW(filename);
|
|
|
|
dos_path = heap_alloc((len + 1) * sizeof(WCHAR));
|
|
|
|
memcpy(dos_path, filename, (len + 1) * sizeof(WCHAR));
|
|
|
|
}
|
|
|
|
return dos_path;
|
|
|
|
}
|
2020-03-23 16:15:58 +01:00
|
|
|
|
2020-04-09 19:59:57 +02:00
|
|
|
BOOL search_dll_path(const struct process *process, const WCHAR *name, BOOL (*match)(void*, HANDLE, const WCHAR*), void *param)
|
2020-03-23 16:15:58 +01:00
|
|
|
{
|
2020-04-09 19:59:57 +02:00
|
|
|
const WCHAR *env;
|
2020-03-23 16:15:58 +01:00
|
|
|
size_t len, i;
|
|
|
|
HANDLE file;
|
|
|
|
WCHAR *buf;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
name = file_name(name);
|
|
|
|
|
2020-04-09 19:59:57 +02:00
|
|
|
if ((env = process_getenv(process, L"WINEBUILDDIR")))
|
2020-03-23 16:15:58 +01:00
|
|
|
{
|
|
|
|
WCHAR *p, *end;
|
|
|
|
const WCHAR dllsW[] = { '\\','d','l','l','s','\\' };
|
|
|
|
const WCHAR programsW[] = { '\\','p','r','o','g','r','a','m','s','\\' };
|
|
|
|
const WCHAR dot_dllW[] = {'.','d','l','l',0};
|
|
|
|
const WCHAR dot_exeW[] = {'.','e','x','e',0};
|
|
|
|
const WCHAR dot_soW[] = {'.','s','o',0};
|
|
|
|
|
2020-04-09 19:59:57 +02:00
|
|
|
|
|
|
|
len = lstrlenW(env);
|
2020-03-23 16:15:58 +01:00
|
|
|
if (!(buf = heap_alloc((len + 8 + 3 * lstrlenW(name)) * sizeof(WCHAR)))) return FALSE;
|
2020-04-09 19:59:57 +02:00
|
|
|
wcscpy(buf, env);
|
|
|
|
end = buf + len;
|
2020-03-23 16:15:58 +01:00
|
|
|
|
|
|
|
memcpy(end, dllsW, sizeof(dllsW));
|
2020-04-06 19:43:35 +02:00
|
|
|
lstrcpyW(end + ARRAY_SIZE(dllsW), name);
|
|
|
|
if ((p = wcsrchr(end, '.')) && !lstrcmpW(p, dot_soW)) *p = 0;
|
|
|
|
if ((p = wcsrchr(end, '.')) && !lstrcmpW(p, dot_dllW)) *p = 0;
|
|
|
|
p = end + lstrlenW(end);
|
2020-03-23 16:15:58 +01:00
|
|
|
*p++ = '\\';
|
2020-04-06 19:43:35 +02:00
|
|
|
lstrcpyW(p, name);
|
2020-03-23 16:15:58 +01:00
|
|
|
file = CreateFileW(buf, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if (file != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
ret = match(param, file, buf);
|
|
|
|
CloseHandle(file);
|
|
|
|
if (ret) goto found;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(end, programsW, sizeof(programsW));
|
|
|
|
end += ARRAY_SIZE(programsW);
|
2020-04-06 19:43:35 +02:00
|
|
|
lstrcpyW(end, name);
|
|
|
|
if ((p = wcsrchr(end, '.')) && !lstrcmpW(p, dot_soW)) *p = 0;
|
|
|
|
if ((p = wcsrchr(end, '.')) && !lstrcmpW(p, dot_exeW)) *p = 0;
|
|
|
|
p = end + lstrlenW(end);
|
2020-03-23 16:15:58 +01:00
|
|
|
*p++ = '\\';
|
2020-04-06 19:43:35 +02:00
|
|
|
lstrcpyW(p, name);
|
2020-03-23 16:15:58 +01:00
|
|
|
file = CreateFileW(buf, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if (file != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
ret = match(param, file, buf);
|
|
|
|
CloseHandle(file);
|
|
|
|
if (ret) goto found;
|
|
|
|
}
|
|
|
|
|
|
|
|
heap_free(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0;; i++)
|
|
|
|
{
|
|
|
|
WCHAR env_name[64];
|
2020-04-09 19:59:57 +02:00
|
|
|
swprintf(env_name, ARRAY_SIZE(env_name), L"WINEDLLDIR%u", i);
|
|
|
|
if (!(env = process_getenv(process, env_name))) return FALSE;
|
|
|
|
len = lstrlenW(env);
|
2020-03-23 16:15:58 +01:00
|
|
|
if (!(buf = heap_alloc((len + lstrlenW(name) + 2) * sizeof(WCHAR)))) return FALSE;
|
|
|
|
|
|
|
|
len = GetEnvironmentVariableW(env_name, buf, len);
|
|
|
|
buf[len++] = '\\';
|
2020-04-06 19:43:35 +02:00
|
|
|
lstrcpyW(buf + len, name);
|
2020-03-23 16:15:58 +01:00
|
|
|
file = CreateFileW(buf, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if (file != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
ret = match(param, file, buf);
|
|
|
|
CloseHandle(file);
|
|
|
|
if (ret) goto found;
|
|
|
|
}
|
|
|
|
heap_free(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
found:
|
|
|
|
TRACE("found %s\n", debugstr_w(buf));
|
|
|
|
heap_free(buf);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2020-03-23 16:16:27 +01:00
|
|
|
|
2020-05-13 18:31:46 +02:00
|
|
|
BOOL search_unix_path(const WCHAR *name, const WCHAR *path, BOOL (*match)(void*, HANDLE, const WCHAR*), void *param)
|
2020-03-23 16:16:27 +01:00
|
|
|
{
|
2020-05-13 18:31:46 +02:00
|
|
|
const WCHAR *iter, *next;
|
2020-03-23 16:16:27 +01:00
|
|
|
size_t size, len;
|
|
|
|
WCHAR *dos_path;
|
|
|
|
char *buf;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
if (!path) return FALSE;
|
|
|
|
name = file_name(name);
|
|
|
|
|
2020-05-13 18:31:46 +02:00
|
|
|
size = WideCharToMultiByte(CP_UNIXCP, 0, name, -1, NULL, 0, NULL, NULL)
|
|
|
|
+ WideCharToMultiByte(CP_UNIXCP, 0, path, -1, NULL, 0, NULL, NULL);
|
2020-03-23 16:16:27 +01:00
|
|
|
if (!(buf = heap_alloc(size))) return FALSE;
|
|
|
|
|
|
|
|
for (iter = path;; iter = next + 1)
|
|
|
|
{
|
2020-05-13 18:31:46 +02:00
|
|
|
if (!(next = wcschr(iter, ':'))) next = iter + lstrlenW(iter);
|
2020-03-23 16:16:27 +01:00
|
|
|
if (*iter == '/')
|
|
|
|
{
|
2020-05-13 18:31:46 +02:00
|
|
|
len = WideCharToMultiByte(CP_UNIXCP, 0, iter, next - iter, buf, size, NULL, NULL);
|
2020-03-23 16:16:27 +01:00
|
|
|
if (buf[len - 1] != '/') buf[len++] = '/';
|
|
|
|
WideCharToMultiByte(CP_UNIXCP, 0, name, -1, buf + len, size - len, NULL, NULL);
|
|
|
|
if ((dos_path = wine_get_dos_file_name(buf)))
|
|
|
|
{
|
|
|
|
HANDLE file = CreateFileW(dos_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if (file != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
ret = match(param, file, dos_path);
|
|
|
|
CloseHandle(file);
|
|
|
|
if (ret) TRACE("found %s\n", debugstr_w(dos_path));
|
|
|
|
}
|
|
|
|
heap_free(dos_path);
|
|
|
|
if (ret) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*next != ':') break;
|
|
|
|
}
|
|
|
|
|
|
|
|
heap_free(buf);
|
|
|
|
return ret;
|
|
|
|
}
|