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

Internally, make use of the PRD function for checking available file ranges.
This commit is contained in:
Eric Pouech 2006-11-29 21:40:21 +01:00 committed by Alexandre Julliard
parent cac7be486d
commit c4dc400a88
4 changed files with 33 additions and 51 deletions

View File

@ -159,6 +159,7 @@ dumpers[] =
{SIG_COFFLIB, get_kind_lib, lib_dump},
{SIG_MDMP, get_kind_mdmp, mdmp_dump},
{SIG_LNK, get_kind_lnk, lnk_dump},
{SIG_EMF, get_kind_emf, emf_dump},
{SIG_UNKNOWN, NULL, NULL} /* sentinel */
};

View File

@ -36,7 +36,7 @@
#include "winbase.h"
#include "wingdi.h"
static unsigned int read_int(unsigned char *buffer)
static unsigned int read_int(const unsigned char *buffer)
{
return buffer[0]
+ (buffer[1]<<8)
@ -46,18 +46,18 @@ static unsigned int read_int(unsigned char *buffer)
#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];
int r;
const unsigned char* ptr;
unsigned int type, length, i;
r = read(fd, buffer, 8);
if(r!=8)
return -1;
ptr = PRD(offset, 8);
if (!ptr) return -1;
type = read_int(buffer);
length = read_int(buffer+4);
type = read_int(ptr);
length = read_int(ptr + 4);
switch(type)
{
@ -96,36 +96,34 @@ static int dump_emfrecord(int fd)
length -= 8;
offset += 8;
for(i=0; i<length; i+=4)
{
if (i%16 == 0)
printf(" ");
memset(buffer,0,sizeof buffer);
r = read(fd,buffer,4);
if(r!=4)
return -1;
printf("%08x ", read_int(buffer));
if ( (i%16 == 12) || ((i+4)==length) )
if (!(ptr = PRD(offset, 4))) return -1;
offset += 4;
printf("%08x ", read_int(ptr));
if ( (i % 16 == 12) || (i + 4 == length))
printf("\n");
}
return 0;
}
static int dump_emf_records(int fd)
enum FileSig get_kind_emf(void)
{
while(!dump_emfrecord(fd))
;
return 0;
const ENHMETAHEADER* hdr;
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;
fd = open(emf,O_RDONLY);
if (fd<0) return -1;
dump_emf_records(fd);
close(fd);
return 0;
offset = 0;
while (!dump_emfrecord());
}

View File

@ -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)
{
globals.do_code = 1;
@ -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'"},
{"-q", SPEC, 0, do_quiet, "-q Don't show progress (quiet)."},
{"-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"},
{"-f", DUMP, 0, do_dumphead, "-f Dumps file header 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)"},
{"-x", DUMP, 0, do_dumpall, "-x Dumps everything"},
{"emf", EMF, 0, do_dumpemf, "emf Dumps an Enhanced Meta File"},
{NULL, NONE, 0, NULL, NULL}
};
void do_usage (void)
{
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 ("\tWhen used in --help mode\n");
for (opt = option_table; opt->name; opt++)
@ -254,10 +246,6 @@ void do_usage (void)
for (opt = option_table; opt->name; opt++)
if (opt->mode == DUMP)
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 ("");
exit (1);
@ -489,11 +477,6 @@ int main (int argc, char *argv[])
set_module_name(0);
dump_file(globals.input_name);
break;
case EMF:
if (globals.input_name == NULL)
fatal("No file name has been given\n");
dump_emf(globals.input_name);
break;
}
return 0;

View File

@ -72,7 +72,7 @@
#define SYM_THISCALL 0x4
#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 */
typedef struct __parsed_symbol
@ -156,9 +156,6 @@ extern _globals globals;
/* Default calling convention */
#define CALLING_CONVENTION (globals.do_cdecl ? SYM_CDECL : SYM_STDCALL)
/* EMF functions */
int dump_emf (const char *emf);
/* Image functions */
void dump_file(const char* name);
@ -221,7 +218,7 @@ char *str_toupper (char *str);
const char *get_machine_str(int mach);
/* 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);
unsigned long Offset(const void* ptr);
@ -246,6 +243,9 @@ enum FileSig get_kind_dbg(void);
void dbg_dump( void );
enum FileSig get_kind_lnk(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_codeview(unsigned long ptr, unsigned long len);