2004-04-06 00:21:27 +02:00
|
|
|
/*
|
|
|
|
* File module.c - module handling for the wine debugger
|
|
|
|
*
|
|
|
|
* Copyright (C) 1993, Eric Youngdale.
|
2007-02-21 21:55:04 +01:00
|
|
|
* 2000-2007, 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 <assert.h>
|
|
|
|
|
|
|
|
#include "dbghelp_private.h"
|
2020-03-17 20:10:40 +01:00
|
|
|
#include "image_private.h"
|
2004-04-06 00:21:27 +02:00
|
|
|
#include "psapi.h"
|
|
|
|
#include "winternl.h"
|
|
|
|
#include "wine/debug.h"
|
2018-05-31 16:47:48 +02:00
|
|
|
#include "wine/heap.h"
|
2004-04-06 00:21:27 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
|
|
|
|
|
2020-03-31 18:20:37 +02:00
|
|
|
#define NOTE_GNU_BUILD_ID 3
|
|
|
|
|
2007-02-21 21:55:04 +01:00
|
|
|
const WCHAR S_ElfW[] = {'<','e','l','f','>','\0'};
|
|
|
|
const WCHAR S_WineLoaderW[] = {'<','w','i','n','e','-','l','o','a','d','e','r','>','\0'};
|
|
|
|
static const WCHAR S_DotSoW[] = {'.','s','o','\0'};
|
2007-02-21 21:56:27 +01:00
|
|
|
const WCHAR S_SlashW[] = {'/','\0'};
|
2005-12-22 11:11:39 +01:00
|
|
|
|
2007-02-21 21:55:04 +01:00
|
|
|
static const WCHAR S_AcmW[] = {'.','a','c','m','\0'};
|
|
|
|
static const WCHAR S_DllW[] = {'.','d','l','l','\0'};
|
|
|
|
static const WCHAR S_DrvW[] = {'.','d','r','v','\0'};
|
|
|
|
static const WCHAR S_ExeW[] = {'.','e','x','e','\0'};
|
|
|
|
static const WCHAR S_OcxW[] = {'.','o','c','x','\0'};
|
|
|
|
static const WCHAR S_VxdW[] = {'.','v','x','d','\0'};
|
|
|
|
static const WCHAR * const ext[] = {S_AcmW, S_DllW, S_DrvW, S_ExeW, S_OcxW, S_VxdW, NULL};
|
|
|
|
|
|
|
|
static int match_ext(const WCHAR* ptr, size_t len)
|
2005-12-22 11:11:39 +01:00
|
|
|
{
|
2007-02-21 21:55:04 +01:00
|
|
|
const WCHAR* const *e;
|
2005-12-22 11:11:39 +01:00
|
|
|
size_t l;
|
|
|
|
|
|
|
|
for (e = ext; *e; e++)
|
|
|
|
{
|
2020-04-06 19:43:35 +02:00
|
|
|
l = lstrlenW(*e);
|
2013-11-12 01:16:36 +01:00
|
|
|
if (l >= len) return 0;
|
2020-04-06 19:43:35 +02:00
|
|
|
if (wcsnicmp(&ptr[len - l], *e, l)) continue;
|
2005-12-22 11:11:39 +01:00
|
|
|
return l;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2007-02-21 21:55:04 +01:00
|
|
|
|
2007-03-13 17:32:52 +01:00
|
|
|
static const WCHAR* get_filename(const WCHAR* name, const WCHAR* endptr)
|
|
|
|
{
|
|
|
|
const WCHAR* ptr;
|
|
|
|
|
2020-04-06 19:43:35 +02:00
|
|
|
if (!endptr) endptr = name + lstrlenW(name);
|
2007-03-13 17:32:52 +01:00
|
|
|
for (ptr = endptr - 1; ptr >= name; ptr--)
|
|
|
|
{
|
|
|
|
if (*ptr == '/' || *ptr == '\\') break;
|
|
|
|
}
|
|
|
|
return ++ptr;
|
|
|
|
}
|
|
|
|
|
2018-05-31 16:47:48 +02:00
|
|
|
static BOOL is_wine_loader(const WCHAR *module)
|
|
|
|
{
|
|
|
|
static const WCHAR wineW[] = {'w','i','n','e',0};
|
|
|
|
static const WCHAR suffixW[] = {'6','4',0};
|
|
|
|
const WCHAR *filename = get_filename(module, NULL);
|
2020-03-23 16:15:44 +01:00
|
|
|
const char *ptr;
|
2018-05-31 16:47:48 +02:00
|
|
|
BOOL ret = FALSE;
|
|
|
|
WCHAR *buffer;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
if ((ptr = getenv("WINELOADER")))
|
|
|
|
{
|
2020-03-23 16:15:44 +01:00
|
|
|
ptr = file_nameA(ptr);
|
2018-05-31 16:47:48 +02:00
|
|
|
len = 2 + MultiByteToWideChar( CP_UNIXCP, 0, ptr, -1, NULL, 0 );
|
|
|
|
buffer = heap_alloc( len * sizeof(WCHAR) );
|
|
|
|
MultiByteToWideChar( CP_UNIXCP, 0, ptr, -1, buffer, len );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buffer = heap_alloc( sizeof(wineW) + 2 * sizeof(WCHAR) );
|
2020-04-06 19:43:35 +02:00
|
|
|
lstrcpyW( buffer, wineW );
|
2018-05-31 16:47:48 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 19:43:35 +02:00
|
|
|
if (!wcscmp( filename, buffer ))
|
2018-05-31 16:47:48 +02:00
|
|
|
ret = TRUE;
|
|
|
|
|
2020-04-06 19:43:35 +02:00
|
|
|
lstrcatW( buffer, suffixW );
|
|
|
|
if (!wcscmp( filename, buffer ))
|
2018-05-31 16:47:48 +02:00
|
|
|
ret = TRUE;
|
|
|
|
|
|
|
|
heap_free( buffer );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-02-21 21:55:04 +01:00
|
|
|
static void module_fill_module(const WCHAR* in, WCHAR* out, size_t size)
|
2004-05-18 23:29:09 +02:00
|
|
|
{
|
2007-03-13 17:32:52 +01:00
|
|
|
const WCHAR *ptr, *endptr;
|
2005-12-22 11:11:39 +01:00
|
|
|
size_t len, l;
|
2004-05-18 23:29:09 +02:00
|
|
|
|
2020-04-06 19:43:35 +02:00
|
|
|
ptr = get_filename(in, endptr = in + lstrlenW(in));
|
2007-03-13 17:32:52 +01:00
|
|
|
len = min(endptr - ptr, size - 1);
|
2007-02-21 21:55:04 +01:00
|
|
|
memcpy(out, ptr, len * sizeof(WCHAR));
|
2005-04-18 17:33:31 +02:00
|
|
|
out[len] = '\0';
|
2005-12-22 11:11:39 +01:00
|
|
|
if (len > 4 && (l = match_ext(out, len)))
|
|
|
|
out[len - l] = '\0';
|
2018-05-31 16:47:48 +02:00
|
|
|
else if (is_wine_loader(out))
|
2007-02-21 21:55:04 +01:00
|
|
|
lstrcpynW(out, S_WineLoaderW, size);
|
2004-05-24 21:08:19 +02:00
|
|
|
else
|
|
|
|
{
|
2020-04-06 19:43:35 +02:00
|
|
|
if (len > 3 && !wcsicmp(&out[len - 3], S_DotSoW) &&
|
2005-12-22 11:11:39 +01:00
|
|
|
(l = match_ext(out, len - 3)))
|
2020-04-06 19:43:35 +02:00
|
|
|
lstrcpyW(&out[len - l - 3], S_ElfW);
|
2004-05-24 21:08:19 +02:00
|
|
|
}
|
2020-04-06 19:43:35 +02:00
|
|
|
while ((*out = towlower(*out))) out++;
|
2004-05-18 23:29:09 +02:00
|
|
|
}
|
|
|
|
|
2007-02-21 21:55:04 +01:00
|
|
|
void module_set_module(struct module* module, const WCHAR* name)
|
2007-02-21 21:54:33 +01:00
|
|
|
{
|
2018-07-12 23:49:34 +02:00
|
|
|
module_fill_module(name, module->module.ModuleName, ARRAY_SIZE(module->module.ModuleName));
|
|
|
|
module_fill_module(name, module->modulename, ARRAY_SIZE(module->modulename));
|
2007-02-21 21:54:33 +01:00
|
|
|
}
|
|
|
|
|
2018-05-31 16:47:49 +02:00
|
|
|
/* Returned string must be freed by caller */
|
2020-12-08 20:19:12 +01:00
|
|
|
const WCHAR *get_wine_loader_name(struct process *pcs)
|
2011-01-28 11:41:14 +01:00
|
|
|
{
|
2020-12-08 20:19:12 +01:00
|
|
|
const WCHAR *name = process_getenv(pcs, L"WINELOADER");
|
|
|
|
if (!name) name = pcs->is_64bit ? L"wine64" : L"wine";
|
|
|
|
TRACE("returning %s\n", debugstr_w(name));
|
|
|
|
return name;
|
2011-01-28 11:41:14 +01:00
|
|
|
}
|
|
|
|
|
2006-02-20 12:16:08 +01:00
|
|
|
static const char* get_module_type(enum module_type type, BOOL virtual)
|
2005-11-29 11:47:40 +01:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
2006-02-20 12:16:08 +01:00
|
|
|
case DMT_ELF: return virtual ? "Virtual ELF" : "ELF";
|
|
|
|
case DMT_PE: return virtual ? "Virtual PE" : "PE";
|
2009-03-13 17:48:00 +01:00
|
|
|
case DMT_MACHO: return virtual ? "Virtual Mach-O" : "Mach-O";
|
2005-11-29 11:47:40 +01:00
|
|
|
default: return "---";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/***********************************************************************
|
2007-02-21 21:55:04 +01:00
|
|
|
* Creates and links a new module to a process
|
2004-04-06 00:21:27 +02:00
|
|
|
*/
|
2007-02-21 21:55:04 +01:00
|
|
|
struct module* module_new(struct process* pcs, const WCHAR* name,
|
2006-02-20 12:16:08 +01:00
|
|
|
enum module_type type, BOOL virtual,
|
2009-12-12 12:18:56 +01:00
|
|
|
DWORD64 mod_addr, DWORD64 size,
|
2020-03-26 16:51:49 +01:00
|
|
|
ULONG_PTR stamp, ULONG_PTR checksum)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
|
|
|
struct module* module;
|
2010-03-18 21:31:43 +01:00
|
|
|
unsigned i;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2009-03-13 17:48:00 +01:00
|
|
|
assert(type == DMT_ELF || type == DMT_PE || type == DMT_MACHO);
|
2007-04-25 00:57:55 +02:00
|
|
|
if (!(module = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*module))))
|
2004-04-06 00:21:27 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
module->next = pcs->lmodules;
|
|
|
|
pcs->lmodules = module;
|
|
|
|
|
2009-12-12 12:18:56 +01:00
|
|
|
TRACE("=> %s %s-%s %s\n",
|
|
|
|
get_module_type(type, virtual),
|
|
|
|
wine_dbgstr_longlong(mod_addr), wine_dbgstr_longlong(mod_addr + size),
|
2007-02-21 21:55:04 +01:00
|
|
|
debugstr_w(name));
|
2004-04-06 00:21:27 +02:00
|
|
|
|
|
|
|
pool_init(&module->pool, 65536);
|
2007-02-21 21:55:04 +01:00
|
|
|
|
2010-06-07 21:50:46 +02:00
|
|
|
module->process = pcs;
|
2004-04-06 00:21:27 +02:00
|
|
|
module->module.SizeOfStruct = sizeof(module->module);
|
|
|
|
module->module.BaseOfImage = mod_addr;
|
|
|
|
module->module.ImageSize = size;
|
2007-02-21 21:54:33 +01:00
|
|
|
module_set_module(module, name);
|
2004-04-06 00:21:27 +02:00
|
|
|
module->module.ImageName[0] = '\0';
|
2018-07-12 23:49:34 +02:00
|
|
|
lstrcpynW(module->module.LoadedImageName, name, ARRAY_SIZE(module->module.LoadedImageName));
|
2004-04-06 00:21:27 +02:00
|
|
|
module->module.SymType = SymNone;
|
|
|
|
module->module.NumSyms = 0;
|
|
|
|
module->module.TimeDateStamp = stamp;
|
|
|
|
module->module.CheckSum = checksum;
|
|
|
|
|
2011-02-23 05:41:27 +01:00
|
|
|
memset(module->module.LoadedPdbName, 0, sizeof(module->module.LoadedPdbName));
|
2006-06-26 21:37:32 +02:00
|
|
|
module->module.CVSig = 0;
|
|
|
|
memset(module->module.CVData, 0, sizeof(module->module.CVData));
|
|
|
|
module->module.PdbSig = 0;
|
|
|
|
memset(&module->module.PdbSig70, 0, sizeof(module->module.PdbSig70));
|
|
|
|
module->module.PdbAge = 0;
|
|
|
|
module->module.PdbUnmatched = FALSE;
|
|
|
|
module->module.DbgUnmatched = FALSE;
|
|
|
|
module->module.LineNumbers = FALSE;
|
|
|
|
module->module.GlobalSymbols = FALSE;
|
|
|
|
module->module.TypeInfo = FALSE;
|
2006-11-06 20:05:38 +01:00
|
|
|
module->module.SourceIndexed = FALSE;
|
|
|
|
module->module.Publics = FALSE;
|
2021-07-17 00:17:39 +02:00
|
|
|
module->module.MachineType = 0;
|
|
|
|
module->module.Reserved = 0;
|
2006-06-26 21:37:32 +02:00
|
|
|
|
2010-04-01 21:24:14 +02:00
|
|
|
module->reloc_delta = 0;
|
2004-04-06 00:21:27 +02:00
|
|
|
module->type = type;
|
2012-08-14 23:08:03 +02:00
|
|
|
module->is_virtual = virtual;
|
2010-03-18 21:31:43 +01:00
|
|
|
for (i = 0; i < DFI_LAST; i++) module->format_info[i] = NULL;
|
2004-04-06 00:21:27 +02:00
|
|
|
module->sortlist_valid = FALSE;
|
2009-07-10 14:46:55 +02:00
|
|
|
module->sorttab_size = 0;
|
2004-04-06 00:21:27 +02:00
|
|
|
module->addr_sorttab = NULL;
|
2009-06-25 22:27:38 +02:00
|
|
|
module->num_sorttab = 0;
|
|
|
|
module->num_symbols = 0;
|
2009-12-14 22:05:54 +01:00
|
|
|
|
|
|
|
vector_init(&module->vsymt, sizeof(struct symt*), 128);
|
2004-04-06 00:21:27 +02:00
|
|
|
/* FIXME: this seems a bit too high (on a per module basis)
|
|
|
|
* need some statistics about this
|
|
|
|
*/
|
|
|
|
hash_table_init(&module->pool, &module->ht_symbols, 4096);
|
|
|
|
hash_table_init(&module->pool, &module->ht_types, 4096);
|
2004-09-27 22:31:42 +02:00
|
|
|
vector_init(&module->vtypes, sizeof(struct symt*), 32);
|
2004-04-06 00:21:27 +02:00
|
|
|
|
|
|
|
module->sources_used = 0;
|
|
|
|
module->sources_alloc = 0;
|
|
|
|
module->sources = 0;
|
2016-09-01 10:55:49 +02:00
|
|
|
wine_rb_init(&module->sources_offsets_tree, source_rb_compare);
|
2004-04-06 00:21:27 +02:00
|
|
|
|
|
|
|
return module;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2011-05-31 13:12:44 +02:00
|
|
|
* module_find_by_nameW
|
2004-04-06 00:21:27 +02:00
|
|
|
*
|
|
|
|
*/
|
2011-05-31 13:12:44 +02:00
|
|
|
struct module* module_find_by_nameW(const struct process* pcs, const WCHAR* name)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
|
|
|
struct module* module;
|
|
|
|
|
2007-03-13 17:33:02 +01:00
|
|
|
for (module = pcs->lmodules; module; module = module->next)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2020-04-06 19:43:35 +02:00
|
|
|
if (!wcsicmp(name, module->module.ModuleName)) return module;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
SetLastError(ERROR_INVALID_NAME);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-03-13 17:33:02 +01:00
|
|
|
struct module* module_find_by_nameA(const struct process* pcs, const char* name)
|
2007-02-21 21:55:04 +01:00
|
|
|
{
|
|
|
|
WCHAR wname[MAX_PATH];
|
|
|
|
|
2018-07-12 23:49:34 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, name, -1, wname, ARRAY_SIZE(wname));
|
2011-05-31 13:12:44 +02:00
|
|
|
return module_find_by_nameW(pcs, wname);
|
2007-03-13 17:33:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* module_is_already_loaded
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct module* module_is_already_loaded(const struct process* pcs, const WCHAR* name)
|
|
|
|
{
|
|
|
|
struct module* module;
|
|
|
|
const WCHAR* filename;
|
|
|
|
|
|
|
|
/* first compare the loaded image name... */
|
|
|
|
for (module = pcs->lmodules; module; module = module->next)
|
|
|
|
{
|
2020-04-06 19:43:35 +02:00
|
|
|
if (!wcsicmp(name, module->module.LoadedImageName))
|
2007-03-13 17:33:02 +01:00
|
|
|
return module;
|
|
|
|
}
|
|
|
|
/* then compare the standard filenames (without the path) ... */
|
|
|
|
filename = get_filename(name, NULL);
|
|
|
|
for (module = pcs->lmodules; module; module = module->next)
|
|
|
|
{
|
2020-04-06 19:43:35 +02:00
|
|
|
if (!wcsicmp(filename, get_filename(module->module.LoadedImageName, NULL)))
|
2007-03-13 17:33:02 +01:00
|
|
|
return module;
|
|
|
|
}
|
|
|
|
SetLastError(ERROR_INVALID_NAME);
|
|
|
|
return NULL;
|
2007-02-21 21:55:04 +01:00
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/***********************************************************************
|
2004-07-04 02:10:54 +02:00
|
|
|
* module_get_container
|
2004-04-06 00:21:27 +02:00
|
|
|
*
|
|
|
|
*/
|
2009-01-03 13:53:34 +01:00
|
|
|
static struct module* module_get_container(const struct process* pcs,
|
2004-07-04 02:10:54 +02:00
|
|
|
const struct module* inner)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
|
|
|
struct module* module;
|
|
|
|
|
|
|
|
for (module = pcs->lmodules; module; module = module->next)
|
|
|
|
{
|
|
|
|
if (module != inner &&
|
|
|
|
module->module.BaseOfImage <= inner->module.BaseOfImage &&
|
|
|
|
module->module.BaseOfImage + module->module.ImageSize >=
|
|
|
|
inner->module.BaseOfImage + inner->module.ImageSize)
|
|
|
|
return module;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-07-04 02:10:54 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* module_get_containee
|
|
|
|
*
|
|
|
|
*/
|
2019-06-04 20:28:21 +02:00
|
|
|
struct module* module_get_containee(const struct process* pcs, const struct module* outer)
|
2004-07-04 02:10:54 +02:00
|
|
|
{
|
|
|
|
struct module* module;
|
2019-06-04 20:28:21 +02:00
|
|
|
|
2004-07-04 02:10:54 +02:00
|
|
|
for (module = pcs->lmodules; module; module = module->next)
|
|
|
|
{
|
2019-06-04 20:28:21 +02:00
|
|
|
if (module != outer &&
|
|
|
|
outer->module.BaseOfImage <= module->module.BaseOfImage &&
|
|
|
|
outer->module.BaseOfImage + outer->module.ImageSize >=
|
2004-07-04 02:10:54 +02:00
|
|
|
module->module.BaseOfImage + module->module.ImageSize)
|
|
|
|
return module;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/******************************************************************
|
|
|
|
* module_get_debug
|
|
|
|
*
|
|
|
|
* get the debug information from a module:
|
|
|
|
* - if the module's type is deferred, then force loading of debug info (and return
|
|
|
|
* the module itself)
|
|
|
|
* - if the module has no debug info and has an ELF container, then return the ELF
|
|
|
|
* container (and also force the ELF container's debug info loading if deferred)
|
|
|
|
* - otherwise return the module itself if it has some debug info
|
|
|
|
*/
|
2006-11-24 22:17:10 +01:00
|
|
|
BOOL module_get_debug(struct module_pair* pair)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2007-02-21 21:55:56 +01:00
|
|
|
IMAGEHLP_DEFERRED_SYMBOL_LOADW64 idslW64;
|
2004-08-30 21:31:13 +02:00
|
|
|
|
2006-05-07 14:29:49 +02:00
|
|
|
if (!pair->requested) return FALSE;
|
|
|
|
/* for a PE builtin, always get info from container */
|
2006-11-24 22:17:10 +01:00
|
|
|
if (!(pair->effective = module_get_container(pair->pcs, pair->requested)))
|
2006-05-07 14:29:49 +02:00
|
|
|
pair->effective = pair->requested;
|
2004-11-08 21:26:22 +01:00
|
|
|
/* if deferred, force loading */
|
2006-05-07 14:29:49 +02:00
|
|
|
if (pair->effective->module.SymType == SymDeferred)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2004-11-08 21:26:22 +01:00
|
|
|
BOOL ret;
|
2006-02-20 12:16:08 +01:00
|
|
|
|
2006-05-07 14:29:49 +02:00
|
|
|
if (pair->effective->is_virtual) ret = FALSE;
|
2020-03-25 17:41:16 +01:00
|
|
|
else if (pair->effective->type == DMT_PE)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2007-02-21 21:55:56 +01:00
|
|
|
idslW64.SizeOfStruct = sizeof(idslW64);
|
|
|
|
idslW64.BaseOfImage = pair->effective->module.BaseOfImage;
|
|
|
|
idslW64.CheckSum = pair->effective->module.CheckSum;
|
|
|
|
idslW64.TimeDateStamp = pair->effective->module.TimeDateStamp;
|
|
|
|
memcpy(idslW64.FileName, pair->effective->module.ImageName,
|
2008-02-21 17:44:24 +01:00
|
|
|
sizeof(pair->effective->module.ImageName));
|
2007-02-21 21:55:56 +01:00
|
|
|
idslW64.Reparse = FALSE;
|
|
|
|
idslW64.hFile = INVALID_HANDLE_VALUE;
|
|
|
|
|
|
|
|
pcs_callback(pair->pcs, CBA_DEFERRED_SYMBOL_LOAD_START, &idslW64);
|
2006-11-24 22:17:10 +01:00
|
|
|
ret = pe_load_debug_info(pair->pcs, pair->effective);
|
|
|
|
pcs_callback(pair->pcs,
|
2006-01-23 16:29:21 +01:00
|
|
|
ret ? CBA_DEFERRED_SYMBOL_LOAD_COMPLETE : CBA_DEFERRED_SYMBOL_LOAD_FAILURE,
|
2007-02-21 21:55:56 +01:00
|
|
|
&idslW64);
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
2020-03-25 17:41:16 +01:00
|
|
|
else ret = pair->pcs->loader->load_debug_info(pair->pcs, pair->effective);
|
|
|
|
|
2006-05-07 14:29:49 +02:00
|
|
|
if (!ret) pair->effective->module.SymType = SymNone;
|
|
|
|
assert(pair->effective->module.SymType != SymDeferred);
|
2006-12-05 22:13:27 +01:00
|
|
|
pair->effective->module.NumSyms = pair->effective->ht_symbols.num_elts;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
2006-05-07 14:29:49 +02:00
|
|
|
return pair->effective->module.SymType != SymNone;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* module_find_by_addr
|
|
|
|
*
|
|
|
|
* either the addr where module is loaded, or any address inside the
|
|
|
|
* module
|
|
|
|
*/
|
2012-01-22 13:00:57 +01:00
|
|
|
struct module* module_find_by_addr(const struct process* pcs, DWORD64 addr,
|
2004-05-18 23:29:09 +02:00
|
|
|
enum module_type type)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
|
|
|
struct module* module;
|
|
|
|
|
|
|
|
if (type == DMT_UNKNOWN)
|
|
|
|
{
|
|
|
|
if ((module = module_find_by_addr(pcs, addr, DMT_PE)) ||
|
2009-03-13 17:48:00 +01:00
|
|
|
(module = module_find_by_addr(pcs, addr, DMT_ELF)) ||
|
|
|
|
(module = module_find_by_addr(pcs, addr, DMT_MACHO)))
|
2004-04-06 00:21:27 +02:00
|
|
|
return module;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (module = pcs->lmodules; module; module = module->next)
|
|
|
|
{
|
|
|
|
if (type == module->type && addr >= module->module.BaseOfImage &&
|
|
|
|
addr < module->module.BaseOfImage + module->module.ImageSize)
|
|
|
|
return module;
|
|
|
|
}
|
|
|
|
}
|
2018-11-25 10:15:49 +01:00
|
|
|
SetLastError(ERROR_MOD_NOT_FOUND);
|
2004-04-06 00:21:27 +02:00
|
|
|
return module;
|
|
|
|
}
|
|
|
|
|
2007-03-13 17:32:57 +01:00
|
|
|
/******************************************************************
|
2009-03-11 15:08:54 +01:00
|
|
|
* module_is_container_loaded
|
2007-03-13 17:32:57 +01:00
|
|
|
*
|
2009-03-11 15:08:54 +01:00
|
|
|
* checks whether the native container, for a (supposed) PE builtin is
|
2007-03-13 17:32:57 +01:00
|
|
|
* already loaded
|
|
|
|
*/
|
2009-03-11 15:08:54 +01:00
|
|
|
static BOOL module_is_container_loaded(const struct process* pcs,
|
2009-12-12 12:18:56 +01:00
|
|
|
const WCHAR* ImageName, DWORD64 base)
|
2004-05-24 21:08:19 +02:00
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
struct module* module;
|
2007-08-03 00:51:09 +02:00
|
|
|
PCWSTR filename, modname;
|
2007-03-13 17:32:57 +01:00
|
|
|
|
|
|
|
if (!base) return FALSE;
|
|
|
|
filename = get_filename(ImageName, NULL);
|
2020-04-06 19:43:35 +02:00
|
|
|
len = lstrlenW(filename);
|
2004-05-24 21:08:19 +02:00
|
|
|
|
|
|
|
for (module = pcs->lmodules; module; module = module->next)
|
|
|
|
{
|
2009-03-13 17:48:00 +01:00
|
|
|
if ((module->type == DMT_ELF || module->type == DMT_MACHO) &&
|
2007-03-13 17:32:57 +01:00
|
|
|
base >= module->module.BaseOfImage &&
|
|
|
|
base < module->module.BaseOfImage + module->module.ImageSize)
|
|
|
|
{
|
|
|
|
modname = get_filename(module->module.LoadedImageName, NULL);
|
2020-04-06 19:43:35 +02:00
|
|
|
if (!wcsnicmp(modname, filename, len) &&
|
2007-03-13 17:32:57 +01:00
|
|
|
!memcmp(modname + len, S_DotSoW, 3 * sizeof(WCHAR)))
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2004-05-24 21:08:19 +02:00
|
|
|
}
|
2007-03-13 17:32:57 +01:00
|
|
|
/* likely a native PE module */
|
|
|
|
WARN("Couldn't find container for %s\n", debugstr_w(ImageName));
|
2004-05-24 21:08:19 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-03-17 20:10:40 +01:00
|
|
|
static BOOL image_check_debug_link(const WCHAR* file, struct image_file_map* fmap, DWORD link_crc)
|
|
|
|
{
|
2020-03-17 17:21:58 +01:00
|
|
|
DWORD read_bytes;
|
2020-03-17 20:10:40 +01:00
|
|
|
HANDLE handle;
|
|
|
|
WCHAR *path;
|
2020-03-17 17:21:58 +01:00
|
|
|
WORD magic;
|
2020-03-17 20:10:40 +01:00
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
path = get_dos_file_name(file);
|
|
|
|
handle = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
|
|
|
heap_free(path);
|
|
|
|
if (handle == INVALID_HANDLE_VALUE) return FALSE;
|
|
|
|
|
|
|
|
if (link_crc)
|
|
|
|
{
|
|
|
|
DWORD crc = calc_crc32(handle);
|
|
|
|
if (crc != link_crc)
|
|
|
|
{
|
|
|
|
WARN("Bad CRC for file %s (got %08x while expecting %08x)\n", debugstr_w(file), crc, link_crc);
|
|
|
|
CloseHandle(handle);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-17 17:21:58 +01:00
|
|
|
SetFilePointer(handle, 0, 0, FILE_BEGIN);
|
|
|
|
if (ReadFile(handle, &magic, sizeof(magic), &read_bytes, NULL) && magic == IMAGE_DOS_SIGNATURE)
|
|
|
|
ret = pe_map_file(handle, fmap, DMT_PE);
|
|
|
|
else
|
|
|
|
ret = elf_map_handle(handle, fmap);
|
2020-03-17 20:10:40 +01:00
|
|
|
CloseHandle(handle);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* image_locate_debug_link
|
|
|
|
*
|
|
|
|
* Locate a filename from a .gnu_debuglink section, using the same
|
|
|
|
* strategy as gdb:
|
|
|
|
* "If the full name of the directory containing the executable is
|
|
|
|
* execdir, and the executable has a debug link that specifies the
|
|
|
|
* name debugfile, then GDB will automatically search for the
|
|
|
|
* debugging information file in three places:
|
|
|
|
* - the directory containing the executable file (that is, it
|
|
|
|
* will look for a file named `execdir/debugfile',
|
|
|
|
* - a subdirectory of that directory named `.debug' (that is, the
|
|
|
|
* file `execdir/.debug/debugfile', and
|
|
|
|
* - a subdirectory of the global debug file directory that includes
|
|
|
|
* the executable's full path, and the name from the link (that is,
|
|
|
|
* the file `globaldebugdir/execdir/debugfile', where globaldebugdir
|
|
|
|
* is the global debug file directory, and execdir has been turned
|
|
|
|
* into a relative path)." (from GDB manual)
|
|
|
|
*/
|
|
|
|
static BOOL image_locate_debug_link(const struct module* module, struct image_file_map* fmap, const char* filename, DWORD crc)
|
|
|
|
{
|
|
|
|
static const WCHAR globalDebugDirW[] = {'/','u','s','r','/','l','i','b','/','d','e','b','u','g','/'};
|
|
|
|
static const WCHAR dotDebugW[] = {'.','d','e','b','u','g','/'};
|
|
|
|
const size_t globalDebugDirLen = ARRAY_SIZE(globalDebugDirW);
|
|
|
|
size_t filename_len, path_len;
|
|
|
|
WCHAR* p = NULL;
|
|
|
|
WCHAR* slash;
|
|
|
|
WCHAR* slash2;
|
|
|
|
struct image_file_map* fmap_link = NULL;
|
|
|
|
|
|
|
|
fmap_link = HeapAlloc(GetProcessHeap(), 0, sizeof(*fmap_link));
|
|
|
|
if (!fmap_link) return FALSE;
|
|
|
|
|
|
|
|
filename_len = MultiByteToWideChar(CP_UNIXCP, 0, filename, -1, NULL, 0);
|
2020-04-06 19:43:35 +02:00
|
|
|
path_len = lstrlenW(module->module.LoadedImageName);
|
|
|
|
if (module->real_path) path_len = max(path_len, lstrlenW(module->real_path));
|
2020-03-17 20:10:40 +01:00
|
|
|
p = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
(globalDebugDirLen + path_len + 6 + 1 + filename_len + 1) * sizeof(WCHAR));
|
|
|
|
if (!p) goto found;
|
|
|
|
|
|
|
|
/* we prebuild the string with "execdir" */
|
2020-04-06 19:43:35 +02:00
|
|
|
lstrcpyW(p, module->module.LoadedImageName);
|
2020-03-17 20:10:40 +01:00
|
|
|
slash = p;
|
2020-04-06 19:43:35 +02:00
|
|
|
if ((slash2 = wcsrchr(slash, '/'))) slash = slash2 + 1;
|
|
|
|
if ((slash2 = wcsrchr(slash, '\\'))) slash = slash2 + 1;
|
2020-03-17 20:10:40 +01:00
|
|
|
|
|
|
|
/* testing execdir/filename */
|
|
|
|
MultiByteToWideChar(CP_UNIXCP, 0, filename, -1, slash, filename_len);
|
|
|
|
if (image_check_debug_link(p, fmap_link, crc)) goto found;
|
|
|
|
|
|
|
|
/* testing execdir/.debug/filename */
|
|
|
|
memcpy(slash, dotDebugW, sizeof(dotDebugW));
|
|
|
|
MultiByteToWideChar(CP_UNIXCP, 0, filename, -1, slash + ARRAY_SIZE(dotDebugW), filename_len);
|
|
|
|
if (image_check_debug_link(p, fmap_link, crc)) goto found;
|
|
|
|
|
2020-03-17 17:22:07 +01:00
|
|
|
if (module->real_path)
|
|
|
|
{
|
2020-04-06 19:43:35 +02:00
|
|
|
lstrcpyW(p, module->real_path);
|
2020-03-17 17:22:07 +01:00
|
|
|
slash = p;
|
2020-04-06 19:43:35 +02:00
|
|
|
if ((slash2 = wcsrchr(slash, '/'))) slash = slash2 + 1;
|
|
|
|
if ((slash2 = wcsrchr(slash, '\\'))) slash = slash2 + 1;
|
2020-03-17 17:22:07 +01:00
|
|
|
MultiByteToWideChar(CP_UNIXCP, 0, filename, -1, slash, filename_len);
|
|
|
|
if (image_check_debug_link(p, fmap_link, crc)) goto found;
|
|
|
|
}
|
|
|
|
|
2020-03-17 20:10:40 +01:00
|
|
|
/* testing globaldebugdir/execdir/filename */
|
|
|
|
memmove(p + globalDebugDirLen, p, (slash - p) * sizeof(WCHAR));
|
|
|
|
memcpy(p, globalDebugDirW, globalDebugDirLen * sizeof(WCHAR));
|
|
|
|
slash += globalDebugDirLen;
|
|
|
|
MultiByteToWideChar(CP_UNIXCP, 0, filename, -1, slash, filename_len);
|
|
|
|
if (image_check_debug_link(p, fmap_link, crc)) goto found;
|
|
|
|
|
|
|
|
/* finally testing filename */
|
|
|
|
if (image_check_debug_link(slash, fmap_link, crc)) goto found;
|
|
|
|
|
|
|
|
|
|
|
|
WARN("Couldn't locate or map %s\n", filename);
|
|
|
|
HeapFree(GetProcessHeap(), 0, p);
|
|
|
|
HeapFree(GetProcessHeap(), 0, fmap_link);
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
found:
|
|
|
|
TRACE("Located debug information file %s at %s\n", filename, debugstr_w(p));
|
|
|
|
HeapFree(GetProcessHeap(), 0, p);
|
|
|
|
fmap->alternate = fmap_link;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* image_locate_build_id_target
|
|
|
|
*
|
|
|
|
* Try to find the .so file containing the debug info out of the build-id note information
|
|
|
|
*/
|
|
|
|
static BOOL image_locate_build_id_target(struct image_file_map* fmap, const BYTE* id, unsigned idlen)
|
|
|
|
{
|
|
|
|
static const WCHAR globalDebugDirW[] = {'/','u','s','r','/','l','i','b','/','d','e','b','u','g','/'};
|
|
|
|
static const WCHAR buildidW[] = {'.','b','u','i','l','d','-','i','d','/'};
|
|
|
|
static const WCHAR dotDebug0W[] = {'.','d','e','b','u','g',0};
|
|
|
|
struct image_file_map* fmap_link = NULL;
|
|
|
|
WCHAR* p;
|
|
|
|
WCHAR* z;
|
|
|
|
const BYTE* idend = id + idlen;
|
|
|
|
|
|
|
|
fmap_link = HeapAlloc(GetProcessHeap(), 0, sizeof(*fmap_link));
|
|
|
|
if (!fmap_link) return FALSE;
|
|
|
|
|
|
|
|
p = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
sizeof(globalDebugDirW) + sizeof(buildidW) +
|
|
|
|
(idlen * 2 + 1) * sizeof(WCHAR) + sizeof(dotDebug0W));
|
|
|
|
z = p;
|
|
|
|
memcpy(z, globalDebugDirW, sizeof(globalDebugDirW));
|
|
|
|
z += ARRAY_SIZE(globalDebugDirW);
|
|
|
|
memcpy(z, buildidW, sizeof(buildidW));
|
|
|
|
z += ARRAY_SIZE(buildidW);
|
|
|
|
|
|
|
|
if (id < idend)
|
|
|
|
{
|
|
|
|
*z++ = "0123456789abcdef"[*id >> 4 ];
|
|
|
|
*z++ = "0123456789abcdef"[*id & 0x0F];
|
|
|
|
id++;
|
|
|
|
}
|
|
|
|
if (id < idend)
|
|
|
|
*z++ = '/';
|
|
|
|
while (id < idend)
|
|
|
|
{
|
|
|
|
*z++ = "0123456789abcdef"[*id >> 4 ];
|
|
|
|
*z++ = "0123456789abcdef"[*id & 0x0F];
|
|
|
|
id++;
|
|
|
|
}
|
|
|
|
memcpy(z, dotDebug0W, sizeof(dotDebug0W));
|
|
|
|
TRACE("checking %s\n", wine_dbgstr_w(p));
|
|
|
|
|
|
|
|
if (image_check_debug_link(p, fmap_link, 0))
|
|
|
|
{
|
|
|
|
struct image_section_map buildid_sect;
|
|
|
|
if (image_find_section(fmap_link, ".note.gnu.build-id", &buildid_sect))
|
|
|
|
{
|
|
|
|
const UINT32* note;
|
|
|
|
|
|
|
|
note = (const UINT32*)image_map_section(&buildid_sect);
|
|
|
|
if (note != IMAGE_NO_MAP)
|
|
|
|
{
|
|
|
|
/* the usual ELF note structure: name-size desc-size type <name> <desc> */
|
2020-03-31 18:20:37 +02:00
|
|
|
if (note[2] == NOTE_GNU_BUILD_ID)
|
2020-03-17 20:10:40 +01:00
|
|
|
{
|
|
|
|
if (note[1] == idlen &&
|
|
|
|
!memcmp(note + 3 + ((note[0] + 3) >> 2), idend - idlen, idlen))
|
|
|
|
{
|
|
|
|
TRACE("Located debug information file at %s\n", debugstr_w(p));
|
|
|
|
HeapFree(GetProcessHeap(), 0, p);
|
|
|
|
fmap->alternate = fmap_link;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
WARN("mismatch in buildid information for %s\n", wine_dbgstr_w(p));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
image_unmap_section(&buildid_sect);
|
|
|
|
}
|
|
|
|
image_unmap_file(fmap_link);
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("not found\n");
|
|
|
|
HeapFree(GetProcessHeap(), 0, p);
|
|
|
|
HeapFree(GetProcessHeap(), 0, fmap_link);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* image_check_alternate
|
|
|
|
*
|
|
|
|
* Load alternate files for a given image file, looking at either .note.gnu_build-id
|
|
|
|
* or .gnu_debuglink sections.
|
|
|
|
*/
|
|
|
|
BOOL image_check_alternate(struct image_file_map* fmap, const struct module* module)
|
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
BOOL found = FALSE;
|
|
|
|
struct image_section_map buildid_sect, debuglink_sect;
|
|
|
|
|
|
|
|
/* if present, add the .gnu_debuglink file as an alternate to current one */
|
|
|
|
if (image_find_section(fmap, ".note.gnu.build-id", &buildid_sect))
|
|
|
|
{
|
|
|
|
const UINT32* note;
|
|
|
|
|
|
|
|
found = TRUE;
|
|
|
|
note = (const UINT32*)image_map_section(&buildid_sect);
|
|
|
|
if (note != IMAGE_NO_MAP)
|
|
|
|
{
|
|
|
|
/* the usual ELF note structure: name-size desc-size type <name> <desc> */
|
2020-03-31 18:20:37 +02:00
|
|
|
if (note[2] == NOTE_GNU_BUILD_ID)
|
2020-03-17 20:10:40 +01:00
|
|
|
{
|
|
|
|
ret = image_locate_build_id_target(fmap, (const BYTE*)(note + 3 + ((note[0] + 3) >> 2)), note[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
image_unmap_section(&buildid_sect);
|
|
|
|
}
|
|
|
|
/* if present, add the .gnu_debuglink file as an alternate to current one */
|
|
|
|
if (!ret && image_find_section(fmap, ".gnu_debuglink", &debuglink_sect))
|
|
|
|
{
|
|
|
|
const char* dbg_link;
|
|
|
|
|
|
|
|
found = TRUE;
|
|
|
|
dbg_link = (const char*)image_map_section(&debuglink_sect);
|
|
|
|
if (dbg_link != IMAGE_NO_MAP)
|
|
|
|
{
|
|
|
|
/* The content of a debug link section is:
|
|
|
|
* 1/ a NULL terminated string, containing the file name for the
|
|
|
|
* debug info
|
|
|
|
* 2/ padding on 4 byte boundary
|
|
|
|
* 3/ CRC of the linked file
|
|
|
|
*/
|
|
|
|
DWORD crc = *(const DWORD*)(dbg_link + ((DWORD_PTR)(strlen(dbg_link) + 4) & ~3));
|
|
|
|
ret = image_locate_debug_link(module, fmap, dbg_link, crc);
|
|
|
|
if (!ret)
|
|
|
|
WARN("Couldn't load linked debug file for %s\n",
|
|
|
|
debugstr_w(module->module.ModuleName));
|
|
|
|
}
|
|
|
|
image_unmap_section(&debuglink_sect);
|
|
|
|
}
|
|
|
|
return found ? ret : TRUE;
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SymLoadModule (DBGHELP.@)
|
|
|
|
*/
|
2007-08-03 00:51:09 +02:00
|
|
|
DWORD WINAPI SymLoadModule(HANDLE hProcess, HANDLE hFile, PCSTR ImageName,
|
|
|
|
PCSTR ModuleName, DWORD BaseOfDll, DWORD SizeOfDll)
|
2007-02-21 21:54:54 +01:00
|
|
|
{
|
|
|
|
return SymLoadModuleEx(hProcess, hFile, ImageName, ModuleName, BaseOfDll,
|
|
|
|
SizeOfDll, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SymLoadModuleEx (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
DWORD64 WINAPI SymLoadModuleEx(HANDLE hProcess, HANDLE hFile, PCSTR ImageName,
|
|
|
|
PCSTR ModuleName, DWORD64 BaseOfDll, DWORD DllSize,
|
|
|
|
PMODLOAD_DATA Data, DWORD Flags)
|
|
|
|
{
|
2007-08-03 00:51:09 +02:00
|
|
|
PWSTR wImageName, wModuleName;
|
2007-02-21 21:54:54 +01:00
|
|
|
unsigned len;
|
|
|
|
DWORD64 ret;
|
|
|
|
|
|
|
|
TRACE("(%p %p %s %s %s %08x %p %08x)\n",
|
|
|
|
hProcess, hFile, debugstr_a(ImageName), debugstr_a(ModuleName),
|
|
|
|
wine_dbgstr_longlong(BaseOfDll), DllSize, Data, Flags);
|
|
|
|
|
|
|
|
if (ImageName)
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, ImageName, -1, NULL, 0);
|
|
|
|
wImageName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, ImageName, -1, wImageName, len);
|
|
|
|
}
|
|
|
|
else wImageName = NULL;
|
|
|
|
if (ModuleName)
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, ModuleName, -1, NULL, 0);
|
|
|
|
wModuleName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, ModuleName, -1, wModuleName, len);
|
|
|
|
}
|
|
|
|
else wModuleName = NULL;
|
|
|
|
|
|
|
|
ret = SymLoadModuleExW(hProcess, hFile, wImageName, wModuleName,
|
|
|
|
BaseOfDll, DllSize, Data, Flags);
|
|
|
|
HeapFree(GetProcessHeap(), 0, wImageName);
|
|
|
|
HeapFree(GetProcessHeap(), 0, wModuleName);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SymLoadModuleExW (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
DWORD64 WINAPI SymLoadModuleExW(HANDLE hProcess, HANDLE hFile, PCWSTR wImageName,
|
|
|
|
PCWSTR wModuleName, DWORD64 BaseOfDll, DWORD SizeOfDll,
|
|
|
|
PMODLOAD_DATA Data, DWORD Flags)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
|
|
|
struct process* pcs;
|
|
|
|
struct module* module = NULL;
|
|
|
|
|
2007-02-21 21:54:54 +01:00
|
|
|
TRACE("(%p %p %s %s %s %08x %p %08x)\n",
|
|
|
|
hProcess, hFile, debugstr_w(wImageName), debugstr_w(wModuleName),
|
|
|
|
wine_dbgstr_longlong(BaseOfDll), SizeOfDll, Data, Flags);
|
|
|
|
|
|
|
|
if (Data)
|
|
|
|
FIXME("Unsupported load data parameter %p for %s\n",
|
|
|
|
Data, debugstr_w(wImageName));
|
|
|
|
if (!validate_addr64(BaseOfDll)) return FALSE;
|
|
|
|
|
|
|
|
if (!(pcs = process_find_by_handle(hProcess))) return FALSE;
|
|
|
|
|
|
|
|
if (Flags & SLMFLAG_VIRTUAL)
|
|
|
|
{
|
2009-12-01 10:48:56 +01:00
|
|
|
if (!wImageName) return FALSE;
|
2020-03-25 17:41:38 +01:00
|
|
|
module = module_new(pcs, wImageName, DMT_PE, TRUE, BaseOfDll, SizeOfDll, 0, 0);
|
2007-02-21 21:54:54 +01:00
|
|
|
if (!module) return FALSE;
|
2007-02-21 21:55:04 +01:00
|
|
|
if (wModuleName) module_set_module(module, wModuleName);
|
2007-02-21 21:54:54 +01:00
|
|
|
module->module.SymType = SymVirtual;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if (Flags & ~(SLMFLAG_VIRTUAL))
|
|
|
|
FIXME("Unsupported Flags %08x for %s\n", Flags, debugstr_w(wImageName));
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2020-03-24 01:54:07 +01:00
|
|
|
pcs->loader->synchronize_module_list(pcs);
|
2004-05-24 21:08:19 +02:00
|
|
|
|
|
|
|
/* this is a Wine extension to the API just to redo the synchronisation */
|
2007-02-21 21:54:54 +01:00
|
|
|
if (!wImageName && !hFile) return 0;
|
|
|
|
|
2007-03-13 17:33:02 +01:00
|
|
|
/* check if the module is already loaded, or if it's a builtin PE module with
|
|
|
|
* an containing ELF module
|
|
|
|
*/
|
|
|
|
if (wImageName)
|
2004-05-18 23:29:09 +02:00
|
|
|
{
|
2007-03-13 17:33:02 +01:00
|
|
|
module = module_is_already_loaded(pcs, wImageName);
|
2009-03-11 15:08:54 +01:00
|
|
|
if (!module && module_is_container_loaded(pcs, wImageName, BaseOfDll))
|
2007-03-13 17:33:02 +01:00
|
|
|
{
|
|
|
|
/* force the loading of DLL as builtin */
|
2007-03-13 17:33:08 +01:00
|
|
|
module = pe_load_builtin_module(pcs, wImageName, BaseOfDll, SizeOfDll);
|
2007-03-13 17:33:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!module)
|
|
|
|
{
|
|
|
|
/* otherwise, try a regular PE module */
|
2009-03-13 17:48:00 +01:00
|
|
|
if (!(module = pe_load_native_module(pcs, wImageName, hFile, BaseOfDll, SizeOfDll)) &&
|
|
|
|
wImageName)
|
2007-03-13 17:33:02 +01:00
|
|
|
{
|
2009-03-13 17:48:00 +01:00
|
|
|
/* and finally an ELF or Mach-O module */
|
2020-03-25 17:40:59 +01:00
|
|
|
module = pcs->loader->load_module(pcs, wImageName, BaseOfDll);
|
2007-03-13 17:33:02 +01:00
|
|
|
}
|
2004-05-18 23:29:09 +02:00
|
|
|
}
|
2007-03-13 17:33:02 +01:00
|
|
|
if (!module)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2007-02-21 21:54:54 +01:00
|
|
|
WARN("Couldn't locate %s\n", debugstr_w(wImageName));
|
2004-04-06 00:21:27 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2006-12-05 22:13:27 +01:00
|
|
|
module->module.NumSyms = module->ht_symbols.num_elts;
|
2007-03-13 17:33:02 +01:00
|
|
|
/* by default module_new fills module.ModuleName from a derivation
|
|
|
|
* of LoadedImageName. Overwrite it, if we have better information
|
2004-04-06 00:21:27 +02:00
|
|
|
*/
|
2007-02-21 21:55:04 +01:00
|
|
|
if (wModuleName)
|
|
|
|
module_set_module(module, wModuleName);
|
2009-12-01 10:48:56 +01:00
|
|
|
if (wImageName)
|
2018-07-12 23:49:34 +02:00
|
|
|
lstrcpynW(module->module.ImageName, wImageName, ARRAY_SIZE(module->module.ImageName));
|
2004-04-06 00:21:27 +02:00
|
|
|
|
|
|
|
return module->module.BaseOfImage;
|
|
|
|
}
|
|
|
|
|
2005-05-29 22:02:42 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SymLoadModule64 (DBGHELP.@)
|
|
|
|
*/
|
2006-01-23 16:37:48 +01:00
|
|
|
DWORD64 WINAPI SymLoadModule64(HANDLE hProcess, HANDLE hFile, PCSTR ImageName,
|
|
|
|
PCSTR ModuleName, DWORD64 BaseOfDll, DWORD SizeOfDll)
|
2005-05-29 22:02:42 +02:00
|
|
|
{
|
2012-01-22 13:00:57 +01:00
|
|
|
return SymLoadModuleEx(hProcess, hFile, ImageName, ModuleName, BaseOfDll, SizeOfDll,
|
|
|
|
NULL, 0);
|
2005-05-29 22:02:42 +02:00
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/******************************************************************
|
|
|
|
* module_remove
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL module_remove(struct process* pcs, struct module* module)
|
|
|
|
{
|
2010-03-18 21:31:43 +01:00
|
|
|
struct module_format*modfmt;
|
2004-04-06 00:21:27 +02:00
|
|
|
struct module** p;
|
2010-03-18 21:31:43 +01:00
|
|
|
unsigned i;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2007-03-13 17:26:33 +01:00
|
|
|
TRACE("%s (%p)\n", debugstr_w(module->module.ModuleName), module);
|
2010-03-15 21:12:31 +01:00
|
|
|
|
2010-03-18 21:31:43 +01:00
|
|
|
for (i = 0; i < DFI_LAST; i++)
|
|
|
|
{
|
|
|
|
if ((modfmt = module->format_info[i]) && modfmt->remove)
|
|
|
|
modfmt->remove(pcs, module->format_info[i]);
|
|
|
|
}
|
2004-04-06 00:21:27 +02:00
|
|
|
hash_table_destroy(&module->ht_symbols);
|
|
|
|
hash_table_destroy(&module->ht_types);
|
2007-12-04 22:45:11 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, module->sources);
|
2004-04-06 00:21:27 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, module->addr_sorttab);
|
2020-03-10 14:54:31 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, module->real_path);
|
2004-04-06 00:21:27 +02:00
|
|
|
pool_destroy(&module->pool);
|
2006-05-10 21:35:47 +02:00
|
|
|
/* native dbghelp doesn't invoke registered callback(,CBA_SYMBOLS_UNLOADED,) here
|
|
|
|
* so do we
|
|
|
|
*/
|
2004-04-06 00:21:27 +02:00
|
|
|
for (p = &pcs->lmodules; *p; p = &(*p)->next)
|
|
|
|
{
|
|
|
|
if (*p == module)
|
|
|
|
{
|
|
|
|
*p = module->next;
|
|
|
|
HeapFree(GetProcessHeap(), 0, module);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FIXME("This shouldn't happen\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymUnloadModule (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymUnloadModule(HANDLE hProcess, DWORD BaseOfDll)
|
|
|
|
{
|
|
|
|
struct process* pcs;
|
|
|
|
struct module* module;
|
|
|
|
|
|
|
|
pcs = process_find_by_handle(hProcess);
|
|
|
|
if (!pcs) return FALSE;
|
|
|
|
module = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN);
|
|
|
|
if (!module) return FALSE;
|
|
|
|
return module_remove(pcs, module);
|
|
|
|
}
|
|
|
|
|
2005-11-29 11:35:10 +01:00
|
|
|
/******************************************************************
|
|
|
|
* SymUnloadModule64 (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymUnloadModule64(HANDLE hProcess, DWORD64 BaseOfDll)
|
|
|
|
{
|
|
|
|
struct process* pcs;
|
|
|
|
struct module* module;
|
|
|
|
|
|
|
|
pcs = process_find_by_handle(hProcess);
|
|
|
|
if (!pcs) return FALSE;
|
|
|
|
if (!validate_addr64(BaseOfDll)) return FALSE;
|
2012-01-22 13:00:57 +01:00
|
|
|
module = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN);
|
2005-11-29 11:35:10 +01:00
|
|
|
if (!module) return FALSE;
|
|
|
|
return module_remove(pcs, module);
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SymEnumerateModules (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
2007-03-13 17:26:39 +01:00
|
|
|
struct enum_modW64_32
|
|
|
|
{
|
|
|
|
PSYM_ENUMMODULES_CALLBACK cb;
|
|
|
|
PVOID user;
|
|
|
|
char module[MAX_PATH];
|
|
|
|
};
|
|
|
|
|
2007-08-03 00:51:09 +02:00
|
|
|
static BOOL CALLBACK enum_modW64_32(PCWSTR name, DWORD64 base, PVOID user)
|
2007-03-13 17:26:39 +01:00
|
|
|
{
|
|
|
|
struct enum_modW64_32* x = user;
|
|
|
|
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, name, -1, x->module, sizeof(x->module), NULL, NULL);
|
|
|
|
return x->cb(x->module, (DWORD)base, x->user);
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
BOOL WINAPI SymEnumerateModules(HANDLE hProcess,
|
|
|
|
PSYM_ENUMMODULES_CALLBACK EnumModulesCallback,
|
|
|
|
PVOID UserContext)
|
|
|
|
{
|
2007-03-13 17:26:39 +01:00
|
|
|
struct enum_modW64_32 x;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2007-03-13 17:26:39 +01:00
|
|
|
x.cb = EnumModulesCallback;
|
|
|
|
x.user = UserContext;
|
|
|
|
|
|
|
|
return SymEnumerateModulesW64(hProcess, enum_modW64_32, &x);
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
|
2006-06-26 21:37:36 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SymEnumerateModules64 (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
2007-03-13 17:26:39 +01:00
|
|
|
struct enum_modW64_64
|
|
|
|
{
|
|
|
|
PSYM_ENUMMODULES_CALLBACK64 cb;
|
|
|
|
PVOID user;
|
|
|
|
char module[MAX_PATH];
|
|
|
|
};
|
|
|
|
|
2007-08-03 00:51:09 +02:00
|
|
|
static BOOL CALLBACK enum_modW64_64(PCWSTR name, DWORD64 base, PVOID user)
|
2007-03-13 17:26:39 +01:00
|
|
|
{
|
|
|
|
struct enum_modW64_64* x = user;
|
|
|
|
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, name, -1, x->module, sizeof(x->module), NULL, NULL);
|
|
|
|
return x->cb(x->module, base, x->user);
|
|
|
|
}
|
|
|
|
|
2006-06-26 21:37:36 +02:00
|
|
|
BOOL WINAPI SymEnumerateModules64(HANDLE hProcess,
|
|
|
|
PSYM_ENUMMODULES_CALLBACK64 EnumModulesCallback,
|
|
|
|
PVOID UserContext)
|
2007-03-13 17:26:39 +01:00
|
|
|
{
|
|
|
|
struct enum_modW64_64 x;
|
|
|
|
|
|
|
|
x.cb = EnumModulesCallback;
|
|
|
|
x.user = UserContext;
|
|
|
|
|
|
|
|
return SymEnumerateModulesW64(hProcess, enum_modW64_64, &x);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymEnumerateModulesW64 (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymEnumerateModulesW64(HANDLE hProcess,
|
|
|
|
PSYM_ENUMMODULES_CALLBACKW64 EnumModulesCallback,
|
|
|
|
PVOID UserContext)
|
2006-06-26 21:37:36 +02:00
|
|
|
{
|
|
|
|
struct process* pcs = process_find_by_handle(hProcess);
|
|
|
|
struct module* module;
|
|
|
|
|
|
|
|
if (!pcs) return FALSE;
|
|
|
|
|
|
|
|
for (module = pcs->lmodules; module; module = module->next)
|
|
|
|
{
|
2019-06-07 01:44:31 +02:00
|
|
|
if (!dbghelp_opt_native &&
|
2009-03-13 17:48:00 +01:00
|
|
|
(module->type == DMT_ELF || module->type == DMT_MACHO))
|
2006-06-26 21:37:36 +02:00
|
|
|
continue;
|
2018-01-31 16:40:44 +01:00
|
|
|
if (!EnumModulesCallback(module->modulename,
|
2006-06-26 21:37:36 +02:00
|
|
|
module->module.BaseOfImage, UserContext))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/******************************************************************
|
2007-01-02 14:24:10 +01:00
|
|
|
* EnumerateLoadedModules64 (DBGHELP.@)
|
2004-04-06 00:21:27 +02:00
|
|
|
*
|
|
|
|
*/
|
2007-02-21 21:54:44 +01:00
|
|
|
struct enum_load_modW64_64
|
|
|
|
{
|
|
|
|
PENUMLOADED_MODULES_CALLBACK64 cb;
|
|
|
|
PVOID user;
|
|
|
|
char module[MAX_PATH];
|
|
|
|
};
|
|
|
|
|
2007-08-03 00:51:09 +02:00
|
|
|
static BOOL CALLBACK enum_load_modW64_64(PCWSTR name, DWORD64 base, ULONG size,
|
2007-02-21 21:54:44 +01:00
|
|
|
PVOID user)
|
|
|
|
{
|
|
|
|
struct enum_load_modW64_64* x = user;
|
|
|
|
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, name, -1, x->module, sizeof(x->module), NULL, NULL);
|
|
|
|
return x->cb(x->module, base, size, x->user);
|
|
|
|
}
|
|
|
|
|
2007-01-02 14:24:10 +01:00
|
|
|
BOOL WINAPI EnumerateLoadedModules64(HANDLE hProcess,
|
|
|
|
PENUMLOADED_MODULES_CALLBACK64 EnumLoadedModulesCallback,
|
|
|
|
PVOID UserContext)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2007-02-21 21:54:44 +01:00
|
|
|
struct enum_load_modW64_64 x;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2007-02-21 21:54:44 +01:00
|
|
|
x.cb = EnumLoadedModulesCallback;
|
|
|
|
x.user = UserContext;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2007-02-21 21:54:44 +01:00
|
|
|
return EnumerateLoadedModulesW64(hProcess, enum_load_modW64_64, &x);
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
|
2007-01-02 14:24:10 +01:00
|
|
|
/******************************************************************
|
|
|
|
* EnumerateLoadedModules (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
2007-02-21 21:54:44 +01:00
|
|
|
struct enum_load_modW64_32
|
2007-01-02 14:24:10 +01:00
|
|
|
{
|
|
|
|
PENUMLOADED_MODULES_CALLBACK cb;
|
|
|
|
PVOID user;
|
2007-02-21 21:54:44 +01:00
|
|
|
char module[MAX_PATH];
|
2007-01-02 14:24:10 +01:00
|
|
|
};
|
|
|
|
|
2007-08-03 00:51:09 +02:00
|
|
|
static BOOL CALLBACK enum_load_modW64_32(PCWSTR name, DWORD64 base, ULONG size,
|
2007-02-21 21:54:44 +01:00
|
|
|
PVOID user)
|
2007-01-02 14:24:10 +01:00
|
|
|
{
|
2007-02-21 21:54:44 +01:00
|
|
|
struct enum_load_modW64_32* x = user;
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, name, -1, x->module, sizeof(x->module), NULL, NULL);
|
|
|
|
return x->cb(x->module, (DWORD)base, size, x->user);
|
2007-01-02 14:24:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI EnumerateLoadedModules(HANDLE hProcess,
|
|
|
|
PENUMLOADED_MODULES_CALLBACK EnumLoadedModulesCallback,
|
|
|
|
PVOID UserContext)
|
|
|
|
{
|
2007-02-21 21:54:44 +01:00
|
|
|
struct enum_load_modW64_32 x;
|
2007-01-02 14:24:10 +01:00
|
|
|
|
|
|
|
x.cb = EnumLoadedModulesCallback;
|
|
|
|
x.user = UserContext;
|
|
|
|
|
2007-02-21 21:54:44 +01:00
|
|
|
return EnumerateLoadedModulesW64(hProcess, enum_load_modW64_32, &x);
|
2007-01-02 14:24:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* EnumerateLoadedModulesW64 (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI EnumerateLoadedModulesW64(HANDLE hProcess,
|
|
|
|
PENUMLOADED_MODULES_CALLBACKW64 EnumLoadedModulesCallback,
|
|
|
|
PVOID UserContext)
|
|
|
|
{
|
2007-02-21 21:54:44 +01:00
|
|
|
HMODULE* hMods;
|
2007-02-21 21:55:04 +01:00
|
|
|
WCHAR baseW[256], modW[256];
|
2007-02-21 21:54:44 +01:00
|
|
|
DWORD i, sz;
|
|
|
|
MODULEINFO mi;
|
2007-01-02 14:24:10 +01:00
|
|
|
|
2007-02-21 21:54:44 +01:00
|
|
|
hMods = HeapAlloc(GetProcessHeap(), 0, 256 * sizeof(hMods[0]));
|
|
|
|
if (!hMods) return FALSE;
|
2007-01-02 14:24:10 +01:00
|
|
|
|
2007-02-21 21:54:44 +01:00
|
|
|
if (!EnumProcessModules(hProcess, hMods, 256 * sizeof(hMods[0]), &sz))
|
|
|
|
{
|
|
|
|
/* hProcess should also be a valid process handle !! */
|
|
|
|
FIXME("If this happens, bump the number in mod\n");
|
|
|
|
HeapFree(GetProcessHeap(), 0, hMods);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
sz /= sizeof(HMODULE);
|
|
|
|
for (i = 0; i < sz; i++)
|
|
|
|
{
|
|
|
|
if (!GetModuleInformation(hProcess, hMods[i], &mi, sizeof(mi)) ||
|
2018-07-12 23:49:34 +02:00
|
|
|
!GetModuleBaseNameW(hProcess, hMods[i], baseW, ARRAY_SIZE(baseW)))
|
2007-02-21 21:54:44 +01:00
|
|
|
continue;
|
2018-07-12 23:49:34 +02:00
|
|
|
module_fill_module(baseW, modW, ARRAY_SIZE(modW));
|
2007-02-21 21:54:44 +01:00
|
|
|
EnumLoadedModulesCallback(modW, (DWORD_PTR)mi.lpBaseOfDll, mi.SizeOfImage,
|
|
|
|
UserContext);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, hMods);
|
|
|
|
|
|
|
|
return sz != 0 && i == sz;
|
2007-01-02 14:24:10 +01:00
|
|
|
}
|
|
|
|
|
2018-01-30 14:46:29 +01:00
|
|
|
static void dbghelp_str_WtoA(const WCHAR *src, char *dst, int dst_len)
|
|
|
|
{
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, src, -1, dst, dst_len - 1, NULL, NULL);
|
|
|
|
dst[dst_len - 1] = 0;
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SymGetModuleInfo (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
2007-02-21 21:54:49 +01:00
|
|
|
BOOL WINAPI SymGetModuleInfo(HANDLE hProcess, DWORD dwAddr,
|
2004-04-06 00:21:27 +02:00
|
|
|
PIMAGEHLP_MODULE ModuleInfo)
|
|
|
|
{
|
2007-02-21 21:54:49 +01:00
|
|
|
IMAGEHLP_MODULE mi;
|
|
|
|
IMAGEHLP_MODULEW64 miw64;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2007-02-21 21:54:49 +01:00
|
|
|
if (sizeof(mi) < ModuleInfo->SizeOfStruct) FIXME("Wrong size\n");
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2007-02-21 21:54:49 +01:00
|
|
|
miw64.SizeOfStruct = sizeof(miw64);
|
|
|
|
if (!SymGetModuleInfoW64(hProcess, dwAddr, &miw64)) return FALSE;
|
|
|
|
|
2018-01-30 14:46:28 +01:00
|
|
|
mi.SizeOfStruct = ModuleInfo->SizeOfStruct;
|
2007-02-21 21:54:49 +01:00
|
|
|
mi.BaseOfImage = miw64.BaseOfImage;
|
|
|
|
mi.ImageSize = miw64.ImageSize;
|
|
|
|
mi.TimeDateStamp = miw64.TimeDateStamp;
|
|
|
|
mi.CheckSum = miw64.CheckSum;
|
|
|
|
mi.NumSyms = miw64.NumSyms;
|
|
|
|
mi.SymType = miw64.SymType;
|
2018-01-30 14:46:29 +01:00
|
|
|
dbghelp_str_WtoA(miw64.ModuleName, mi.ModuleName, sizeof(mi.ModuleName));
|
|
|
|
dbghelp_str_WtoA(miw64.ImageName, mi.ImageName, sizeof(mi.ImageName));
|
|
|
|
dbghelp_str_WtoA(miw64.LoadedImageName, mi.LoadedImageName, sizeof(mi.LoadedImageName));
|
2007-02-21 21:54:49 +01:00
|
|
|
|
|
|
|
memcpy(ModuleInfo, &mi, ModuleInfo->SizeOfStruct);
|
2006-06-26 21:37:32 +02:00
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-05-10 21:35:18 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SymGetModuleInfoW (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
2007-02-21 21:54:49 +01:00
|
|
|
BOOL WINAPI SymGetModuleInfoW(HANDLE hProcess, DWORD dwAddr,
|
2006-05-10 21:35:18 +02:00
|
|
|
PIMAGEHLP_MODULEW ModuleInfo)
|
|
|
|
{
|
2007-02-21 21:54:49 +01:00
|
|
|
IMAGEHLP_MODULEW64 miw64;
|
2006-05-10 21:35:18 +02:00
|
|
|
IMAGEHLP_MODULEW miw;
|
|
|
|
|
|
|
|
if (sizeof(miw) < ModuleInfo->SizeOfStruct) FIXME("Wrong size\n");
|
|
|
|
|
2007-02-21 21:54:49 +01:00
|
|
|
miw64.SizeOfStruct = sizeof(miw64);
|
|
|
|
if (!SymGetModuleInfoW64(hProcess, dwAddr, &miw64)) return FALSE;
|
|
|
|
|
2018-01-30 14:46:28 +01:00
|
|
|
miw.SizeOfStruct = ModuleInfo->SizeOfStruct;
|
2007-02-21 21:54:49 +01:00
|
|
|
miw.BaseOfImage = miw64.BaseOfImage;
|
|
|
|
miw.ImageSize = miw64.ImageSize;
|
|
|
|
miw.TimeDateStamp = miw64.TimeDateStamp;
|
|
|
|
miw.CheckSum = miw64.CheckSum;
|
|
|
|
miw.NumSyms = miw64.NumSyms;
|
|
|
|
miw.SymType = miw64.SymType;
|
2020-04-06 19:43:35 +02:00
|
|
|
lstrcpyW(miw.ModuleName, miw64.ModuleName);
|
|
|
|
lstrcpyW(miw.ImageName, miw64.ImageName);
|
|
|
|
lstrcpyW(miw.LoadedImageName, miw64.LoadedImageName);
|
2006-05-10 21:35:18 +02:00
|
|
|
memcpy(ModuleInfo, &miw, ModuleInfo->SizeOfStruct);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-11-29 11:42:13 +01:00
|
|
|
/******************************************************************
|
|
|
|
* SymGetModuleInfo64 (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
2007-02-21 21:54:49 +01:00
|
|
|
BOOL WINAPI SymGetModuleInfo64(HANDLE hProcess, DWORD64 dwAddr,
|
2005-11-29 11:42:13 +01:00
|
|
|
PIMAGEHLP_MODULE64 ModuleInfo)
|
2007-02-21 21:54:49 +01:00
|
|
|
{
|
|
|
|
IMAGEHLP_MODULE64 mi64;
|
|
|
|
IMAGEHLP_MODULEW64 miw64;
|
|
|
|
|
2008-05-25 12:02:26 +02:00
|
|
|
if (sizeof(mi64) < ModuleInfo->SizeOfStruct)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_MOD_NOT_FOUND); /* NOTE: native returns this error */
|
|
|
|
WARN("Wrong size %u\n", ModuleInfo->SizeOfStruct);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-02-21 21:54:49 +01:00
|
|
|
|
|
|
|
miw64.SizeOfStruct = sizeof(miw64);
|
|
|
|
if (!SymGetModuleInfoW64(hProcess, dwAddr, &miw64)) return FALSE;
|
|
|
|
|
2018-01-30 14:46:28 +01:00
|
|
|
mi64.SizeOfStruct = ModuleInfo->SizeOfStruct;
|
2007-02-21 21:54:49 +01:00
|
|
|
mi64.BaseOfImage = miw64.BaseOfImage;
|
|
|
|
mi64.ImageSize = miw64.ImageSize;
|
|
|
|
mi64.TimeDateStamp = miw64.TimeDateStamp;
|
|
|
|
mi64.CheckSum = miw64.CheckSum;
|
|
|
|
mi64.NumSyms = miw64.NumSyms;
|
|
|
|
mi64.SymType = miw64.SymType;
|
2018-01-30 14:46:29 +01:00
|
|
|
dbghelp_str_WtoA(miw64.ModuleName, mi64.ModuleName, sizeof(mi64.ModuleName));
|
|
|
|
dbghelp_str_WtoA(miw64.ImageName, mi64.ImageName, sizeof(mi64.ImageName));
|
|
|
|
dbghelp_str_WtoA(miw64.LoadedImageName, mi64.LoadedImageName, sizeof(mi64.LoadedImageName));
|
|
|
|
dbghelp_str_WtoA(miw64.LoadedPdbName, mi64.LoadedPdbName, sizeof(mi64.LoadedPdbName));
|
2007-02-21 21:54:49 +01:00
|
|
|
|
|
|
|
mi64.CVSig = miw64.CVSig;
|
2018-01-30 14:46:29 +01:00
|
|
|
dbghelp_str_WtoA(miw64.CVData, mi64.CVData, sizeof(mi64.CVData));
|
2007-02-21 21:54:49 +01:00
|
|
|
mi64.PdbSig = miw64.PdbSig;
|
|
|
|
mi64.PdbSig70 = miw64.PdbSig70;
|
|
|
|
mi64.PdbAge = miw64.PdbAge;
|
|
|
|
mi64.PdbUnmatched = miw64.PdbUnmatched;
|
|
|
|
mi64.DbgUnmatched = miw64.DbgUnmatched;
|
|
|
|
mi64.LineNumbers = miw64.LineNumbers;
|
|
|
|
mi64.GlobalSymbols = miw64.GlobalSymbols;
|
|
|
|
mi64.TypeInfo = miw64.TypeInfo;
|
|
|
|
mi64.SourceIndexed = miw64.SourceIndexed;
|
|
|
|
mi64.Publics = miw64.Publics;
|
2021-07-17 00:17:39 +02:00
|
|
|
mi64.MachineType = miw64.MachineType;
|
|
|
|
mi64.Reserved = miw64.Reserved;
|
2007-02-21 21:54:49 +01:00
|
|
|
|
|
|
|
memcpy(ModuleInfo, &mi64, ModuleInfo->SizeOfStruct);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymGetModuleInfoW64 (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymGetModuleInfoW64(HANDLE hProcess, DWORD64 dwAddr,
|
|
|
|
PIMAGEHLP_MODULEW64 ModuleInfo)
|
2005-11-29 11:42:13 +01:00
|
|
|
{
|
|
|
|
struct process* pcs = process_find_by_handle(hProcess);
|
|
|
|
struct module* module;
|
2007-02-21 21:54:49 +01:00
|
|
|
IMAGEHLP_MODULEW64 miw64;
|
2005-11-29 11:42:13 +01:00
|
|
|
|
|
|
|
TRACE("%p %s %p\n", hProcess, wine_dbgstr_longlong(dwAddr), ModuleInfo);
|
|
|
|
|
|
|
|
if (!pcs) return FALSE;
|
|
|
|
if (ModuleInfo->SizeOfStruct > sizeof(*ModuleInfo)) return FALSE;
|
|
|
|
module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
|
|
|
|
if (!module) return FALSE;
|
|
|
|
|
2007-02-21 21:55:04 +01:00
|
|
|
miw64 = module->module;
|
2005-11-29 11:42:13 +01:00
|
|
|
|
2007-02-21 21:55:04 +01:00
|
|
|
/* update debug information from container if any */
|
2005-11-29 11:42:13 +01:00
|
|
|
if (module->module.SymType == SymNone)
|
|
|
|
{
|
|
|
|
module = module_get_container(pcs, module);
|
|
|
|
if (module && module->module.SymType != SymNone)
|
2006-01-23 16:38:57 +01:00
|
|
|
{
|
2007-02-21 21:54:49 +01:00
|
|
|
miw64.SymType = module->module.SymType;
|
|
|
|
miw64.NumSyms = module->module.NumSyms;
|
2006-01-23 16:38:57 +01:00
|
|
|
}
|
2005-11-29 11:42:13 +01:00
|
|
|
}
|
2007-02-21 21:54:49 +01:00
|
|
|
memcpy(ModuleInfo, &miw64, ModuleInfo->SizeOfStruct);
|
2006-05-10 21:35:18 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/***********************************************************************
|
2006-01-05 13:41:25 +01:00
|
|
|
* SymGetModuleBase (DBGHELP.@)
|
2004-04-06 00:21:27 +02:00
|
|
|
*/
|
|
|
|
DWORD WINAPI SymGetModuleBase(HANDLE hProcess, DWORD dwAddr)
|
|
|
|
{
|
2010-03-27 09:09:02 +01:00
|
|
|
DWORD64 ret;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2010-03-27 09:09:02 +01:00
|
|
|
ret = SymGetModuleBase64(hProcess, dwAddr);
|
|
|
|
return validate_addr64(ret) ? ret : 0;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
2004-07-04 02:10:54 +02:00
|
|
|
|
2006-01-05 13:41:25 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SymGetModuleBase64 (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
DWORD64 WINAPI SymGetModuleBase64(HANDLE hProcess, DWORD64 dwAddr)
|
|
|
|
{
|
2010-03-27 09:09:02 +01:00
|
|
|
struct process* pcs = process_find_by_handle(hProcess);
|
|
|
|
struct module* module;
|
|
|
|
|
|
|
|
if (!pcs) return 0;
|
|
|
|
module = module_find_by_addr(pcs, dwAddr, DMT_UNKNOWN);
|
|
|
|
if (!module) return 0;
|
|
|
|
return module->module.BaseOfImage;
|
2006-01-05 13:41:25 +01:00
|
|
|
}
|
|
|
|
|
2004-07-04 02:10:54 +02:00
|
|
|
/******************************************************************
|
|
|
|
* module_reset_debug_info
|
|
|
|
* Removes any debug information linked to a given module.
|
|
|
|
*/
|
|
|
|
void module_reset_debug_info(struct module* module)
|
|
|
|
{
|
|
|
|
module->sortlist_valid = TRUE;
|
2009-07-10 14:46:55 +02:00
|
|
|
module->sorttab_size = 0;
|
2004-07-04 02:10:54 +02:00
|
|
|
module->addr_sorttab = NULL;
|
2009-06-25 22:27:38 +02:00
|
|
|
module->num_sorttab = module->num_symbols = 0;
|
2004-07-04 02:10:54 +02:00
|
|
|
hash_table_destroy(&module->ht_symbols);
|
|
|
|
module->ht_symbols.num_buckets = 0;
|
|
|
|
module->ht_symbols.buckets = NULL;
|
|
|
|
hash_table_destroy(&module->ht_types);
|
|
|
|
module->ht_types.num_buckets = 0;
|
|
|
|
module->ht_types.buckets = NULL;
|
2004-09-27 22:31:42 +02:00
|
|
|
module->vtypes.num_elts = 0;
|
2004-07-04 02:10:54 +02:00
|
|
|
hash_table_destroy(&module->ht_symbols);
|
|
|
|
module->sources_used = module->sources_alloc = 0;
|
|
|
|
module->sources = NULL;
|
|
|
|
}
|
2009-11-16 02:02:48 +01:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymRefreshModuleList (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymRefreshModuleList(HANDLE hProcess)
|
|
|
|
{
|
2009-11-16 21:27:08 +01:00
|
|
|
struct process* pcs;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", hProcess);
|
|
|
|
|
|
|
|
if (!(pcs = process_find_by_handle(hProcess))) return FALSE;
|
|
|
|
|
2020-03-24 01:54:07 +01:00
|
|
|
return pcs->loader->synchronize_module_list(pcs);
|
2009-11-16 02:02:48 +01:00
|
|
|
}
|
2010-03-20 09:47:24 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SymFunctionTableAccess (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
PVOID WINAPI SymFunctionTableAccess(HANDLE hProcess, DWORD AddrBase)
|
|
|
|
{
|
|
|
|
return SymFunctionTableAccess64(hProcess, AddrBase);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SymFunctionTableAccess64 (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
PVOID WINAPI SymFunctionTableAccess64(HANDLE hProcess, DWORD64 AddrBase)
|
|
|
|
{
|
|
|
|
struct process* pcs = process_find_by_handle(hProcess);
|
|
|
|
struct module* module;
|
|
|
|
|
|
|
|
if (!pcs || !dbghelp_current_cpu->find_runtime_function) return NULL;
|
|
|
|
module = module_find_by_addr(pcs, AddrBase, DMT_UNKNOWN);
|
|
|
|
if (!module) return NULL;
|
|
|
|
|
|
|
|
return dbghelp_current_cpu->find_runtime_function(module, AddrBase);
|
|
|
|
}
|
2020-03-24 01:54:07 +01:00
|
|
|
|
|
|
|
static BOOL native_synchronize_module_list(struct process* pcs)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-03-26 16:51:49 +01:00
|
|
|
static struct module* native_load_module(struct process* pcs, const WCHAR* name, ULONG_PTR addr)
|
2020-03-25 17:40:59 +01:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-03-25 17:41:16 +01:00
|
|
|
static BOOL native_load_debug_info(struct process* process, struct module* module)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-03-25 17:40:45 +01:00
|
|
|
static BOOL native_enum_modules(struct process *process, enum_modules_cb cb, void* user)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-03-24 01:54:36 +01:00
|
|
|
static BOOL native_fetch_file_info(struct process* process, const WCHAR* name, ULONG_PTR load_addr, DWORD_PTR* base,
|
|
|
|
DWORD* size, DWORD* checksum)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-03-24 01:54:07 +01:00
|
|
|
const struct loader_ops no_loader_ops =
|
|
|
|
{
|
|
|
|
native_synchronize_module_list,
|
2020-03-25 17:40:59 +01:00
|
|
|
native_load_module,
|
2020-03-25 17:41:16 +01:00
|
|
|
native_load_debug_info,
|
2020-03-25 17:40:45 +01:00
|
|
|
native_enum_modules,
|
2020-03-24 01:54:36 +01:00
|
|
|
native_fetch_file_info,
|
2020-03-24 01:54:07 +01:00
|
|
|
};
|