2004-04-06 00:21:27 +02:00
|
|
|
/*
|
|
|
|
* File dbghelp.c - generic routines (process) for dbghelp DLL
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004, Eric Pouech
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
|
|
|
|
2019-08-02 01:53:58 +02:00
|
|
|
#include <unistd.h>
|
2004-04-06 00:21:27 +02:00
|
|
|
#include "dbghelp_private.h"
|
2019-08-02 01:53:58 +02:00
|
|
|
#include "winternl.h"
|
2004-04-06 00:21:27 +02:00
|
|
|
#include "winerror.h"
|
|
|
|
#include "psapi.h"
|
|
|
|
#include "wine/debug.h"
|
2005-12-20 11:49:24 +01:00
|
|
|
#include "wdbgexts.h"
|
2006-05-10 21:35:07 +02:00
|
|
|
#include "winnls.h"
|
2004-04-06 00:21:27 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
|
|
|
|
|
|
|
|
/* TODO
|
|
|
|
* - support for symbols' types is still partly missing
|
|
|
|
* + C++ support
|
2004-04-19 04:58:27 +02:00
|
|
|
* + we should store the underlying type for an enum in the symt_enum struct
|
2004-11-19 19:02:47 +01:00
|
|
|
* + for enums, we store the names & values (associated to the enum type),
|
|
|
|
* but those values are not directly usable from a debugger (that's why, I
|
|
|
|
* assume, that we have also to define constants for enum values, as
|
|
|
|
* Codeview does BTW.
|
2005-11-18 13:05:44 +01:00
|
|
|
* + SymEnumTypes should only return *user* defined types (UDT, typedefs...) not
|
|
|
|
* all the types stored/used in the modules (like char*)
|
2005-03-01 11:39:49 +01:00
|
|
|
* - SymGetLine{Next|Prev} don't work as expected (they don't seem to work across
|
|
|
|
* functions, and even across function blocks...). Basically, for *Next* to work
|
|
|
|
* it requires an address after the prolog of the func (the base address of the
|
|
|
|
* func doesn't work)
|
2004-11-19 19:02:47 +01:00
|
|
|
* - most options (dbghelp_options) are not used (loading lines...)
|
2004-05-24 21:08:19 +02:00
|
|
|
* - in symbol lookup by name, we don't use RE everywhere we should. Moreover, when
|
|
|
|
* we're supposed to use RE, it doesn't make use of our hash tables. Therefore,
|
|
|
|
* we could use hash if name isn't a RE, and fall back to a full search when we
|
|
|
|
* get a full RE
|
2004-04-06 00:21:27 +02:00
|
|
|
* - msc:
|
2004-04-19 04:58:27 +02:00
|
|
|
* + we should add parameters' types to the function's signature
|
|
|
|
* while processing a function's parameters
|
2005-03-01 11:39:49 +01:00
|
|
|
* + add support for function-less labels (as MSC seems to define them)
|
2004-04-06 00:21:27 +02:00
|
|
|
* + C++ management
|
|
|
|
* - stabs:
|
2004-08-30 21:31:13 +02:00
|
|
|
* + when, in a same module, the same definition is used in several compilation
|
|
|
|
* units, we get several definitions of the same object (especially
|
|
|
|
* struct/union). we should find a way not to duplicate them
|
|
|
|
* + in some cases (dlls/user/dialog16.c DIALOG_GetControl16), the same static
|
|
|
|
* global variable is defined several times (at different scopes). We are
|
|
|
|
* getting several of those while looking for a unique symbol. Part of the
|
|
|
|
* issue is that we don't give a scope to a static variable inside a function
|
2004-04-06 00:21:27 +02:00
|
|
|
* + C++ management
|
|
|
|
*/
|
|
|
|
|
|
|
|
unsigned dbghelp_options = SYMOPT_UNDNAME;
|
2019-06-07 01:44:30 +02:00
|
|
|
BOOL dbghelp_opt_native = FALSE;
|
2020-03-20 18:09:12 +01:00
|
|
|
SYSTEM_INFO sysinfo;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
|
|
|
static struct process* process_first /* = NULL */;
|
|
|
|
|
2020-03-20 18:09:12 +01:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
|
|
|
|
{
|
|
|
|
switch (reason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
GetSystemInfo(&sysinfo);
|
|
|
|
DisableThreadLibraryCalls(instance);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/******************************************************************
|
|
|
|
* process_find_by_handle
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct process* process_find_by_handle(HANDLE hProcess)
|
|
|
|
{
|
|
|
|
struct process* p;
|
|
|
|
|
|
|
|
for (p = process_first; p && p->handle != hProcess; p = p->next);
|
|
|
|
if (!p) SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2005-11-29 11:24:46 +01:00
|
|
|
/******************************************************************
|
|
|
|
* validate_addr64 (internal)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL validate_addr64(DWORD64 addr)
|
|
|
|
{
|
2009-12-12 12:18:50 +01:00
|
|
|
if (sizeof(void*) == sizeof(int) && (addr >> 32))
|
2005-11-29 11:24:46 +01:00
|
|
|
{
|
|
|
|
FIXME("Unsupported address %s\n", wine_dbgstr_longlong(addr));
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-05-10 21:35:26 +02:00
|
|
|
/******************************************************************
|
|
|
|
* fetch_buffer
|
|
|
|
*
|
|
|
|
* Ensures process' internal buffer is large enough.
|
|
|
|
*/
|
|
|
|
void* fetch_buffer(struct process* pcs, unsigned size)
|
|
|
|
{
|
|
|
|
if (size > pcs->buffer_size)
|
|
|
|
{
|
|
|
|
if (pcs->buffer)
|
|
|
|
pcs->buffer = HeapReAlloc(GetProcessHeap(), 0, pcs->buffer, size);
|
|
|
|
else
|
|
|
|
pcs->buffer = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
pcs->buffer_size = (pcs->buffer) ? size : 0;
|
|
|
|
}
|
|
|
|
return pcs->buffer;
|
|
|
|
}
|
|
|
|
|
2009-12-22 14:20:59 +01:00
|
|
|
const char* wine_dbgstr_addr(const ADDRESS64* addr)
|
|
|
|
{
|
|
|
|
if (!addr) return "(null)";
|
|
|
|
switch (addr->Mode)
|
|
|
|
{
|
|
|
|
case AddrModeFlat:
|
|
|
|
return wine_dbg_sprintf("flat<%s>", wine_dbgstr_longlong(addr->Offset));
|
|
|
|
case AddrMode1616:
|
2022-02-09 09:26:26 +01:00
|
|
|
return wine_dbg_sprintf("1616<%04x:%04lx>", addr->Segment, (DWORD)addr->Offset);
|
2009-12-22 14:20:59 +01:00
|
|
|
case AddrMode1632:
|
2022-02-09 09:26:26 +01:00
|
|
|
return wine_dbg_sprintf("1632<%04x:%08lx>", addr->Segment, (DWORD)addr->Offset);
|
2009-12-22 14:20:59 +01:00
|
|
|
case AddrModeReal:
|
2022-02-09 09:26:26 +01:00
|
|
|
return wine_dbg_sprintf("real<%04x:%04lx>", addr->Segment, (DWORD)addr->Offset);
|
2009-12-22 14:20:59 +01:00
|
|
|
default:
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-17 15:11:28 +02:00
|
|
|
extern struct cpu cpu_i386, cpu_x86_64, cpu_arm, cpu_arm64;
|
2009-12-22 14:21:07 +01:00
|
|
|
|
2020-06-17 15:11:28 +02:00
|
|
|
static struct cpu* dbghelp_cpus[] = {&cpu_i386, &cpu_x86_64, &cpu_arm, &cpu_arm64, NULL};
|
2009-12-22 14:21:07 +01:00
|
|
|
struct cpu* dbghelp_current_cpu =
|
|
|
|
#if defined(__i386__)
|
|
|
|
&cpu_i386
|
2009-12-22 14:21:31 +01:00
|
|
|
#elif defined(__x86_64__)
|
|
|
|
&cpu_x86_64
|
2010-09-18 18:02:28 +02:00
|
|
|
#elif defined(__arm__)
|
|
|
|
&cpu_arm
|
2013-01-16 00:55:14 +01:00
|
|
|
#elif defined(__aarch64__)
|
|
|
|
&cpu_arm64
|
2009-12-22 14:21:07 +01:00
|
|
|
#else
|
2009-12-30 17:32:20 +01:00
|
|
|
#error define support for your CPU
|
2009-12-22 14:21:07 +01:00
|
|
|
#endif
|
|
|
|
;
|
|
|
|
|
|
|
|
struct cpu* cpu_find(DWORD machine)
|
|
|
|
{
|
|
|
|
struct cpu** cpu;
|
|
|
|
|
|
|
|
for (cpu = dbghelp_cpus ; *cpu; cpu++)
|
|
|
|
{
|
|
|
|
if (cpu[0]->machine == machine) return cpu[0];
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-11-13 00:11:48 +01:00
|
|
|
static WCHAR* make_default_search_path(void)
|
|
|
|
{
|
|
|
|
WCHAR* search_path;
|
2021-11-13 00:17:53 +01:00
|
|
|
WCHAR* p;
|
|
|
|
unsigned sym_path_len;
|
|
|
|
unsigned alt_sym_path_len;
|
|
|
|
|
|
|
|
sym_path_len = GetEnvironmentVariableW(L"_NT_SYMBOL_PATH", NULL, 0);
|
2021-11-13 02:17:01 +01:00
|
|
|
alt_sym_path_len = GetEnvironmentVariableW(L"_NT_ALT_SYMBOL_PATH", NULL, 0);
|
2021-11-13 00:17:53 +01:00
|
|
|
|
2021-11-13 02:17:01 +01:00
|
|
|
/* The default symbol path is ".[;%_NT_SYMBOL_PATH%][;%_NT_ALT_SYMBOL_PATH%]".
|
2021-11-13 00:17:53 +01:00
|
|
|
* If the variables exist, the lengths include a null-terminator. We use that
|
|
|
|
* space for the semicolons, and only add the initial dot and the final null. */
|
|
|
|
search_path = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
(1 + sym_path_len + alt_sym_path_len + 1) * sizeof(WCHAR));
|
|
|
|
if (!search_path) return NULL;
|
|
|
|
|
|
|
|
p = search_path;
|
|
|
|
*p++ = L'.';
|
|
|
|
if (sym_path_len)
|
2021-11-13 00:11:48 +01:00
|
|
|
{
|
2021-11-13 00:17:53 +01:00
|
|
|
*p++ = L';';
|
|
|
|
GetEnvironmentVariableW(L"_NT_SYMBOL_PATH", p, sym_path_len);
|
|
|
|
p += sym_path_len - 1;
|
2021-11-13 00:11:48 +01:00
|
|
|
}
|
2021-11-13 00:17:53 +01:00
|
|
|
|
|
|
|
if (alt_sym_path_len)
|
2021-11-13 00:11:48 +01:00
|
|
|
{
|
2021-11-13 00:17:53 +01:00
|
|
|
*p++ = L';';
|
2021-11-13 02:17:01 +01:00
|
|
|
GetEnvironmentVariableW(L"_NT_ALT_SYMBOL_PATH", p, alt_sym_path_len);
|
2021-11-13 00:17:53 +01:00
|
|
|
p += alt_sym_path_len - 1;
|
2021-11-13 00:11:48 +01:00
|
|
|
}
|
2021-11-13 00:17:53 +01:00
|
|
|
*p = L'\0';
|
2021-11-13 00:11:48 +01:00
|
|
|
|
|
|
|
return search_path;
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/******************************************************************
|
2006-05-10 21:35:07 +02:00
|
|
|
* SymSetSearchPathW (DBGHELP.@)
|
2004-04-06 00:21:27 +02:00
|
|
|
*
|
|
|
|
*/
|
2006-05-10 21:35:07 +02:00
|
|
|
BOOL WINAPI SymSetSearchPathW(HANDLE hProcess, PCWSTR searchPath)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
|
|
|
struct process* pcs = process_find_by_handle(hProcess);
|
2021-11-13 00:11:48 +01:00
|
|
|
WCHAR* search_path_buffer;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
|
|
|
if (!pcs) return FALSE;
|
|
|
|
|
2021-11-13 00:11:48 +01:00
|
|
|
if (searchPath)
|
|
|
|
{
|
|
|
|
search_path_buffer = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
(lstrlenW(searchPath) + 1) * sizeof(WCHAR));
|
|
|
|
if (!search_path_buffer) return FALSE;
|
|
|
|
lstrcpyW(search_path_buffer, searchPath);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
search_path_buffer = make_default_search_path();
|
|
|
|
if (!search_path_buffer) return FALSE;
|
|
|
|
}
|
2004-04-06 00:21:27 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, pcs->search_path);
|
2021-11-13 00:11:48 +01:00
|
|
|
pcs->search_path = search_path_buffer;
|
2004-04-06 00:21:27 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-05-10 21:35:07 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SymSetSearchPath (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymSetSearchPath(HANDLE hProcess, PCSTR searchPath)
|
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
unsigned len;
|
2021-11-13 00:11:48 +01:00
|
|
|
WCHAR* sp = NULL;
|
2006-05-10 21:35:07 +02:00
|
|
|
|
2021-11-13 00:11:48 +01:00
|
|
|
if (searchPath)
|
2006-05-10 21:35:07 +02:00
|
|
|
{
|
2021-11-13 00:11:48 +01:00
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, searchPath, -1, NULL, 0);
|
|
|
|
sp = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
if (!sp) return FALSE;
|
2006-05-10 21:35:07 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, searchPath, -1, sp, len);
|
|
|
|
}
|
2021-11-13 00:11:48 +01:00
|
|
|
|
|
|
|
ret = SymSetSearchPathW(hProcess, sp);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, sp);
|
2006-05-10 21:35:07 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/***********************************************************************
|
2006-05-10 21:35:07 +02:00
|
|
|
* SymGetSearchPathW (DBGHELP.@)
|
2004-04-06 00:21:27 +02:00
|
|
|
*/
|
2007-08-03 00:51:09 +02:00
|
|
|
BOOL WINAPI SymGetSearchPathW(HANDLE hProcess, PWSTR szSearchPath,
|
2006-05-10 21:35:07 +02:00
|
|
|
DWORD SearchPathLength)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
|
|
|
struct process* pcs = process_find_by_handle(hProcess);
|
|
|
|
if (!pcs) return FALSE;
|
|
|
|
|
2006-05-10 21:35:07 +02:00
|
|
|
lstrcpynW(szSearchPath, pcs->search_path, SearchPathLength);
|
2004-04-06 00:21:27 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-05-10 21:35:07 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SymGetSearchPath (DBGHELP.@)
|
|
|
|
*/
|
2007-08-03 00:51:09 +02:00
|
|
|
BOOL WINAPI SymGetSearchPath(HANDLE hProcess, PSTR szSearchPath,
|
2006-05-10 21:35:07 +02:00
|
|
|
DWORD SearchPathLength)
|
|
|
|
{
|
2007-02-21 21:56:01 +01:00
|
|
|
WCHAR* buffer = HeapAlloc(GetProcessHeap(), 0, SearchPathLength * sizeof(WCHAR));
|
2006-05-10 21:35:07 +02:00
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
if (buffer)
|
|
|
|
{
|
2007-02-21 21:56:01 +01:00
|
|
|
ret = SymGetSearchPathW(hProcess, buffer, SearchPathLength);
|
2006-05-10 21:35:07 +02:00
|
|
|
if (ret)
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, buffer, SearchPathLength,
|
|
|
|
szSearchPath, SearchPathLength, NULL, NULL);
|
|
|
|
HeapFree(GetProcessHeap(), 0, buffer);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/******************************************************************
|
|
|
|
* invade_process
|
|
|
|
*
|
|
|
|
* SymInitialize helper: loads in dbghelp all known (and loaded modules)
|
|
|
|
* this assumes that hProcess is a handle on a valid process
|
|
|
|
*/
|
2009-12-12 12:18:22 +01:00
|
|
|
static BOOL WINAPI process_invade_cb(PCWSTR name, ULONG64 base, ULONG size, PVOID user)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2009-12-12 12:18:22 +01:00
|
|
|
WCHAR tmp[MAX_PATH];
|
2007-12-04 22:45:11 +01:00
|
|
|
HANDLE hProcess = user;
|
2005-03-07 13:24:02 +01:00
|
|
|
|
2018-07-12 23:49:34 +02:00
|
|
|
if (!GetModuleFileNameExW(hProcess, (HMODULE)(DWORD_PTR)base, tmp, ARRAY_SIZE(tmp)))
|
|
|
|
lstrcpynW(tmp, name, ARRAY_SIZE(tmp));
|
2005-03-07 13:24:02 +01:00
|
|
|
|
2009-12-12 12:18:22 +01:00
|
|
|
SymLoadModuleExW(hProcess, 0, tmp, name, base, size, NULL, 0);
|
2005-03-01 11:39:49 +01:00
|
|
|
return TRUE;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
|
2020-04-09 19:59:57 +02:00
|
|
|
const WCHAR *process_getenv(const struct process *process, const WCHAR *name)
|
|
|
|
{
|
|
|
|
size_t name_len;
|
|
|
|
const WCHAR *iter;
|
|
|
|
|
|
|
|
if (!process->environment) return NULL;
|
|
|
|
name_len = lstrlenW(name);
|
|
|
|
|
|
|
|
for (iter = process->environment; *iter; iter += lstrlenW(iter) + 1)
|
|
|
|
{
|
|
|
|
if (!wcsnicmp(iter, name, name_len) && iter[name_len] == '=')
|
|
|
|
return iter + name_len + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-01-23 16:30:03 +01:00
|
|
|
/******************************************************************
|
|
|
|
* check_live_target
|
|
|
|
*
|
|
|
|
*/
|
2021-08-31 13:20:39 +02:00
|
|
|
static BOOL check_live_target(struct process* pcs, BOOL wow64, BOOL child_wow64)
|
2006-01-23 16:30:03 +01:00
|
|
|
{
|
2020-03-25 17:42:06 +01:00
|
|
|
PROCESS_BASIC_INFORMATION pbi;
|
2020-04-09 19:59:57 +02:00
|
|
|
ULONG_PTR base = 0, env = 0;
|
2020-03-25 17:42:06 +01:00
|
|
|
|
2006-01-23 16:30:03 +01:00
|
|
|
if (!GetProcessId(pcs->handle)) return FALSE;
|
2006-03-18 10:32:33 +01:00
|
|
|
if (GetEnvironmentVariableA("DBGHELP_NOLIVE", NULL, 0)) return FALSE;
|
2020-03-25 17:42:06 +01:00
|
|
|
|
|
|
|
if (NtQueryInformationProcess( pcs->handle, ProcessBasicInformation,
|
|
|
|
&pbi, sizeof(pbi), NULL ))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!pcs->is_64bit)
|
|
|
|
{
|
2021-08-31 13:20:39 +02:00
|
|
|
const char* peb32_addr;
|
2020-04-09 19:59:57 +02:00
|
|
|
DWORD env32;
|
|
|
|
PEB32 peb32;
|
2021-08-31 13:20:39 +02:00
|
|
|
|
2020-04-09 19:59:57 +02:00
|
|
|
C_ASSERT(sizeof(void*) != 4 || FIELD_OFFSET(RTL_USER_PROCESS_PARAMETERS, Environment) == 0x48);
|
2021-08-31 13:20:39 +02:00
|
|
|
peb32_addr = (const char*)pbi.PebBaseAddress;
|
|
|
|
if (!wow64 && child_wow64)
|
|
|
|
/* current process is 64bit, while child process is 32 bit, need to read 32bit PEB */
|
|
|
|
peb32_addr += 0x1000;
|
|
|
|
if (!ReadProcessMemory(pcs->handle, peb32_addr, &peb32, sizeof(peb32), NULL)) return FALSE;
|
|
|
|
if (!ReadProcessMemory(pcs->handle, peb32_addr + 0x460 /* CloudFileFlags */, &base, sizeof(base), NULL)) return FALSE;
|
2020-04-09 19:59:57 +02:00
|
|
|
if (read_process_memory(pcs, peb32.ProcessParameters + 0x48, &env32, sizeof(env32))) env = env32;
|
2020-03-25 17:42:06 +01:00
|
|
|
}
|
2020-04-09 19:59:57 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
PEB peb;
|
|
|
|
if (!ReadProcessMemory(pcs->handle, pbi.PebBaseAddress, &peb, sizeof(peb), NULL)) return FALSE;
|
2020-12-04 17:34:08 +01:00
|
|
|
if (!ReadProcessMemory(pcs->handle, (char *)pbi.PebBaseAddress + FIELD_OFFSET(PEB, CloudFileFlags), &base, sizeof(base), NULL)) return FALSE;
|
|
|
|
ReadProcessMemory(pcs->handle, (char *)peb.ProcessParameters + FIELD_OFFSET(RTL_USER_PROCESS_PARAMETERS, Environment), &env, sizeof(env), NULL);
|
2020-04-09 19:59:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* read debuggee environment block */
|
|
|
|
if (env)
|
|
|
|
{
|
|
|
|
size_t buf_size = 0, i, last_null = -1;
|
|
|
|
WCHAR *buf = NULL;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
size_t read_size = sysinfo.dwAllocationGranularity - (env & (sysinfo.dwAllocationGranularity - 1));
|
|
|
|
if (buf)
|
|
|
|
{
|
|
|
|
WCHAR *new_buf;
|
|
|
|
if (!(new_buf = realloc(buf, buf_size + read_size))) break;
|
|
|
|
buf = new_buf;
|
|
|
|
}
|
|
|
|
else if(!(buf = malloc(read_size))) break;
|
|
|
|
|
|
|
|
if (!read_process_memory(pcs, env, (char*)buf + buf_size, read_size)) break;
|
|
|
|
for (i = buf_size / sizeof(WCHAR); i < (buf_size + read_size) / sizeof(WCHAR); i++)
|
|
|
|
{
|
|
|
|
if (buf[i]) continue;
|
|
|
|
if (last_null + 1 == i)
|
|
|
|
{
|
|
|
|
pcs->environment = realloc(buf, (i + 1) * sizeof(WCHAR));
|
|
|
|
buf = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
last_null = i;
|
|
|
|
}
|
|
|
|
env += read_size;
|
|
|
|
buf_size += read_size;
|
|
|
|
}
|
|
|
|
while (buf);
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
|
2020-04-02 19:18:39 +02:00
|
|
|
if (!base) return FALSE;
|
2020-03-25 17:42:06 +01:00
|
|
|
|
2022-02-09 09:26:26 +01:00
|
|
|
TRACE("got debug info address %#Ix from PEB %p\n", base, pbi.PebBaseAddress);
|
2020-07-31 14:22:34 +02:00
|
|
|
if (!elf_read_wine_loader_dbg_info(pcs, base) && !macho_read_wine_loader_dbg_info(pcs, base))
|
2022-02-09 09:26:26 +01:00
|
|
|
WARN("couldn't load process debug info at %#Ix\n", base);
|
2020-07-31 14:22:34 +02:00
|
|
|
return TRUE;
|
2006-01-23 16:30:03 +01:00
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/******************************************************************
|
2006-05-10 21:35:07 +02:00
|
|
|
* SymInitializeW (DBGHELP.@)
|
2004-04-06 00:21:27 +02:00
|
|
|
*
|
|
|
|
* The initialisation of a dbghelp's context.
|
|
|
|
* Note that hProcess doesn't need to be a valid process handle (except
|
|
|
|
* when fInvadeProcess is TRUE).
|
2015-08-07 15:40:50 +02:00
|
|
|
* Since we also allow loading ELF (pure) libraries and Wine ELF libraries
|
2004-04-06 00:21:27 +02:00
|
|
|
* containing PE (and NE) module(s), here's how we handle it:
|
|
|
|
* - we load every module (ELF, NE, PE) passed in SymLoadModule
|
|
|
|
* - in fInvadeProcess (in SymInitialize) is TRUE, we set up what is called ELF
|
|
|
|
* synchronization: hProcess should be a valid process handle, and we hook
|
|
|
|
* ourselves on hProcess's loaded ELF-modules, and keep this list in sync with
|
|
|
|
* our internal ELF modules representation (loading / unloading). This way,
|
|
|
|
* we'll pair every loaded builtin PE module with its ELF counterpart (and
|
|
|
|
* access its debug information).
|
2006-01-23 16:30:03 +01:00
|
|
|
* - if fInvadeProcess (in SymInitialize) is FALSE, we check anyway if the
|
|
|
|
* hProcess refers to a running process. We use some heuristics here, so YMMV.
|
|
|
|
* If we detect a live target, then we get the same handling as if
|
|
|
|
* fInvadeProcess is TRUE (except that the modules are not loaded). Otherwise,
|
|
|
|
* we won't be able to make the peering between a builtin PE module and its ELF
|
|
|
|
* counterpart. Hence we won't be able to provide the requested debug
|
|
|
|
* information. We'll however be able to load native PE modules (and their
|
|
|
|
* debug information) without any trouble.
|
2004-04-06 00:21:27 +02:00
|
|
|
* Note also that this scheme can be intertwined with the deferred loading
|
|
|
|
* mechanism (ie only load the debug information when we actually need it).
|
|
|
|
*/
|
2006-05-10 21:35:07 +02:00
|
|
|
BOOL WINAPI SymInitializeW(HANDLE hProcess, PCWSTR UserSearchPath, BOOL fInvadeProcess)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
|
|
|
struct process* pcs;
|
2018-05-31 16:47:49 +02:00
|
|
|
BOOL wow64, child_wow64;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2006-05-10 21:35:07 +02:00
|
|
|
TRACE("(%p %s %u)\n", hProcess, debugstr_w(UserSearchPath), fInvadeProcess);
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2018-09-19 12:26:56 +02:00
|
|
|
if (process_find_by_handle(hProcess))
|
|
|
|
{
|
2008-01-17 21:47:55 +01:00
|
|
|
WARN("the symbols for this process have already been initialized!\n");
|
|
|
|
|
|
|
|
/* MSDN says to only call this function once unless SymCleanup() has been called since the last call.
|
|
|
|
It also says to call SymRefreshModuleList() instead if you just want the module list refreshed.
|
|
|
|
Native still returns TRUE even if the process has already been initialized. */
|
|
|
|
return TRUE;
|
|
|
|
}
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2018-05-31 16:47:49 +02:00
|
|
|
IsWow64Process(GetCurrentProcess(), &wow64);
|
|
|
|
|
2018-11-19 19:17:03 +01:00
|
|
|
if (GetProcessId(hProcess) && !IsWow64Process(hProcess, &child_wow64))
|
2018-05-31 16:47:49 +02:00
|
|
|
return FALSE;
|
2018-09-19 12:26:56 +02:00
|
|
|
|
|
|
|
pcs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pcs));
|
|
|
|
if (!pcs) return FALSE;
|
|
|
|
|
|
|
|
pcs->handle = hProcess;
|
2018-05-31 16:47:49 +02:00
|
|
|
pcs->is_64bit = (sizeof(void *) == 8 || wow64) && !child_wow64;
|
2020-03-24 01:54:07 +01:00
|
|
|
pcs->loader = &no_loader_ops; /* platform-specific initialization will override it if loader debug info can be found */
|
2018-05-31 16:47:49 +02:00
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
if (UserSearchPath)
|
|
|
|
{
|
2006-05-10 21:35:07 +02:00
|
|
|
pcs->search_path = lstrcpyW(HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
(lstrlenW(UserSearchPath) + 1) * sizeof(WCHAR)),
|
|
|
|
UserSearchPath);
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-11-13 00:11:48 +01:00
|
|
|
pcs->search_path = make_default_search_path();
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pcs->lmodules = NULL;
|
|
|
|
pcs->dbg_hdr_addr = 0;
|
|
|
|
pcs->next = process_first;
|
|
|
|
process_first = pcs;
|
2006-01-23 16:30:03 +01:00
|
|
|
|
2021-08-31 13:20:39 +02:00
|
|
|
if (check_live_target(pcs, wow64, child_wow64))
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2006-01-23 16:30:03 +01:00
|
|
|
if (fInvadeProcess)
|
2009-12-12 12:18:22 +01:00
|
|
|
EnumerateLoadedModulesW64(hProcess, process_invade_cb, hProcess);
|
2020-07-31 14:22:34 +02:00
|
|
|
if (pcs->loader) pcs->loader->synchronize_module_list(pcs);
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
2006-01-23 16:30:03 +01:00
|
|
|
else if (fInvadeProcess)
|
|
|
|
{
|
|
|
|
SymCleanup(hProcess);
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-03-01 11:39:49 +01:00
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-05-10 21:35:07 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SymInitialize (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymInitialize(HANDLE hProcess, PCSTR UserSearchPath, BOOL fInvadeProcess)
|
|
|
|
{
|
|
|
|
WCHAR* sp = NULL;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (UserSearchPath)
|
|
|
|
{
|
|
|
|
unsigned len;
|
|
|
|
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, UserSearchPath, -1, NULL, 0);
|
|
|
|
sp = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, UserSearchPath, -1, sp, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = SymInitializeW(hProcess, sp, fInvadeProcess);
|
|
|
|
HeapFree(GetProcessHeap(), 0, sp);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SymCleanup (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymCleanup(HANDLE hProcess)
|
|
|
|
{
|
|
|
|
struct process** ppcs;
|
|
|
|
struct process* next;
|
|
|
|
|
|
|
|
for (ppcs = &process_first; *ppcs; ppcs = &(*ppcs)->next)
|
|
|
|
{
|
|
|
|
if ((*ppcs)->handle == hProcess)
|
|
|
|
{
|
|
|
|
while ((*ppcs)->lmodules) module_remove(*ppcs, (*ppcs)->lmodules);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, (*ppcs)->search_path);
|
2020-04-09 19:59:57 +02:00
|
|
|
free((*ppcs)->environment);
|
2004-04-06 00:21:27 +02:00
|
|
|
next = (*ppcs)->next;
|
|
|
|
HeapFree(GetProcessHeap(), 0, *ppcs);
|
|
|
|
*ppcs = next;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2008-01-17 21:47:55 +01:00
|
|
|
|
|
|
|
ERR("this process has not had SymInitialize() called for it!\n");
|
2004-04-06 00:21:27 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymSetOptions (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
DWORD WINAPI SymSetOptions(DWORD opts)
|
|
|
|
{
|
2006-01-23 16:29:21 +01:00
|
|
|
struct process* pcs;
|
|
|
|
|
|
|
|
for (pcs = process_first; pcs; pcs = pcs->next)
|
|
|
|
{
|
|
|
|
pcs_callback(pcs, CBA_SET_OPTIONS, &opts);
|
|
|
|
}
|
2004-04-06 00:21:27 +02:00
|
|
|
return dbghelp_options = opts;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymGetOptions (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
DWORD WINAPI SymGetOptions(void)
|
|
|
|
{
|
|
|
|
return dbghelp_options;
|
|
|
|
}
|
|
|
|
|
2019-06-07 01:44:28 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SymSetExtendedOption (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymSetExtendedOption(IMAGEHLP_EXTENDED_OPTIONS option, BOOL value)
|
|
|
|
{
|
2019-06-07 01:44:30 +02:00
|
|
|
BOOL old = FALSE;
|
|
|
|
|
|
|
|
switch(option)
|
|
|
|
{
|
|
|
|
case SYMOPT_EX_WINE_NATIVE_MODULES:
|
|
|
|
old = dbghelp_opt_native;
|
|
|
|
dbghelp_opt_native = value;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unsupported option %d with value %d\n", option, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return old;
|
2019-06-07 01:44:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymGetExtendedOption (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymGetExtendedOption(IMAGEHLP_EXTENDED_OPTIONS option)
|
|
|
|
{
|
2019-06-07 01:44:30 +02:00
|
|
|
switch(option)
|
|
|
|
{
|
|
|
|
case SYMOPT_EX_WINE_NATIVE_MODULES:
|
|
|
|
return dbghelp_opt_native;
|
|
|
|
default:
|
|
|
|
FIXME("Unsupported option %d\n", option);
|
|
|
|
}
|
|
|
|
|
2019-06-07 01:44:28 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-07-29 16:42:37 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SymSetParentWindow (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymSetParentWindow(HWND hwnd)
|
|
|
|
{
|
|
|
|
/* Save hwnd so it can be used as parent window */
|
|
|
|
FIXME("(%p): stub\n", hwnd);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SymSetContext (DBGHELP.@)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymSetContext(HANDLE hProcess, PIMAGEHLP_STACK_FRAME StackFrame,
|
|
|
|
PIMAGEHLP_CONTEXT Context)
|
|
|
|
{
|
2021-10-26 11:45:32 +02:00
|
|
|
struct process* pcs;
|
|
|
|
|
2021-11-15 18:25:41 +01:00
|
|
|
TRACE("(%p %p %p)\n", hProcess, StackFrame, Context);
|
2021-10-26 11:45:44 +02:00
|
|
|
|
2021-11-15 18:25:41 +01:00
|
|
|
if (!(pcs = process_find_by_handle(hProcess))) return FALSE;
|
|
|
|
if (pcs->ctx_frame.ReturnOffset == StackFrame->ReturnOffset &&
|
|
|
|
pcs->ctx_frame.FrameOffset == StackFrame->FrameOffset &&
|
|
|
|
pcs->ctx_frame.StackOffset == StackFrame->StackOffset &&
|
|
|
|
pcs->ctx_frame.InstructionOffset == StackFrame->InstructionOffset)
|
2006-01-23 16:30:25 +01:00
|
|
|
{
|
2021-10-19 15:51:37 +02:00
|
|
|
TRACE("Setting same frame {rtn=%I64x frm=%I64x stk=%I64x}\n",
|
|
|
|
pcs->ctx_frame.ReturnOffset,
|
|
|
|
pcs->ctx_frame.FrameOffset,
|
|
|
|
pcs->ctx_frame.StackOffset);
|
2021-10-19 15:51:43 +02:00
|
|
|
SetLastError(ERROR_SUCCESS);
|
2006-01-23 16:30:25 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-11-15 18:25:41 +01:00
|
|
|
if (!SymSetScopeFromAddr(hProcess, StackFrame->InstructionOffset))
|
|
|
|
return FALSE;
|
|
|
|
pcs->ctx_frame = *StackFrame;
|
2021-10-19 15:51:43 +02:00
|
|
|
/* Context is not (no longer?) used */
|
2021-11-15 18:25:41 +01:00
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-10-19 15:51:37 +02:00
|
|
|
/******************************************************************
|
|
|
|
* SymSetScopeFromAddr (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymSetScopeFromAddr(HANDLE hProcess, ULONG64 addr)
|
|
|
|
{
|
2021-10-26 11:45:38 +02:00
|
|
|
struct module_pair pair;
|
|
|
|
struct symt_ht* sym;
|
2021-10-19 15:51:37 +02:00
|
|
|
|
2021-10-26 11:45:38 +02:00
|
|
|
TRACE("(%p %#I64x)\n", hProcess, addr);
|
|
|
|
|
|
|
|
if (!module_init_pair(&pair, hProcess, addr)) return FALSE;
|
|
|
|
pair.pcs->localscope_pc = addr;
|
2021-11-15 18:25:41 +01:00
|
|
|
if ((sym = symt_find_nearest(pair.effective, addr)) != NULL && sym->symt.tag == SymTagFunction)
|
|
|
|
pair.pcs->localscope_symt = &sym->symt;
|
|
|
|
else
|
|
|
|
pair.pcs->localscope_symt = NULL;
|
2021-10-19 15:51:37 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymSetScopeFromIndex (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymSetScopeFromIndex(HANDLE hProcess, ULONG64 addr, DWORD index)
|
|
|
|
{
|
2021-10-26 11:45:38 +02:00
|
|
|
struct module_pair pair;
|
|
|
|
struct symt* sym;
|
2021-10-19 15:51:37 +02:00
|
|
|
|
2022-02-09 09:26:26 +01:00
|
|
|
TRACE("(%p %#I64x %lu)\n", hProcess, addr, index);
|
2021-10-26 11:45:38 +02:00
|
|
|
|
|
|
|
if (!module_init_pair(&pair, hProcess, addr)) return FALSE;
|
|
|
|
sym = symt_index2ptr(pair.effective, index);
|
|
|
|
if (!symt_check_tag(sym, SymTagFunction)) return FALSE;
|
|
|
|
|
|
|
|
pair.pcs->localscope_pc = ((struct symt_function*)sym)->address; /* FIXME of FuncDebugStart when it exists? */
|
|
|
|
pair.pcs->localscope_symt = sym;
|
2021-10-19 15:51:37 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SymSetScopeFromInlineContext (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymSetScopeFromInlineContext(HANDLE hProcess, ULONG64 addr, DWORD inlinectx)
|
|
|
|
{
|
2021-10-28 08:58:44 +02:00
|
|
|
struct module_pair pair;
|
|
|
|
struct symt_inlinesite* inlined;
|
|
|
|
|
2022-02-09 09:26:26 +01:00
|
|
|
TRACE("(%p %I64x %lx)\n", hProcess, addr, inlinectx);
|
2021-10-19 15:51:37 +02:00
|
|
|
|
2021-10-26 11:45:50 +02:00
|
|
|
switch (IFC_MODE(inlinectx))
|
|
|
|
{
|
|
|
|
case IFC_MODE_IGNORE:
|
|
|
|
case IFC_MODE_REGULAR: return SymSetScopeFromAddr(hProcess, addr);
|
|
|
|
case IFC_MODE_INLINE:
|
2021-10-28 08:58:44 +02:00
|
|
|
if (!module_init_pair(&pair, hProcess, addr)) return FALSE;
|
|
|
|
inlined = symt_find_inlined_site(pair.effective, addr, inlinectx);
|
|
|
|
if (inlined)
|
|
|
|
{
|
|
|
|
pair.pcs->localscope_pc = addr;
|
|
|
|
pair.pcs->localscope_symt = &inlined->func.symt;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2021-10-26 11:45:50 +02:00
|
|
|
default:
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2021-10-19 15:51:37 +02:00
|
|
|
}
|
|
|
|
|
2006-01-23 16:29:21 +01:00
|
|
|
/******************************************************************
|
|
|
|
* reg_cb64to32 (internal)
|
|
|
|
*
|
|
|
|
* Registered callback for converting information from 64 bit to 32 bit
|
|
|
|
*/
|
|
|
|
static BOOL CALLBACK reg_cb64to32(HANDLE hProcess, ULONG action, ULONG64 data, ULONG64 user)
|
|
|
|
{
|
2009-12-12 12:18:34 +01:00
|
|
|
struct process* pcs = process_find_by_handle(hProcess);
|
2006-01-23 16:29:21 +01:00
|
|
|
void* data32;
|
|
|
|
IMAGEHLP_DEFERRED_SYMBOL_LOAD64* idsl64;
|
|
|
|
IMAGEHLP_DEFERRED_SYMBOL_LOAD idsl;
|
|
|
|
|
2009-12-15 11:14:48 +01:00
|
|
|
if (!pcs) return FALSE;
|
2006-01-23 16:29:21 +01:00
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case CBA_DEBUG_INFO:
|
|
|
|
case CBA_DEFERRED_SYMBOL_LOAD_CANCEL:
|
|
|
|
case CBA_SET_OPTIONS:
|
|
|
|
case CBA_SYMBOLS_UNLOADED:
|
2009-12-12 12:18:34 +01:00
|
|
|
data32 = (void*)(DWORD_PTR)data;
|
2006-01-23 16:29:21 +01:00
|
|
|
break;
|
|
|
|
case CBA_DEFERRED_SYMBOL_LOAD_COMPLETE:
|
|
|
|
case CBA_DEFERRED_SYMBOL_LOAD_FAILURE:
|
|
|
|
case CBA_DEFERRED_SYMBOL_LOAD_PARTIAL:
|
|
|
|
case CBA_DEFERRED_SYMBOL_LOAD_START:
|
2009-12-12 12:18:28 +01:00
|
|
|
idsl64 = (IMAGEHLP_DEFERRED_SYMBOL_LOAD64*)(DWORD_PTR)data;
|
2006-01-23 16:29:21 +01:00
|
|
|
if (!validate_addr64(idsl64->BaseOfImage))
|
|
|
|
return FALSE;
|
|
|
|
idsl.SizeOfStruct = sizeof(idsl);
|
|
|
|
idsl.BaseOfImage = (DWORD)idsl64->BaseOfImage;
|
|
|
|
idsl.CheckSum = idsl64->CheckSum;
|
|
|
|
idsl.TimeDateStamp = idsl64->TimeDateStamp;
|
|
|
|
memcpy(idsl.FileName, idsl64->FileName, sizeof(idsl.FileName));
|
|
|
|
idsl.Reparse = idsl64->Reparse;
|
|
|
|
data32 = &idsl;
|
|
|
|
break;
|
|
|
|
case CBA_DUPLICATE_SYMBOL:
|
|
|
|
case CBA_EVENT:
|
|
|
|
case CBA_READ_MEMORY:
|
|
|
|
default:
|
2022-02-09 09:26:26 +01:00
|
|
|
FIXME("No mapping for action %lu\n", action);
|
2006-01-23 16:29:21 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-12-12 12:18:34 +01:00
|
|
|
return pcs->reg_cb32(hProcess, action, data32, (PVOID)(DWORD_PTR)user);
|
2006-01-23 16:29:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* pcs_callback (internal)
|
|
|
|
*/
|
|
|
|
BOOL pcs_callback(const struct process* pcs, ULONG action, void* data)
|
|
|
|
{
|
2011-03-04 13:44:16 +01:00
|
|
|
IMAGEHLP_DEFERRED_SYMBOL_LOAD64 idsl;
|
|
|
|
|
2022-02-09 09:26:26 +01:00
|
|
|
TRACE("%p %lu %p\n", pcs, action, data);
|
2006-05-10 21:35:11 +02:00
|
|
|
|
2006-01-23 16:29:21 +01:00
|
|
|
if (!pcs->reg_cb) return FALSE;
|
2007-02-21 21:55:56 +01:00
|
|
|
if (!pcs->reg_is_unicode)
|
2006-05-10 21:35:11 +02:00
|
|
|
{
|
2007-02-21 21:55:56 +01:00
|
|
|
IMAGEHLP_DEFERRED_SYMBOL_LOADW64* idslW;
|
2006-05-10 21:35:11 +02:00
|
|
|
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case CBA_DEBUG_INFO:
|
|
|
|
case CBA_DEFERRED_SYMBOL_LOAD_CANCEL:
|
|
|
|
case CBA_SET_OPTIONS:
|
|
|
|
case CBA_SYMBOLS_UNLOADED:
|
|
|
|
break;
|
|
|
|
case CBA_DEFERRED_SYMBOL_LOAD_COMPLETE:
|
|
|
|
case CBA_DEFERRED_SYMBOL_LOAD_FAILURE:
|
|
|
|
case CBA_DEFERRED_SYMBOL_LOAD_PARTIAL:
|
|
|
|
case CBA_DEFERRED_SYMBOL_LOAD_START:
|
2009-12-10 15:31:27 +01:00
|
|
|
idslW = data;
|
2007-02-21 21:55:56 +01:00
|
|
|
idsl.SizeOfStruct = sizeof(idsl);
|
|
|
|
idsl.BaseOfImage = idslW->BaseOfImage;
|
|
|
|
idsl.CheckSum = idslW->CheckSum;
|
|
|
|
idsl.TimeDateStamp = idslW->TimeDateStamp;
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, idslW->FileName, -1,
|
|
|
|
idsl.FileName, sizeof(idsl.FileName), NULL, NULL);
|
|
|
|
idsl.Reparse = idslW->Reparse;
|
|
|
|
data = &idsl;
|
2006-05-10 21:35:11 +02:00
|
|
|
break;
|
|
|
|
case CBA_DUPLICATE_SYMBOL:
|
|
|
|
case CBA_EVENT:
|
|
|
|
case CBA_READ_MEMORY:
|
|
|
|
default:
|
2022-02-09 09:26:26 +01:00
|
|
|
FIXME("No mapping for action %lu\n", action);
|
2006-05-10 21:35:11 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2006-01-23 16:29:21 +01:00
|
|
|
return pcs->reg_cb(pcs->handle, action, (ULONG64)(DWORD_PTR)data, pcs->reg_user);
|
|
|
|
}
|
|
|
|
|
2006-05-10 21:35:11 +02:00
|
|
|
/******************************************************************
|
|
|
|
* sym_register_cb
|
|
|
|
*
|
|
|
|
* Helper for registering a callback.
|
|
|
|
*/
|
2009-12-12 12:18:34 +01:00
|
|
|
static BOOL sym_register_cb(HANDLE hProcess,
|
2006-05-10 21:35:11 +02:00
|
|
|
PSYMBOL_REGISTERED_CALLBACK64 cb,
|
2009-12-12 12:18:34 +01:00
|
|
|
PSYMBOL_REGISTERED_CALLBACK cb32,
|
2006-05-10 21:35:11 +02:00
|
|
|
DWORD64 user, BOOL unicode)
|
|
|
|
{
|
|
|
|
struct process* pcs = process_find_by_handle(hProcess);
|
|
|
|
|
|
|
|
if (!pcs) return FALSE;
|
|
|
|
pcs->reg_cb = cb;
|
2009-12-12 12:18:34 +01:00
|
|
|
pcs->reg_cb32 = cb32;
|
2006-05-10 21:35:11 +02:00
|
|
|
pcs->reg_is_unicode = unicode;
|
|
|
|
pcs->reg_user = user;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SymRegisterCallback (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymRegisterCallback(HANDLE hProcess,
|
|
|
|
PSYMBOL_REGISTERED_CALLBACK CallbackFunction,
|
|
|
|
PVOID UserContext)
|
|
|
|
{
|
2006-05-10 21:35:11 +02:00
|
|
|
TRACE("(%p, %p, %p)\n",
|
|
|
|
hProcess, CallbackFunction, UserContext);
|
2009-12-12 12:18:34 +01:00
|
|
|
return sym_register_cb(hProcess, reg_cb64to32, CallbackFunction, (DWORD_PTR)UserContext, FALSE);
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
|
2005-11-29 10:42:49 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SymRegisterCallback64 (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymRegisterCallback64(HANDLE hProcess,
|
|
|
|
PSYMBOL_REGISTERED_CALLBACK64 CallbackFunction,
|
|
|
|
ULONG64 UserContext)
|
|
|
|
{
|
2006-01-23 16:29:21 +01:00
|
|
|
TRACE("(%p, %p, %s)\n",
|
2005-11-29 10:42:49 +01:00
|
|
|
hProcess, CallbackFunction, wine_dbgstr_longlong(UserContext));
|
2009-12-12 12:18:34 +01:00
|
|
|
return sym_register_cb(hProcess, CallbackFunction, NULL, UserContext, FALSE);
|
2006-05-10 21:35:11 +02:00
|
|
|
}
|
2006-01-23 16:29:21 +01:00
|
|
|
|
2006-05-10 21:35:11 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* SymRegisterCallbackW64 (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SymRegisterCallbackW64(HANDLE hProcess,
|
|
|
|
PSYMBOL_REGISTERED_CALLBACK64 CallbackFunction,
|
|
|
|
ULONG64 UserContext)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %p, %s)\n",
|
|
|
|
hProcess, CallbackFunction, wine_dbgstr_longlong(UserContext));
|
2009-12-12 12:18:34 +01:00
|
|
|
return sym_register_cb(hProcess, CallbackFunction, NULL, UserContext, TRUE);
|
2005-11-29 10:42:49 +01:00
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/* This is imagehlp version not dbghelp !! */
|
|
|
|
static API_VERSION api_version = { 4, 0, 2, 0 };
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ImagehlpApiVersion (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
LPAPI_VERSION WINAPI ImagehlpApiVersion(VOID)
|
|
|
|
{
|
|
|
|
return &api_version;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ImagehlpApiVersionEx (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
LPAPI_VERSION WINAPI ImagehlpApiVersionEx(LPAPI_VERSION AppVersion)
|
|
|
|
{
|
|
|
|
if (!AppVersion) return NULL;
|
|
|
|
|
|
|
|
AppVersion->MajorVersion = api_version.MajorVersion;
|
|
|
|
AppVersion->MinorVersion = api_version.MinorVersion;
|
|
|
|
AppVersion->Revision = api_version.Revision;
|
|
|
|
AppVersion->Reserved = api_version.Reserved;
|
|
|
|
|
|
|
|
return AppVersion;
|
|
|
|
}
|
2005-12-20 11:49:24 +01:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* ExtensionApiVersion (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
LPEXT_API_VERSION WINAPI ExtensionApiVersion(void)
|
|
|
|
{
|
|
|
|
static EXT_API_VERSION eav = {5, 5, 5, 0};
|
|
|
|
return &eav;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WinDbgExtensionDllInit (DBGHELP.@)
|
|
|
|
*/
|
|
|
|
void WINAPI WinDbgExtensionDllInit(PWINDBG_EXTENSION_APIS lpExtensionApis,
|
|
|
|
unsigned short major, unsigned short minor)
|
|
|
|
{
|
|
|
|
}
|
2019-08-02 01:53:58 +02:00
|
|
|
|
2020-03-16 16:06:10 +01:00
|
|
|
DWORD calc_crc32(HANDLE handle)
|
2019-08-02 01:53:58 +02:00
|
|
|
{
|
|
|
|
BYTE buffer[8192];
|
|
|
|
DWORD crc = 0;
|
2020-03-16 16:06:10 +01:00
|
|
|
DWORD len;
|
2019-08-02 01:53:58 +02:00
|
|
|
|
2020-03-16 16:06:10 +01:00
|
|
|
SetFilePointer(handle, 0, 0, FILE_BEGIN);
|
|
|
|
while (ReadFile(handle, buffer, sizeof(buffer), &len, NULL) && len)
|
2019-08-02 01:53:58 +02:00
|
|
|
crc = RtlComputeCrc32(crc, buffer, len);
|
|
|
|
return crc;
|
|
|
|
}
|