dbghelp: Check checksum before mapping elf file.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2020-03-17 17:20:54 +01:00 committed by Alexandre Julliard
parent fff82ac268
commit c1d867fa87
1 changed files with 29 additions and 11 deletions

View File

@ -326,7 +326,7 @@ static inline void elf_reset_file_map(struct image_file_map* fmap)
struct elf_map_file_data
{
enum {from_file, from_process} kind;
enum {from_file, from_process, from_handle} kind;
union
{
struct
@ -338,6 +338,7 @@ struct elf_map_file_data
HANDLE handle;
void* load_addr;
} process;
HANDLE handle;
} u;
};
@ -351,6 +352,7 @@ static BOOL elf_map_file_read(struct image_file_map* fmap, struct elf_map_file_d
switch (emfd->kind)
{
case from_file:
case from_handle:
li.QuadPart = off;
if (!SetFilePointerEx(fmap->u.elf.handle, li, NULL, FILE_BEGIN)) return FALSE;
return ReadFile(fmap->u.elf.handle, buf, len, &bytes_read, NULL);
@ -444,6 +446,10 @@ static BOOL elf_map_file(struct elf_map_file_data* emfd, struct image_file_map*
heap_free(dos_path);
if (fmap->u.elf.handle == INVALID_HANDLE_VALUE) return FALSE;
break;
case from_handle:
if (!DuplicateHandle(GetCurrentProcess(), emfd->u.handle, GetCurrentProcess(), &fmap->u.elf.handle, GENERIC_READ, FALSE, 0))
return FALSE;
break;
case from_process:
break;
}
@ -539,6 +545,7 @@ static BOOL elf_map_file(struct elf_map_file_data* emfd, struct image_file_map*
switch (emfd->kind)
{
case from_handle:
case from_file: break;
case from_process:
if (!(fmap->u.elf.target_copy = HeapAlloc(GetProcessHeap(), 0, fmap->u.elf.elf_size)))
@ -558,6 +565,14 @@ static BOOL elf_map_file(struct elf_map_file_data* emfd, struct image_file_map*
return TRUE;
}
static BOOL elf_map_handle(HANDLE handle, struct image_file_map* fmap)
{
struct elf_map_file_data emfd;
emfd.kind = from_handle;
emfd.u.handle = handle;
return elf_map_file(&emfd, fmap);
}
static void elf_module_remove(struct process* pcs, struct module_format* modfmt)
{
image_unmap_file(&modfmt->u.elf_info->file_map);
@ -968,21 +983,24 @@ static int elf_new_public_symbols(struct module* module, const struct hash_table
static BOOL elf_check_debug_link(const WCHAR* file, struct image_file_map* fmap, DWORD link_crc)
{
struct elf_map_file_data emfd;
HANDLE handle;
WCHAR *path;
DWORD crc;
BOOL ret = FALSE;
emfd.kind = from_file;
emfd.u.file.filename = file;
if (!elf_map_file(&emfd, fmap)) return FALSE;
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;
crc = calc_crc32(fmap->u.elf.handle);
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);
image_unmap_file(fmap);
return FALSE;
}
return TRUE;
else
ret = elf_map_handle(handle, fmap);
CloseHandle(handle);
return ret;
}
/******************************************************************