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

winedump: Dump the EMF files as any other file types.

Internally, make use of the PRD function for checking available file ranges.
parent cac7be48
...@@ -159,6 +159,7 @@ dumpers[] = ...@@ -159,6 +159,7 @@ dumpers[] =
{SIG_COFFLIB, get_kind_lib, lib_dump}, {SIG_COFFLIB, get_kind_lib, lib_dump},
{SIG_MDMP, get_kind_mdmp, mdmp_dump}, {SIG_MDMP, get_kind_mdmp, mdmp_dump},
{SIG_LNK, get_kind_lnk, lnk_dump}, {SIG_LNK, get_kind_lnk, lnk_dump},
{SIG_EMF, get_kind_emf, emf_dump},
{SIG_UNKNOWN, NULL, NULL} /* sentinel */ {SIG_UNKNOWN, NULL, NULL} /* sentinel */
}; };
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
#include "winbase.h" #include "winbase.h"
#include "wingdi.h" #include "wingdi.h"
static unsigned int read_int(unsigned char *buffer) static unsigned int read_int(const unsigned char *buffer)
{ {
return buffer[0] return buffer[0]
+ (buffer[1]<<8) + (buffer[1]<<8)
...@@ -46,18 +46,18 @@ static unsigned int read_int(unsigned char *buffer) ...@@ -46,18 +46,18 @@ static unsigned int read_int(unsigned char *buffer)
#define EMRCASE(x) case x: printf("%-20s %08x\n", #x, length); break #define EMRCASE(x) case x: printf("%-20s %08x\n", #x, length); break
static int dump_emfrecord(int fd) static unsigned offset = 0;
static int dump_emfrecord(void)
{ {
unsigned char buffer[8]; const unsigned char* ptr;
int r;
unsigned int type, length, i; unsigned int type, length, i;
r = read(fd, buffer, 8); ptr = PRD(offset, 8);
if(r!=8) if (!ptr) return -1;
return -1;
type = read_int(buffer); type = read_int(ptr);
length = read_int(buffer+4); length = read_int(ptr + 4);
switch(type) switch(type)
{ {
...@@ -96,36 +96,34 @@ static int dump_emfrecord(int fd) ...@@ -96,36 +96,34 @@ static int dump_emfrecord(int fd)
length -= 8; length -= 8;
offset += 8;
for(i=0; i<length; i+=4) for(i=0; i<length; i+=4)
{ {
if (i%16 == 0) if (i%16 == 0)
printf(" "); printf(" ");
memset(buffer,0,sizeof buffer); if (!(ptr = PRD(offset, 4))) return -1;
r = read(fd,buffer,4); offset += 4;
if(r!=4) printf("%08x ", read_int(ptr));
return -1; if ( (i % 16 == 12) || (i + 4 == length))
printf("%08x ", read_int(buffer));
if ( (i%16 == 12) || ((i+4)==length) )
printf("\n"); printf("\n");
} }
return 0; return 0;
} }
static int dump_emf_records(int fd) enum FileSig get_kind_emf(void)
{ {
while(!dump_emfrecord(fd)) const ENHMETAHEADER* hdr;
;
return 0; hdr = PRD(0, sizeof(*hdr));
if (hdr && hdr->iType == EMR_HEADER && hdr->dSignature == ENHMETA_SIGNATURE)
return SIG_EMF;
return SIG_UNKNOWN;
} }
int dump_emf(const char *emf) void emf_dump(void)
{ {
int fd; offset = 0;
while (!dump_emfrecord());
fd = open(emf,O_RDONLY);
if (fd<0) return -1;
dump_emf_records(fd);
close(fd);
return 0;
} }
...@@ -80,13 +80,6 @@ static void do_dump (const char *arg) ...@@ -80,13 +80,6 @@ static void do_dump (const char *arg)
} }
static void do_dumpemf(void)
{
if (globals.mode != NONE) fatal("Only one mode can be specified\n");
globals.mode = EMF;
}
static void do_code (void) static void do_code (void)
{ {
globals.do_code = 1; globals.do_code = 1;
...@@ -223,20 +216,19 @@ static const struct my_option option_table[] = { ...@@ -223,20 +216,19 @@ static const struct my_option option_table[] = {
{"-S", SPEC, 1, do_symfile, "-S symfile Search only prototype names found in 'symfile'"}, {"-S", SPEC, 1, do_symfile, "-S symfile Search only prototype names found in 'symfile'"},
{"-q", SPEC, 0, do_quiet, "-q Don't show progress (quiet)."}, {"-q", SPEC, 0, do_quiet, "-q Don't show progress (quiet)."},
{"-v", SPEC, 0, do_verbose, "-v Show lots of detail while working (verbose)."}, {"-v", SPEC, 0, do_verbose, "-v Show lots of detail while working (verbose)."},
{"dump", DUMP, 0, do_dump, "dump <file> Dumps the contents of the file (dll, exe, lib...)"}, {"dump", DUMP, 0, do_dump, "dump <file> Dumps the contents of a file (dll, exe, lib...)"},
{"-C", DUMP, 0, do_symdmngl, "-C Turns on symbol demangling"}, {"-C", DUMP, 0, do_symdmngl, "-C Turns on symbol demangling"},
{"-f", DUMP, 0, do_dumphead, "-f Dumps file header information"}, {"-f", DUMP, 0, do_dumphead, "-f Dumps file header information"},
{"-G", DUMP, 0, do_rawdebug, "-G Dumps raw debug information"}, {"-G", DUMP, 0, do_rawdebug, "-G Dumps raw debug information"},
{"-j", DUMP, 1, do_dumpsect, "-j sect_name Dumps only the content of section sect_name (import, export, debug, resource, tls)"}, {"-j", DUMP, 1, do_dumpsect, "-j sect_name Dumps only the content of section sect_name (import, export, debug, resource, tls)"},
{"-x", DUMP, 0, do_dumpall, "-x Dumps everything"}, {"-x", DUMP, 0, do_dumpall, "-x Dumps everything"},
{"emf", EMF, 0, do_dumpemf, "emf Dumps an Enhanced Meta File"},
{NULL, NONE, 0, NULL, NULL} {NULL, NONE, 0, NULL, NULL}
}; };
void do_usage (void) void do_usage (void)
{ {
const struct my_option *opt; const struct my_option *opt;
printf ("Usage: winedump [-h | sym <sym> | spec <dll> | dump <file> | emf <emf>]\n"); printf ("Usage: winedump [-h | sym <sym> | spec <dll> | dump <file>]\n");
printf ("Mode options (can be put as the mode (sym/spec/dump...) is declared):\n"); printf ("Mode options (can be put as the mode (sym/spec/dump...) is declared):\n");
printf ("\tWhen used in --help mode\n"); printf ("\tWhen used in --help mode\n");
for (opt = option_table; opt->name; opt++) for (opt = option_table; opt->name; opt++)
...@@ -254,10 +246,6 @@ void do_usage (void) ...@@ -254,10 +246,6 @@ void do_usage (void)
for (opt = option_table; opt->name; opt++) for (opt = option_table; opt->name; opt++)
if (opt->mode == DUMP) if (opt->mode == DUMP)
printf ("\t %s\n", opt->usage); printf ("\t %s\n", opt->usage);
printf ("\tWhen used in emf mode\n");
for (opt = option_table; opt->name; opt++)
if (opt->mode == EMF)
printf ("\t %s\n", opt->usage);
puts (""); puts ("");
exit (1); exit (1);
...@@ -489,11 +477,6 @@ int main (int argc, char *argv[]) ...@@ -489,11 +477,6 @@ int main (int argc, char *argv[])
set_module_name(0); set_module_name(0);
dump_file(globals.input_name); dump_file(globals.input_name);
break; break;
case EMF:
if (globals.input_name == NULL)
fatal("No file name has been given\n");
dump_emf(globals.input_name);
break;
} }
return 0; return 0;
......
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
#define SYM_THISCALL 0x4 #define SYM_THISCALL 0x4
#define SYM_DATA 0x8 /* Data, not a function */ #define SYM_DATA 0x8 /* Data, not a function */
typedef enum {NONE, DMGL, SPEC, DUMP, EMF} Mode; typedef enum {NONE, DMGL, SPEC, DUMP} Mode;
/* Structure holding a parsed symbol */ /* Structure holding a parsed symbol */
typedef struct __parsed_symbol typedef struct __parsed_symbol
...@@ -156,9 +156,6 @@ extern _globals globals; ...@@ -156,9 +156,6 @@ extern _globals globals;
/* Default calling convention */ /* Default calling convention */
#define CALLING_CONVENTION (globals.do_cdecl ? SYM_CDECL : SYM_STDCALL) #define CALLING_CONVENTION (globals.do_cdecl ? SYM_CDECL : SYM_STDCALL)
/* EMF functions */
int dump_emf (const char *emf);
/* Image functions */ /* Image functions */
void dump_file(const char* name); void dump_file(const char* name);
...@@ -221,7 +218,7 @@ char *str_toupper (char *str); ...@@ -221,7 +218,7 @@ char *str_toupper (char *str);
const char *get_machine_str(int mach); const char *get_machine_str(int mach);
/* file dumping functions */ /* file dumping functions */
enum FileSig {SIG_UNKNOWN, SIG_DOS, SIG_PE, SIG_DBG, SIG_NE, SIG_LE, SIG_MDMP, SIG_COFFLIB, SIG_LNK}; enum FileSig {SIG_UNKNOWN, SIG_DOS, SIG_PE, SIG_DBG, SIG_NE, SIG_LE, SIG_MDMP, SIG_COFFLIB, SIG_LNK, SIG_EMF};
const void* PRD(unsigned long prd, unsigned long len); const void* PRD(unsigned long prd, unsigned long len);
unsigned long Offset(const void* ptr); unsigned long Offset(const void* ptr);
...@@ -246,6 +243,9 @@ enum FileSig get_kind_dbg(void); ...@@ -246,6 +243,9 @@ enum FileSig get_kind_dbg(void);
void dbg_dump( void ); void dbg_dump( void );
enum FileSig get_kind_lnk(void); enum FileSig get_kind_lnk(void);
void lnk_dump( void ); void lnk_dump( void );
enum FileSig get_kind_emf(void);
void emf_dump( void );
void dump_stabs(const void* pv_stabs, unsigned szstabs, const char* stabstr, unsigned szstr); void dump_stabs(const void* pv_stabs, unsigned szstabs, const char* stabstr, unsigned szstr);
void dump_codeview(unsigned long ptr, unsigned long len); void dump_codeview(unsigned long ptr, unsigned long len);
......
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