Commit af25f29c authored by Alexandre Julliard's avatar Alexandre Julliard

winedump: Don't zero out the PE optional header regardless of specified size.

parent 4d417076
...@@ -264,7 +264,7 @@ void lib_dump(void) ...@@ -264,7 +264,7 @@ void lib_dump(void)
if (fh->SizeOfOptionalHeader) if (fh->SizeOfOptionalHeader)
{ {
const IMAGE_OPTIONAL_HEADER32 *oh = (const IMAGE_OPTIONAL_HEADER32 *)((const char *)fh + sizeof(*fh)); const IMAGE_OPTIONAL_HEADER32 *oh = (const IMAGE_OPTIONAL_HEADER32 *)((const char *)fh + sizeof(*fh));
dump_optional_header(oh, fh->SizeOfOptionalHeader); dump_optional_header(oh);
} }
} }
/* Sanity check */ /* Sanity check */
......
...@@ -275,14 +275,14 @@ static inline void print_datadirectory(DWORD n, const IMAGE_DATA_DIRECTORY *dire ...@@ -275,14 +275,14 @@ static inline void print_datadirectory(DWORD n, const IMAGE_DATA_DIRECTORY *dire
} }
} }
static void dump_optional_header32(const IMAGE_OPTIONAL_HEADER32 *image_oh, UINT header_size) static void dump_optional_header32(const IMAGE_OPTIONAL_HEADER32 *image_oh)
{ {
IMAGE_OPTIONAL_HEADER32 oh; IMAGE_OPTIONAL_HEADER32 oh;
const IMAGE_OPTIONAL_HEADER32 *optionalHeader; const IMAGE_OPTIONAL_HEADER32 *optionalHeader;
/* in case optional header is missing or partial */ /* in case optional header is missing or partial */
memset(&oh, 0, sizeof(oh)); memset(&oh, 0, sizeof(oh));
memcpy(&oh, image_oh, min(header_size, sizeof(oh))); memcpy(&oh, image_oh, min(dump_total_len - ((char *)image_oh - (char *)dump_base), sizeof(oh)));
optionalHeader = &oh; optionalHeader = &oh;
print_word("Magic", optionalHeader->Magic); print_word("Magic", optionalHeader->Magic);
...@@ -320,14 +320,14 @@ static void dump_optional_header32(const IMAGE_OPTIONAL_HEADER32 *image_oh, UINT ...@@ -320,14 +320,14 @@ static void dump_optional_header32(const IMAGE_OPTIONAL_HEADER32 *image_oh, UINT
printf("\n"); printf("\n");
} }
static void dump_optional_header64(const IMAGE_OPTIONAL_HEADER64 *image_oh, UINT header_size) static void dump_optional_header64(const IMAGE_OPTIONAL_HEADER64 *image_oh)
{ {
IMAGE_OPTIONAL_HEADER64 oh; IMAGE_OPTIONAL_HEADER64 oh;
const IMAGE_OPTIONAL_HEADER64 *optionalHeader; const IMAGE_OPTIONAL_HEADER64 *optionalHeader;
/* in case optional header is missing or partial */ /* in case optional header is missing or partial */
memset(&oh, 0, sizeof(oh)); memset(&oh, 0, sizeof(oh));
memcpy(&oh, image_oh, min(header_size, sizeof(oh))); memcpy(&oh, image_oh, min(dump_total_len - ((char *)image_oh - (char *)dump_base), sizeof(oh)));
optionalHeader = &oh; optionalHeader = &oh;
print_word("Magic", optionalHeader->Magic); print_word("Magic", optionalHeader->Magic);
...@@ -364,16 +364,16 @@ static void dump_optional_header64(const IMAGE_OPTIONAL_HEADER64 *image_oh, UINT ...@@ -364,16 +364,16 @@ static void dump_optional_header64(const IMAGE_OPTIONAL_HEADER64 *image_oh, UINT
printf("\n"); printf("\n");
} }
void dump_optional_header(const IMAGE_OPTIONAL_HEADER32 *optionalHeader, UINT header_size) void dump_optional_header(const IMAGE_OPTIONAL_HEADER32 *optionalHeader)
{ {
printf("Optional Header (%s)\n", get_magic_type(optionalHeader->Magic)); printf("Optional Header (%s)\n", get_magic_type(optionalHeader->Magic));
switch(optionalHeader->Magic) { switch(optionalHeader->Magic) {
case IMAGE_NT_OPTIONAL_HDR32_MAGIC: case IMAGE_NT_OPTIONAL_HDR32_MAGIC:
dump_optional_header32(optionalHeader, header_size); dump_optional_header32(optionalHeader);
break; break;
case IMAGE_NT_OPTIONAL_HDR64_MAGIC: case IMAGE_NT_OPTIONAL_HDR64_MAGIC:
dump_optional_header64((const IMAGE_OPTIONAL_HEADER64 *)optionalHeader, header_size); dump_optional_header64((const IMAGE_OPTIONAL_HEADER64 *)optionalHeader);
break; break;
default: default:
printf(" Unknown optional header magic: 0x%-4X\n", optionalHeader->Magic); printf(" Unknown optional header magic: 0x%-4X\n", optionalHeader->Magic);
...@@ -428,8 +428,7 @@ void dump_file_header(const IMAGE_FILE_HEADER *fileHeader, BOOL is_hybrid) ...@@ -428,8 +428,7 @@ void dump_file_header(const IMAGE_FILE_HEADER *fileHeader, BOOL is_hybrid)
static void dump_pe_header(void) static void dump_pe_header(void)
{ {
dump_file_header(&PE_nt_headers->FileHeader, get_hybrid_metadata() != NULL); dump_file_header(&PE_nt_headers->FileHeader, get_hybrid_metadata() != NULL);
dump_optional_header((const IMAGE_OPTIONAL_HEADER32*)&PE_nt_headers->OptionalHeader, dump_optional_header((const IMAGE_OPTIONAL_HEADER32*)&PE_nt_headers->OptionalHeader);
PE_nt_headers->FileHeader.SizeOfOptionalHeader);
} }
void dump_section_characteristics(DWORD characteristics, const char* sep) void dump_section_characteristics(DWORD characteristics, const char* sep)
......
...@@ -233,7 +233,7 @@ const char* get_unicode_str( const WCHAR *str, int len ); ...@@ -233,7 +233,7 @@ const char* get_unicode_str( const WCHAR *str, int len );
const char* get_symbol_str(const char* symname); const char* get_symbol_str(const char* symname);
void print_fake_dll(void); void print_fake_dll(void);
void dump_file_header(const IMAGE_FILE_HEADER *, BOOL); void dump_file_header(const IMAGE_FILE_HEADER *, BOOL);
void dump_optional_header(const IMAGE_OPTIONAL_HEADER32 *, UINT); void dump_optional_header(const IMAGE_OPTIONAL_HEADER32 *);
void dump_section(const IMAGE_SECTION_HEADER *, const char* strtable); void dump_section(const IMAGE_SECTION_HEADER *, const char* strtable);
void dump_section_characteristics(DWORD characteristics, const char* sep); void dump_section_characteristics(DWORD characteristics, const char* sep);
......
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