Commit 43598133 authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

dbghelp: Remove unneeded parameter to pe_map_file.

parent d4104e85
...@@ -197,7 +197,7 @@ BOOL image_check_alternate(struct image_file_map* fmap, const struct module* mod ...@@ -197,7 +197,7 @@ BOOL image_check_alternate(struct image_file_map* fmap, const struct module* mod
struct image_file_map* image_load_debugaltlink(struct image_file_map* fmap, struct module* module) DECLSPEC_HIDDEN; struct image_file_map* image_load_debugaltlink(struct image_file_map* fmap, struct module* module) DECLSPEC_HIDDEN;
BOOL elf_map_handle(HANDLE handle, struct image_file_map* fmap) DECLSPEC_HIDDEN; BOOL elf_map_handle(HANDLE handle, struct image_file_map* fmap) DECLSPEC_HIDDEN;
BOOL pe_map_file(HANDLE file, struct image_file_map* fmap, enum module_type mt) DECLSPEC_HIDDEN; BOOL pe_map_file(HANDLE file, struct image_file_map* fmap) DECLSPEC_HIDDEN;
struct image_file_map_ops struct image_file_map_ops
{ {
......
...@@ -497,7 +497,7 @@ static BOOL image_check_debug_link_crc(const WCHAR* file, struct image_file_map* ...@@ -497,7 +497,7 @@ static BOOL image_check_debug_link_crc(const WCHAR* file, struct image_file_map*
SetFilePointer(handle, 0, 0, FILE_BEGIN); SetFilePointer(handle, 0, 0, FILE_BEGIN);
if (ReadFile(handle, &magic, sizeof(magic), &read_bytes, NULL) && magic == IMAGE_DOS_SIGNATURE) if (ReadFile(handle, &magic, sizeof(magic), &read_bytes, NULL) && magic == IMAGE_DOS_SIGNATURE)
ret = pe_map_file(handle, fmap, DMT_PE); ret = pe_map_file(handle, fmap);
else else
ret = elf_map_handle(handle, fmap); ret = elf_map_handle(handle, fmap);
CloseHandle(handle); CloseHandle(handle);
...@@ -521,7 +521,7 @@ static BOOL image_check_debug_link_gnu_id(const WCHAR* file, struct image_file_m ...@@ -521,7 +521,7 @@ static BOOL image_check_debug_link_gnu_id(const WCHAR* file, struct image_file_m
TRACE("Located debug information file at %s\n", debugstr_w(file)); TRACE("Located debug information file at %s\n", debugstr_w(file));
if (ReadFile(handle, &magic, sizeof(magic), &read_bytes, NULL) && magic == IMAGE_DOS_SIGNATURE) if (ReadFile(handle, &magic, sizeof(magic), &read_bytes, NULL) && magic == IMAGE_DOS_SIGNATURE)
ret = pe_map_file(handle, fmap, DMT_PE); ret = pe_map_file(handle, fmap);
else else
ret = elf_map_handle(handle, fmap); ret = elf_map_handle(handle, fmap);
CloseHandle(handle); CloseHandle(handle);
......
...@@ -243,11 +243,14 @@ static BOOL pe_is_valid_pointer_table(const IMAGE_NT_HEADERS* nthdr, const void* ...@@ -243,11 +243,14 @@ static BOOL pe_is_valid_pointer_table(const IMAGE_NT_HEADERS* nthdr, const void*
* *
* Maps an PE file into memory (and checks it's a real PE file) * Maps an PE file into memory (and checks it's a real PE file)
*/ */
BOOL pe_map_file(HANDLE file, struct image_file_map* fmap, enum module_type mt) BOOL pe_map_file(HANDLE file, struct image_file_map* fmap)
{ {
void* mapping; void* mapping;
IMAGE_NT_HEADERS* nthdr;
IMAGE_SECTION_HEADER* section;
unsigned i;
fmap->modtype = mt; fmap->modtype = DMT_PE;
fmap->ops = &pe_file_map_ops; fmap->ops = &pe_file_map_ops;
fmap->alternate = NULL; fmap->alternate = NULL;
fmap->u.pe.hMap = CreateFileMappingW(file, NULL, PAGE_READONLY, 0, 0, NULL); fmap->u.pe.hMap = CreateFileMappingW(file, NULL, PAGE_READONLY, 0, 0, NULL);
...@@ -256,72 +259,61 @@ BOOL pe_map_file(HANDLE file, struct image_file_map* fmap, enum module_type mt) ...@@ -256,72 +259,61 @@ BOOL pe_map_file(HANDLE file, struct image_file_map* fmap, enum module_type mt)
fmap->u.pe.full_map = NULL; fmap->u.pe.full_map = NULL;
if (!(mapping = pe_map_full(fmap, NULL))) goto error; if (!(mapping = pe_map_full(fmap, NULL))) goto error;
switch (mt) if (!(nthdr = RtlImageNtHeader(mapping))) goto error;
memcpy(&fmap->u.pe.file_header, &nthdr->FileHeader, sizeof(fmap->u.pe.file_header));
switch (nthdr->OptionalHeader.Magic)
{ {
case DMT_PE: case IMAGE_NT_OPTIONAL_HDR32_MAGIC:
{ fmap->addr_size = 32;
IMAGE_NT_HEADERS* nthdr; memcpy(&fmap->u.pe.opt.header32, &nthdr->OptionalHeader, sizeof(fmap->u.pe.opt.header32));
IMAGE_SECTION_HEADER* section; break;
unsigned i; case IMAGE_NT_OPTIONAL_HDR64_MAGIC:
if (sizeof(void*) == 4) return FALSE;
if (!(nthdr = RtlImageNtHeader(mapping))) goto error; fmap->addr_size = 64;
memcpy(&fmap->u.pe.file_header, &nthdr->FileHeader, sizeof(fmap->u.pe.file_header)); memcpy(&fmap->u.pe.opt.header64, &nthdr->OptionalHeader, sizeof(fmap->u.pe.opt.header64));
switch (nthdr->OptionalHeader.Magic) break;
{ default:
case IMAGE_NT_OPTIONAL_HDR32_MAGIC: return FALSE;
fmap->addr_size = 32; }
memcpy(&fmap->u.pe.opt.header32, &nthdr->OptionalHeader, sizeof(fmap->u.pe.opt.header32));
break;
case IMAGE_NT_OPTIONAL_HDR64_MAGIC:
if (sizeof(void*) == 4) return FALSE;
fmap->addr_size = 64;
memcpy(&fmap->u.pe.opt.header64, &nthdr->OptionalHeader, sizeof(fmap->u.pe.opt.header64));
break;
default:
return FALSE;
}
fmap->u.pe.builtin = !memcmp((const IMAGE_DOS_HEADER*)mapping + 1, builtin_signature, sizeof(builtin_signature)); fmap->u.pe.builtin = !memcmp((const IMAGE_DOS_HEADER*)mapping + 1, builtin_signature, sizeof(builtin_signature));
section = IMAGE_FIRST_SECTION( nthdr ); section = IMAGE_FIRST_SECTION( nthdr );
fmap->u.pe.sect = HeapAlloc(GetProcessHeap(), 0, fmap->u.pe.sect = HeapAlloc(GetProcessHeap(), 0,
nthdr->FileHeader.NumberOfSections * sizeof(fmap->u.pe.sect[0])); nthdr->FileHeader.NumberOfSections * sizeof(fmap->u.pe.sect[0]));
if (!fmap->u.pe.sect) goto error; if (!fmap->u.pe.sect) goto error;
for (i = 0; i < nthdr->FileHeader.NumberOfSections; i++) for (i = 0; i < nthdr->FileHeader.NumberOfSections; i++)
{ {
memcpy(&fmap->u.pe.sect[i].shdr, section + i, sizeof(IMAGE_SECTION_HEADER)); memcpy(&fmap->u.pe.sect[i].shdr, section + i, sizeof(IMAGE_SECTION_HEADER));
fmap->u.pe.sect[i].mapped = IMAGE_NO_MAP; fmap->u.pe.sect[i].mapped = IMAGE_NO_MAP;
} }
if (nthdr->FileHeader.PointerToSymbolTable && nthdr->FileHeader.NumberOfSymbols) if (nthdr->FileHeader.PointerToSymbolTable && nthdr->FileHeader.NumberOfSymbols)
{ {
LARGE_INTEGER li; LARGE_INTEGER li;
if (GetFileSizeEx(file, &li) && pe_is_valid_pointer_table(nthdr, mapping, li.QuadPart)) if (GetFileSizeEx(file, &li) && pe_is_valid_pointer_table(nthdr, mapping, li.QuadPart))
{ {
/* FIXME ugly: should rather map the relevant content instead of copying it */ /* FIXME ugly: should rather map the relevant content instead of copying it */
const char* src = (const char*)mapping + const char* src = (const char*)mapping +
nthdr->FileHeader.PointerToSymbolTable + nthdr->FileHeader.PointerToSymbolTable +
nthdr->FileHeader.NumberOfSymbols * sizeof(IMAGE_SYMBOL); nthdr->FileHeader.NumberOfSymbols * sizeof(IMAGE_SYMBOL);
char* dst; char* dst;
DWORD sz = *(DWORD*)src; DWORD sz = *(DWORD*)src;
if ((dst = HeapAlloc(GetProcessHeap(), 0, sz))) if ((dst = HeapAlloc(GetProcessHeap(), 0, sz)))
memcpy(dst, src, sz); memcpy(dst, src, sz);
fmap->u.pe.strtable = dst; fmap->u.pe.strtable = dst;
} }
else else
{ {
WARN("Bad coff table... wipping out\n"); WARN("Bad coff table... wipping out\n");
/* we have bad information here, wipe it out */ /* we have bad information here, wipe it out */
fmap->u.pe.file_header.PointerToSymbolTable = 0; fmap->u.pe.file_header.PointerToSymbolTable = 0;
fmap->u.pe.file_header.NumberOfSymbols = 0; fmap->u.pe.file_header.NumberOfSymbols = 0;
fmap->u.pe.strtable = NULL; fmap->u.pe.strtable = NULL;
}
}
else fmap->u.pe.strtable = NULL;
} }
break;
default: assert(0); goto error;
} }
else fmap->u.pe.strtable = NULL;
pe_unmap_full(fmap); pe_unmap_full(fmap);
return TRUE; return TRUE;
...@@ -757,7 +749,7 @@ static BOOL search_builtin_pe(void *param, HANDLE handle, const WCHAR *path) ...@@ -757,7 +749,7 @@ static BOOL search_builtin_pe(void *param, HANDLE handle, const WCHAR *path)
{ {
struct builtin_search *search = param; struct builtin_search *search = param;
if (!pe_map_file(handle, &search->fmap, DMT_PE)) return FALSE; if (!pe_map_file(handle, &search->fmap)) return FALSE;
search->path = wcsdup(path); search->path = wcsdup(path);
return TRUE; return TRUE;
...@@ -815,7 +807,7 @@ struct module* pe_load_native_module(struct process* pcs, const WCHAR* name, ...@@ -815,7 +807,7 @@ struct module* pe_load_native_module(struct process* pcs, const WCHAR* name,
if ((modfmt = HeapAlloc(GetProcessHeap(), 0, sizeof(struct module_format) + sizeof(struct pe_module_info)))) if ((modfmt = HeapAlloc(GetProcessHeap(), 0, sizeof(struct module_format) + sizeof(struct pe_module_info))))
{ {
modfmt->u.pe_info = (struct pe_module_info*)(modfmt + 1); modfmt->u.pe_info = (struct pe_module_info*)(modfmt + 1);
if (pe_map_file(hFile, &modfmt->u.pe_info->fmap, DMT_PE)) if (pe_map_file(hFile, &modfmt->u.pe_info->fmap))
{ {
struct builtin_search builtin = { NULL }; struct builtin_search builtin = { NULL };
if (opened && modfmt->u.pe_info->fmap.u.pe.builtin && if (opened && modfmt->u.pe_info->fmap.u.pe.builtin &&
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment