2004-04-06 00:21:27 +02:00
|
|
|
/*
|
|
|
|
* File pe_module.c - handle PE module information
|
|
|
|
*
|
|
|
|
* Copyright (C) 1996, Eric Youngdale.
|
|
|
|
* Copyright (C) 1999-2000, Ulrich Weigand.
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "dbghelp_private.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "winternl.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* pe_load_stabs
|
|
|
|
*
|
|
|
|
* look for stabs information in PE header (it's how the mingw compiler provides
|
|
|
|
* its debugging information)
|
|
|
|
*/
|
2004-08-30 21:31:13 +02:00
|
|
|
static BOOL pe_load_stabs(const struct process* pcs, struct module* module,
|
|
|
|
const void* mapping, IMAGE_NT_HEADERS* nth)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
|
|
|
IMAGE_SECTION_HEADER* section;
|
|
|
|
int i, stabsize = 0, stabstrsize = 0;
|
|
|
|
unsigned int stabs = 0, stabstr = 0;
|
2004-08-30 21:31:13 +02:00
|
|
|
BOOL ret = FALSE;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
|
|
|
section = (IMAGE_SECTION_HEADER*)
|
|
|
|
((char*)&nth->OptionalHeader + nth->FileHeader.SizeOfOptionalHeader);
|
|
|
|
for (i = 0; i < nth->FileHeader.NumberOfSections; i++, section++)
|
|
|
|
{
|
|
|
|
if (!strcasecmp(section->Name, ".stab"))
|
|
|
|
{
|
|
|
|
stabs = section->VirtualAddress;
|
|
|
|
stabsize = section->SizeOfRawData;
|
|
|
|
}
|
|
|
|
else if (!strncasecmp(section->Name, ".stabstr", 8))
|
|
|
|
{
|
|
|
|
stabstr = section->VirtualAddress;
|
|
|
|
stabstrsize = section->SizeOfRawData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stabstrsize && stabsize)
|
|
|
|
{
|
2004-11-08 21:26:22 +01:00
|
|
|
ret = stabs_parse(module,
|
|
|
|
module->module.BaseOfImage - nth->OptionalHeader.ImageBase,
|
|
|
|
RtlImageRvaToVa(nth, (void*)mapping, stabs, NULL),
|
|
|
|
stabsize,
|
|
|
|
RtlImageRvaToVa(nth, (void*)mapping, stabstr, NULL),
|
|
|
|
stabstrsize);
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
2004-08-30 21:31:13 +02:00
|
|
|
return ret;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
|
2004-06-14 19:58:31 +02:00
|
|
|
static BOOL CALLBACK dbg_match(char* file, void* user)
|
|
|
|
{
|
|
|
|
/* accept first file */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/******************************************************************
|
|
|
|
* pe_load_dbg_file
|
|
|
|
*
|
|
|
|
* loads a .dbg file
|
|
|
|
*/
|
2004-08-30 21:31:13 +02:00
|
|
|
static BOOL pe_load_dbg_file(const struct process* pcs, struct module* module,
|
|
|
|
const char* dbg_name, DWORD timestamp)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2004-05-18 23:29:09 +02:00
|
|
|
char tmp[MAX_PATH];
|
2004-06-14 19:58:31 +02:00
|
|
|
HANDLE hFile = INVALID_HANDLE_VALUE, hMap = 0;
|
2004-05-18 23:29:09 +02:00
|
|
|
const BYTE* dbg_mapping = NULL;
|
|
|
|
const IMAGE_SEPARATE_DEBUG_HEADER* hdr;
|
|
|
|
const IMAGE_DEBUG_DIRECTORY* dbg;
|
2004-08-30 21:31:13 +02:00
|
|
|
BOOL ret = FALSE;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
|
|
|
WINE_TRACE("Processing DBG file %s\n", dbg_name);
|
|
|
|
|
2004-06-14 19:58:31 +02:00
|
|
|
if (SymFindFileInPath(pcs->handle, NULL, (char*)dbg_name,
|
|
|
|
NULL, 0, 0, 0,
|
|
|
|
tmp, dbg_match, NULL) &&
|
|
|
|
(hFile = CreateFileA(tmp, GENERIC_READ, FILE_SHARE_READ, NULL,
|
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) != INVALID_HANDLE_VALUE &&
|
2004-04-06 00:21:27 +02:00
|
|
|
((hMap = CreateFileMappingA(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != 0) &&
|
|
|
|
((dbg_mapping = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) != NULL))
|
|
|
|
{
|
2004-05-18 23:29:09 +02:00
|
|
|
hdr = (const IMAGE_SEPARATE_DEBUG_HEADER*)dbg_mapping;
|
2004-04-06 00:21:27 +02:00
|
|
|
if (hdr->TimeDateStamp != timestamp)
|
|
|
|
{
|
|
|
|
WINE_ERR("Warning - %s has incorrect internal timestamp\n",
|
|
|
|
dbg_name);
|
|
|
|
/*
|
|
|
|
* Well, sometimes this happens to DBG files which ARE REALLY the
|
|
|
|
* right .DBG files but nonetheless this check fails. Anyway,
|
|
|
|
* WINDBG (debugger for Windows by Microsoft) loads debug symbols
|
|
|
|
* which have incorrect timestamps.
|
|
|
|
*/
|
|
|
|
}
|
2004-10-04 21:30:50 +02:00
|
|
|
if (hdr->Signature == IMAGE_SEPARATE_DEBUG_SIGNATURE)
|
|
|
|
{
|
2004-10-11 22:08:07 +02:00
|
|
|
/* section headers come immediately after debug header */
|
|
|
|
const IMAGE_SECTION_HEADER *sectp =
|
|
|
|
(const IMAGE_SECTION_HEADER*)(hdr + 1);
|
|
|
|
/* and after that and the exported names comes the debug directory */
|
2004-10-04 21:30:50 +02:00
|
|
|
dbg = (const IMAGE_DEBUG_DIRECTORY*)
|
|
|
|
(dbg_mapping + sizeof(*hdr) +
|
|
|
|
hdr->NumberOfSections * sizeof(IMAGE_SECTION_HEADER) +
|
|
|
|
hdr->ExportedNamesSize);
|
2004-10-11 22:08:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
ret = pe_load_debug_directory(pcs, module, dbg_mapping, sectp,
|
|
|
|
hdr->NumberOfSections, dbg,
|
2004-10-04 21:30:50 +02:00
|
|
|
hdr->DebugDirectorySize / sizeof(*dbg));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ERR("Wrong signature in .DBG file %s\n", debugstr_a(tmp));
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
else
|
2004-05-24 21:08:19 +02:00
|
|
|
WINE_ERR("-Unable to peruse .DBG file %s (%s)\n", dbg_name, debugstr_a(tmp));
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
if (dbg_mapping) UnmapViewOfFile((void*)dbg_mapping);
|
|
|
|
if (hMap) CloseHandle(hMap);
|
|
|
|
if (hFile != NULL) CloseHandle(hFile);
|
2004-08-30 21:31:13 +02:00
|
|
|
return ret;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* pe_load_msc_debug_info
|
|
|
|
*
|
|
|
|
* Process MSC debug information in PE file.
|
|
|
|
*/
|
2004-08-30 21:31:13 +02:00
|
|
|
static BOOL pe_load_msc_debug_info(const struct process* pcs,
|
|
|
|
struct module* module,
|
|
|
|
const void* mapping, IMAGE_NT_HEADERS* nth)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2004-08-30 21:31:13 +02:00
|
|
|
BOOL ret = FALSE;
|
2004-05-18 23:29:09 +02:00
|
|
|
const IMAGE_DATA_DIRECTORY* dir;
|
|
|
|
const IMAGE_DEBUG_DIRECTORY*dbg = NULL;
|
|
|
|
int nDbg;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
|
|
|
/* Read in debug directory */
|
|
|
|
dir = nth->OptionalHeader.DataDirectory + IMAGE_DIRECTORY_ENTRY_DEBUG;
|
|
|
|
nDbg = dir->Size / sizeof(IMAGE_DEBUG_DIRECTORY);
|
2004-08-30 21:31:13 +02:00
|
|
|
if (!nDbg) return FALSE;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2004-08-30 21:31:13 +02:00
|
|
|
dbg = RtlImageRvaToVa(nth, (void*)mapping, dir->VirtualAddress, NULL);
|
2004-04-06 00:21:27 +02:00
|
|
|
|
|
|
|
/* Parse debug directory */
|
|
|
|
if (nth->FileHeader.Characteristics & IMAGE_FILE_DEBUG_STRIPPED)
|
|
|
|
{
|
|
|
|
/* Debug info is stripped to .DBG file */
|
2004-05-18 23:29:09 +02:00
|
|
|
const IMAGE_DEBUG_MISC* misc = (const IMAGE_DEBUG_MISC*)
|
|
|
|
((const char*)mapping + dbg->PointerToRawData);
|
2004-04-06 00:21:27 +02:00
|
|
|
|
|
|
|
if (nDbg != 1 || dbg->Type != IMAGE_DEBUG_TYPE_MISC ||
|
|
|
|
misc->DataType != IMAGE_DEBUG_MISC_EXENAME)
|
|
|
|
{
|
|
|
|
WINE_ERR("-Debug info stripped, but no .DBG file in module %s\n",
|
|
|
|
module->module.ModuleName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-08-30 21:31:13 +02:00
|
|
|
ret = pe_load_dbg_file(pcs, module, misc->Data, nth->FileHeader.TimeDateStamp);
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-10-11 22:08:07 +02:00
|
|
|
const IMAGE_SECTION_HEADER *sectp = (const IMAGE_SECTION_HEADER*)((const char*)&nth->OptionalHeader + nth->FileHeader.SizeOfOptionalHeader);
|
2004-04-06 00:21:27 +02:00
|
|
|
/* Debug info is embedded into PE module */
|
2004-10-11 22:08:07 +02:00
|
|
|
ret = pe_load_debug_directory(pcs, module, mapping, sectp,
|
|
|
|
nth->FileHeader.NumberOfSections, dbg, nDbg);
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
|
2004-08-30 21:31:13 +02:00
|
|
|
return ret;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* pe_load_export_debug_info
|
|
|
|
*/
|
2004-08-30 21:31:13 +02:00
|
|
|
static BOOL pe_load_export_debug_info(const struct process* pcs,
|
|
|
|
struct module* module,
|
|
|
|
const void* mapping, IMAGE_NT_HEADERS* nth)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2004-08-30 21:31:13 +02:00
|
|
|
unsigned int i;
|
|
|
|
const IMAGE_EXPORT_DIRECTORY* exports;
|
|
|
|
DWORD base = module->module.BaseOfImage;
|
|
|
|
DWORD size;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
2004-08-30 21:31:13 +02:00
|
|
|
if (dbghelp_options & SYMOPT_NO_PUBLICS) return TRUE;
|
2004-04-06 00:21:27 +02:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Add start of DLL (better use the (yet unimplemented) Exe SymTag for this) */
|
|
|
|
/* FIXME: module.ModuleName isn't correctly set yet if it's passed in SymLoadModule */
|
|
|
|
symt_new_public(module, NULL, module->module.ModuleName, base, 0,
|
|
|
|
TRUE /* FIXME */, TRUE /* FIXME */);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Add entry point */
|
2004-05-18 23:29:09 +02:00
|
|
|
symt_new_public(module, NULL, "EntryPoint",
|
2004-04-06 00:21:27 +02:00
|
|
|
base + nth->OptionalHeader.AddressOfEntryPoint, 0,
|
2004-08-30 21:31:13 +02:00
|
|
|
TRUE, TRUE);
|
2004-04-06 00:21:27 +02:00
|
|
|
#if 0
|
2004-05-18 23:29:09 +02:00
|
|
|
/* FIXME: we'd better store addresses linked to sections rather than
|
|
|
|
absolute values */
|
2004-04-06 00:21:27 +02:00
|
|
|
IMAGE_SECTION_HEADER* section;
|
|
|
|
/* Add start of sections */
|
|
|
|
section = (IMAGE_SECTION_HEADER*)
|
|
|
|
((char*)&nth->OptionalHeader + nth->FileHeader.SizeOfOptionalHeader);
|
|
|
|
for (i = 0; i < nth->FileHeader.NumberOfSections; i++, section++)
|
|
|
|
{
|
2004-08-30 21:31:13 +02:00
|
|
|
symt_new_public(module, NULL, section->Name,
|
|
|
|
RtlImageRvaToVa(nth, (void*)mapping, section->VirtualAddress, NULL),
|
|
|
|
0, TRUE /* FIXME */, TRUE /* FIXME */);
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
#endif
|
2004-08-30 21:31:13 +02:00
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/* Add exported functions */
|
2004-08-30 21:31:13 +02:00
|
|
|
if ((exports = RtlImageDirectoryEntryToData((void*)mapping, FALSE,
|
|
|
|
IMAGE_DIRECTORY_ENTRY_EXPORT, &size)))
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2004-08-30 21:31:13 +02:00
|
|
|
const WORD* ordinals = NULL;
|
|
|
|
const DWORD_PTR* functions = NULL;
|
|
|
|
const DWORD* names = NULL;
|
|
|
|
unsigned int j;
|
|
|
|
char buffer[16];
|
|
|
|
|
|
|
|
functions = RtlImageRvaToVa(nth, (void*)mapping, exports->AddressOfFunctions, NULL);
|
|
|
|
ordinals = RtlImageRvaToVa(nth, (void*)mapping, exports->AddressOfNameOrdinals, NULL);
|
|
|
|
names = RtlImageRvaToVa(nth, (void*)mapping, exports->AddressOfNames, NULL);
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
for (i = 0; i < exports->NumberOfNames; i++)
|
|
|
|
{
|
|
|
|
if (!names[i]) continue;
|
2004-08-30 21:31:13 +02:00
|
|
|
symt_new_public(module, NULL,
|
|
|
|
RtlImageRvaToVa(nth, (void*)mapping, names[i], NULL),
|
|
|
|
base + functions[ordinals[i]],
|
|
|
|
0, TRUE /* FIXME */, TRUE /* FIXME */);
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < exports->NumberOfFunctions; i++)
|
|
|
|
{
|
|
|
|
if (!functions[i]) continue;
|
|
|
|
/* Check if we already added it with a name */
|
|
|
|
for (j = 0; j < exports->NumberOfNames; j++)
|
|
|
|
if ((ordinals[j] == i) && names[j]) break;
|
|
|
|
if (j < exports->NumberOfNames) continue;
|
2004-05-18 23:29:09 +02:00
|
|
|
snprintf(buffer, sizeof(buffer), "%ld", i + exports->Base);
|
|
|
|
symt_new_public(module, NULL, buffer, base + (DWORD)functions[i], 0,
|
2004-04-06 00:21:27 +02:00
|
|
|
TRUE /* FIXME */, TRUE /* FIXME */);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* no real debug info, only entry points */
|
2004-11-08 21:26:22 +01:00
|
|
|
if (module->module.SymType == SymDeferred)
|
|
|
|
module->module.SymType = SymExport;
|
2004-08-30 21:31:13 +02:00
|
|
|
return TRUE;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* pe_load_debug_info
|
|
|
|
*
|
|
|
|
*/
|
2004-08-30 21:31:13 +02:00
|
|
|
BOOL pe_load_debug_info(const struct process* pcs, struct module* module)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2004-08-30 21:31:13 +02:00
|
|
|
BOOL ret = FALSE;
|
2004-04-06 00:21:27 +02:00
|
|
|
HANDLE hFile;
|
|
|
|
HANDLE hMap;
|
|
|
|
void* mapping;
|
|
|
|
IMAGE_NT_HEADERS* nth;
|
|
|
|
|
|
|
|
hFile = CreateFileA(module->module.LoadedImageName, GENERIC_READ, FILE_SHARE_READ,
|
|
|
|
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
2004-08-30 21:31:13 +02:00
|
|
|
if (hFile == INVALID_HANDLE_VALUE) return ret;
|
2004-04-06 00:21:27 +02:00
|
|
|
if ((hMap = CreateFileMappingA(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != 0)
|
|
|
|
{
|
|
|
|
if ((mapping = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) != NULL)
|
|
|
|
{
|
|
|
|
nth = RtlImageNtHeader(mapping);
|
|
|
|
|
|
|
|
if (!(dbghelp_options & SYMOPT_PUBLICS_ONLY))
|
|
|
|
{
|
2004-08-30 21:31:13 +02:00
|
|
|
ret = pe_load_stabs(pcs, module, mapping, nth) ||
|
|
|
|
pe_load_msc_debug_info(pcs, module, mapping, nth);
|
2004-04-06 00:21:27 +02:00
|
|
|
/* if we still have no debug info (we could only get SymExport at this
|
|
|
|
* point), then do the SymExport except if we have an ELF container,
|
|
|
|
* in which case we'll rely on the export's on the ELF side
|
|
|
|
*/
|
|
|
|
}
|
2004-12-06 12:41:32 +01:00
|
|
|
/* FIXME shouldn't we check that? if (!module_get_debug(pcs, module))l */
|
2004-08-30 21:31:13 +02:00
|
|
|
if (pe_load_export_debug_info(pcs, module, mapping, nth) && !ret)
|
|
|
|
ret = TRUE;
|
2004-04-06 00:21:27 +02:00
|
|
|
UnmapViewOfFile(mapping);
|
|
|
|
}
|
|
|
|
CloseHandle(hMap);
|
|
|
|
}
|
|
|
|
CloseHandle(hFile);
|
|
|
|
|
2004-08-30 21:31:13 +02:00
|
|
|
return ret;
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* pe_load_module
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct module* pe_load_module(struct process* pcs, char* name,
|
|
|
|
HANDLE hFile, DWORD base, DWORD size)
|
|
|
|
{
|
|
|
|
struct module* module = NULL;
|
|
|
|
BOOL opened = FALSE;
|
|
|
|
HANDLE hMap;
|
|
|
|
void* mapping;
|
|
|
|
char loaded_name[MAX_PATH];
|
|
|
|
|
|
|
|
loaded_name[0] = '\0';
|
|
|
|
if (!hFile)
|
|
|
|
{
|
|
|
|
if (!name)
|
|
|
|
{
|
|
|
|
/* FIXME SetLastError */
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-03-29 15:14:08 +02:00
|
|
|
if ((hFile = FindExecutableImage(name, pcs->search_path, loaded_name)) == NULL)
|
2004-04-06 00:21:27 +02:00
|
|
|
return NULL;
|
|
|
|
opened = TRUE;
|
|
|
|
}
|
|
|
|
else if (name) strcpy(loaded_name, name);
|
|
|
|
else if (dbghelp_options & SYMOPT_DEFERRED_LOADS)
|
|
|
|
FIXME("Trouble ahead (no module name passed in deferred mode)\n");
|
2004-05-24 21:08:19 +02:00
|
|
|
if (!(module = module_find_by_name(pcs, loaded_name, DMT_PE)) &&
|
|
|
|
(hMap = CreateFileMappingA(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != NULL)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
|
|
|
if ((mapping = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) != NULL)
|
|
|
|
{
|
|
|
|
IMAGE_NT_HEADERS* nth = RtlImageNtHeader(mapping);
|
|
|
|
|
|
|
|
if (nth)
|
|
|
|
{
|
|
|
|
if (!base) base = nth->OptionalHeader.ImageBase;
|
|
|
|
if (!size) size = nth->OptionalHeader.SizeOfImage;
|
|
|
|
|
|
|
|
module = module_new(pcs, loaded_name, DMT_PE, base, size,
|
|
|
|
nth->FileHeader.TimeDateStamp,
|
|
|
|
nth->OptionalHeader.CheckSum);
|
|
|
|
if (module)
|
|
|
|
{
|
2004-08-30 21:31:13 +02:00
|
|
|
if (dbghelp_options & SYMOPT_DEFERRED_LOADS)
|
|
|
|
module->module.SymType = SymDeferred;
|
|
|
|
else
|
|
|
|
pe_load_debug_info(pcs, module);
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
UnmapViewOfFile(mapping);
|
|
|
|
}
|
|
|
|
CloseHandle(hMap);
|
|
|
|
}
|
|
|
|
if (opened) CloseHandle(hFile);
|
|
|
|
|
|
|
|
return module;
|
|
|
|
}
|
|
|
|
|
2005-03-29 15:14:08 +02:00
|
|
|
/******************************************************************
|
|
|
|
* pe_load_nt_header
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL pe_load_nt_header(HANDLE hProc, DWORD base, IMAGE_NT_HEADERS* nth)
|
|
|
|
{
|
|
|
|
IMAGE_DOS_HEADER dos;
|
|
|
|
|
|
|
|
return ReadProcessMemory(hProc, (char*)base, &dos, sizeof(dos), NULL) &&
|
|
|
|
dos.e_magic == IMAGE_DOS_SIGNATURE &&
|
|
|
|
ReadProcessMemory(hProc, (char*)(base + dos.e_lfanew),
|
|
|
|
nth, sizeof(*nth), NULL) &&
|
|
|
|
nth->Signature == IMAGE_NT_SIGNATURE;
|
|
|
|
}
|
|
|
|
|
2004-04-06 00:21:27 +02:00
|
|
|
/******************************************************************
|
|
|
|
* pe_load_module_from_pcs
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct module* pe_load_module_from_pcs(struct process* pcs, const char* name,
|
|
|
|
const char* mod_name, DWORD base, DWORD size)
|
|
|
|
{
|
|
|
|
struct module* module;
|
|
|
|
const char* ptr;
|
|
|
|
|
|
|
|
if ((module = module_find_by_name(pcs, name, DMT_PE))) return module;
|
|
|
|
if (mod_name) ptr = mod_name;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (ptr = name + strlen(name) - 1; ptr >= name; ptr--)
|
|
|
|
{
|
|
|
|
if (*ptr == '/' || *ptr == '\\')
|
|
|
|
{
|
|
|
|
ptr++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ptr && (module = module_find_by_name(pcs, ptr, DMT_PE))) return module;
|
2005-03-01 11:39:49 +01:00
|
|
|
if (base)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2005-03-01 11:39:49 +01:00
|
|
|
if (pcs->dbg_hdr_addr)
|
2004-04-06 00:21:27 +02:00
|
|
|
{
|
2005-03-01 11:39:49 +01:00
|
|
|
IMAGE_NT_HEADERS nth;
|
|
|
|
|
2005-03-29 15:14:08 +02:00
|
|
|
if (pe_load_nt_header(pcs->handle, base, &nth))
|
2005-03-01 11:39:49 +01:00
|
|
|
{
|
|
|
|
if (!size) size = nth.OptionalHeader.SizeOfImage;
|
|
|
|
module = module_new(pcs, name, DMT_PE, base, size,
|
|
|
|
nth.FileHeader.TimeDateStamp, nth.OptionalHeader.CheckSum);
|
|
|
|
}
|
|
|
|
} else if (size)
|
|
|
|
module = module_new(pcs, name, DMT_PE, base, size, 0 /* FIXME */, 0 /* FIXME */);
|
2004-04-06 00:21:27 +02:00
|
|
|
}
|
|
|
|
return module;
|
|
|
|
}
|