[PATCH 01/10] [WineDump]: consistency
Eric Pouech
eric.pouech at wanadoo.fr
Wed Nov 29 14:40:00 CST 2006
- rewrote PE, NE, LE dumping so that they are consistent in
terms of dump function signatures
- avoid passing around the base of the module, but use instead
the PRD function
A+
---
tools/winedump/dump.c | 12 ++++++------
tools/winedump/le.c | 38 ++++++++++++++++++++-----------------
tools/winedump/ne.c | 46 ++++++++++++++++++++++++---------------------
tools/winedump/pe.c | 28 ++++++++++++++++-----------
tools/winedump/pe.h | 3 +--
tools/winedump/winedump.h | 8 +++++---
6 files changed, 73 insertions(+), 62 deletions(-)
diff --git a/tools/winedump/dump.c b/tools/winedump/dump.c
index 9670a98..aa4d58d 100644
--- a/tools/winedump/dump.c
+++ b/tools/winedump/dump.c
@@ -144,21 +144,21 @@ unsigned long Offset(const void* ptr)
return (const char *)ptr - (const char *)dump_base;
}
-static void do_dump( enum FileSig sig, const void* pmt )
+static void do_dump( enum FileSig sig )
{
if (sig == SIG_NE)
{
- ne_dump( dump_base, dump_total_len );
+ ne_dump();
return;
}
if (sig == SIG_LE)
{
- le_dump( dump_base, dump_total_len );
+ le_dump();
return;
}
- pe_dump(pmt);
+ pe_dump();
}
static enum FileSig check_headers(void)
@@ -264,10 +264,10 @@ #endif
case SIG_NE:
case SIG_LE:
printf("Contents of \"%s\": %ld bytes\n\n", name, dump_total_len);
- (*fn)(effective_sig, dump_base);
+ (*fn)(effective_sig);
break;
case SIG_DBG:
- dump_separate_dbg();
+ dbg_dump();
break;
case SIG_DOS:
ret = 0; break;
diff --git a/tools/winedump/le.c b/tools/winedump/le.c
index 84e219d..0cd7084 100644
--- a/tools/winedump/le.c
+++ b/tools/winedump/le.c
@@ -225,7 +225,7 @@ static void dump_le_header( const IMAGE_
le->e32_ddkver);
}
-static void dump_le_objects( const void *base, const IMAGE_VXD_HEADER *le )
+static void dump_le_objects( const IMAGE_VXD_HEADER *le )
{
const struct o32_obj *pobj;
unsigned int i;
@@ -285,7 +285,7 @@ static void dump_le_objects( const void
}
}
-static void dump_le_names( const void *base, const IMAGE_VXD_HEADER *le )
+static void dump_le_names( const IMAGE_VXD_HEADER *le )
{
const unsigned char *pstr = (const unsigned char *)le + le->e32_restab;
@@ -299,7 +299,7 @@ static void dump_le_names( const void *b
if (le->e32_cbnrestab)
{
printf( "\nNon-resident name table:\n" );
- pstr = (const unsigned char *)base + le->e32_nrestab;
+ pstr = PRD(le->e32_nrestab, 0);
while (*pstr)
{
printf( " %4d: %*.*s\n", get_word(pstr + *pstr + 1), *pstr, *pstr,
@@ -309,49 +309,51 @@ static void dump_le_names( const void *b
}
}
-static void dump_le_resources( const void *base, const IMAGE_VXD_HEADER *le )
+static void dump_le_resources( const IMAGE_VXD_HEADER *le )
{
printf( "\nResources:\n" );
printf( " Not Implemented\n" );
}
-static void dump_le_modules( const void *base, const IMAGE_VXD_HEADER *le )
+static void dump_le_modules( const IMAGE_VXD_HEADER *le )
{
printf( "\nImported modulename table:\n" );
printf( " Not Implemented\n" );
}
-static void dump_le_entries( const void *base, const IMAGE_VXD_HEADER *le )
+static void dump_le_entries( const IMAGE_VXD_HEADER *le )
{
printf( "\nEntry table:\n" );
printf( " Not Implemented\n" );
}
-static void dump_le_fixups( const void *base, const IMAGE_VXD_HEADER *le )
+static void dump_le_fixups( const IMAGE_VXD_HEADER *le )
{
printf( "\nFixup table:\n" );
printf( " Not Implemented\n" );
}
-static void dump_le_VxD( const void *base, const IMAGE_VXD_HEADER *le )
+static void dump_le_VxD( const IMAGE_VXD_HEADER *le )
{
printf( "\nVxD descriptor:\n" );
printf( " Not Implemented\n" );
}
-void le_dump( const void *exe, size_t exe_size )
+void le_dump( void )
{
- const IMAGE_DOS_HEADER *dos = exe;
+ const IMAGE_DOS_HEADER *dos;
const IMAGE_VXD_HEADER *le;
- le = (const IMAGE_VXD_HEADER*)((const char *)dos + dos->e_lfanew);
+ dos = PRD(0, sizeof(*dos));
+ if (!dos) return;
+ le = PRD(dos->e_lfanew, sizeof(*le));
dump_le_header( le );
- dump_le_objects( exe, le );
- dump_le_resources( exe, le );
- dump_le_names( exe, le );
- dump_le_entries( exe, le );
- dump_le_modules( exe, le );
- dump_le_fixups( exe, le );
- dump_le_VxD( exe, le );
+ dump_le_objects( le );
+ dump_le_resources( le );
+ dump_le_names( le );
+ dump_le_entries( le );
+ dump_le_modules( le );
+ dump_le_fixups( le );
+ dump_le_VxD( le );
}
diff --git a/tools/winedump/ne.c b/tools/winedump/ne.c
index a9446e8..a9f7dc2 100644
--- a/tools/winedump/ne.c
+++ b/tools/winedump/ne.c
@@ -95,7 +95,7 @@ static void dump_ne_header( const IMAGE_
printf( "Expected version: %d.%d\n", HIBYTE(ne->ne_expver), LOBYTE(ne->ne_expver) );
}
-static void dump_ne_names( const void *base, const IMAGE_OS2_HEADER *ne )
+static void dump_ne_names( const IMAGE_OS2_HEADER *ne )
{
const unsigned char *pstr = (const unsigned char *)ne + ne->ne_restab;
@@ -108,7 +108,7 @@ static void dump_ne_names( const void *b
if (ne->ne_cbnrestab)
{
printf( "\nNon-resident name table:\n" );
- pstr = (const unsigned char *)base + ne->ne_nrestab;
+ pstr = PRD(ne->ne_nrestab, 0);
while (*pstr)
{
printf( " %4d: %*.*s\n", get_word(pstr + *pstr + 1), *pstr, *pstr, pstr + 1 );
@@ -140,7 +140,7 @@ static const char *get_resource_type( WO
}
}
-static void dump_ne_resources( const void *base, const IMAGE_OS2_HEADER *ne )
+static void dump_ne_resources( const IMAGE_OS2_HEADER *ne )
{
const NE_NAMEINFO *name;
const void *res_ptr = (const char *)ne + ne->ne_rsrctab;
@@ -161,14 +161,14 @@ static void dump_ne_resources( const voi
else printf( " %.*s", *((const unsigned char *)res_ptr + info->type_id),
(const char *)res_ptr + info->type_id + 1 );
printf(" flags %04x length %04x\n", name->flags, name->length << size_shift);
- dump_data( (const unsigned char *)base + (name->offset << size_shift),
+ dump_data( PRD(name->offset << size_shift, name->length << size_shift),
name->length << size_shift, " " );
}
info = (const NE_TYPEINFO *)name;
}
}
-static const char *get_export_name( const void *base, const IMAGE_OS2_HEADER *ne, int ordinal )
+static const char *get_export_name( const IMAGE_OS2_HEADER *ne, int ordinal )
{
static char name[256];
const BYTE *pstr;
@@ -186,7 +186,7 @@ static const char *get_export_name( cons
else /* non-resident names */
{
if (!ne->ne_cbnrestab) break;
- pstr = (const BYTE *)base + ne->ne_nrestab;
+ pstr = PRD(ne->ne_nrestab, 0);
}
while (*pstr)
{
@@ -205,7 +205,7 @@ static const char *get_export_name( cons
return name;
}
-static void dump_ne_exports( const void *base, const IMAGE_OS2_HEADER *ne )
+static void dump_ne_exports( const IMAGE_OS2_HEADER *ne )
{
const BYTE *ptr = (const BYTE *)ne + ne->ne_enttab;
const BYTE *end = ptr + ne->ne_cbenttab;
@@ -229,7 +229,7 @@ static void dump_ne_exports( const void
{
printf( " %4d MOVABLE %d:%04x %s\n",
ordinal + i, ptr[3], get_word(ptr + 4),
- get_export_name( base, ne, ordinal + i ) );
+ get_export_name( ne, ordinal + i ) );
ptr += 6;
}
ordinal += count;
@@ -239,7 +239,7 @@ static void dump_ne_exports( const void
{
printf( " %4d CONST %04x %s\n",
ordinal + i, get_word(ptr + 1),
- get_export_name( base, ne, ordinal + i ) );
+ get_export_name( ne, ordinal + i ) );
ptr += 3;
}
ordinal += count;
@@ -249,7 +249,7 @@ static void dump_ne_exports( const void
{
printf( " %4d FIXED %d:%04x %s\n",
ordinal + i, type, get_word(ptr + 1),
- get_export_name( base, ne, ordinal + i ) );
+ get_export_name( ne, ordinal + i ) );
ptr += 3;
}
ordinal += count;
@@ -300,7 +300,7 @@ #undef ADD_FLAG
return buffer;
}
-static void dump_relocations( const void *base, const IMAGE_OS2_HEADER *ne, WORD count,
+static void dump_relocations( const IMAGE_OS2_HEADER *ne, WORD count,
const struct relocation_entry *rep )
{
const WORD *modref = (const WORD *)((const BYTE *)ne + ne->ne_modtab);
@@ -354,7 +354,7 @@ static void dump_relocations( const void
}
}
-static void dump_ne_segment( const void *base, const IMAGE_OS2_HEADER *ne, int segnum )
+static void dump_ne_segment( const IMAGE_OS2_HEADER *ne, int segnum )
{
const struct ne_segtable_entry *table = (const struct ne_segtable_entry *)((const BYTE *)ne + ne->ne_segtab);
const struct ne_segtable_entry *seg = table + segnum - 1;
@@ -366,23 +366,27 @@ static void dump_ne_segment( const void
printf( " Alloc size: %08x\n", seg->min_alloc );
if (seg->seg_flags & NE_SEGFLAGS_RELOC_DATA)
{
- const BYTE *ptr = (const BYTE *)base + (seg->seg_data_offset << ne->ne_align) + seg->seg_data_length;
+ const BYTE *ptr = PRD((seg->seg_data_offset << ne->ne_align) + seg->seg_data_length, 0);
WORD count = get_word(ptr);
ptr += sizeof(WORD);
printf( " Relocations:\n" );
- dump_relocations( base, ne, count, (const struct relocation_entry *)ptr );
+ dump_relocations( ne, count, (const struct relocation_entry *)ptr );
}
}
-void ne_dump( const void *exe, size_t exe_size )
+void ne_dump( void )
{
unsigned int i;
- const IMAGE_DOS_HEADER *dos = exe;
- const IMAGE_OS2_HEADER *ne = (const IMAGE_OS2_HEADER *)((const char *)dos + dos->e_lfanew);
+ const IMAGE_DOS_HEADER *dos;
+ const IMAGE_OS2_HEADER *ne;
+
+ dos = PRD(0, sizeof(*dos));
+ if (!dos) return;
+ ne = PRD(dos->e_lfanew, sizeof(*ne));
dump_ne_header( ne );
- dump_ne_names( exe, ne );
- dump_ne_resources( exe, ne );
- dump_ne_exports( exe, ne );
- for (i = 1; i <= ne->ne_cseg; i++) dump_ne_segment( exe, ne, i );
+ dump_ne_names( ne );
+ dump_ne_resources( ne );
+ dump_ne_exports( ne );
+ for (i = 1; i <= ne->ne_cseg; i++) dump_ne_segment( ne, i );
}
diff --git a/tools/winedump/pe.c b/tools/winedump/pe.c
index 7e87ff0..210b100 100644
--- a/tools/winedump/pe.c
+++ b/tools/winedump/pe.c
@@ -87,18 +87,22 @@ static const void* RVA(unsigned long rva
return NULL;
}
-static const IMAGE_NT_HEADERS32 *get_nt_header( const void *pmt )
+static const IMAGE_NT_HEADERS32 *get_nt_header( void )
{
- const IMAGE_DOS_HEADER *dos = pmt;
- return (const IMAGE_NT_HEADERS32 *)((const BYTE *)dos + dos->e_lfanew);
+ const IMAGE_DOS_HEADER *dos;
+ dos = PRD(0, sizeof(*dos));
+ if (!dos) return NULL;
+ return PRD(dos->e_lfanew, sizeof(IMAGE_NT_HEADERS32));
}
-static int is_fake_dll( const void *base )
+static int is_fake_dll( void )
{
static const char fakedll_signature[] = "Wine placeholder DLL";
- const IMAGE_DOS_HEADER *dos = base;
+ const IMAGE_DOS_HEADER *dos;
- if (dos->e_lfanew >= sizeof(*dos) + sizeof(fakedll_signature) &&
+ dos = PRD(0, sizeof(*dos) + sizeof(fakedll_signature));
+
+ if (dos && dos->e_lfanew >= sizeof(*dos) + sizeof(fakedll_signature) &&
!memcmp( dos + 1, fakedll_signature, sizeof(fakedll_signature) )) return TRUE;
return FALSE;
}
@@ -781,7 +785,7 @@ static void dump_dir_tls(void)
printf(" }\n\n");
}
-void dump_separate_dbg(void)
+void dbg_dump(void)
{
const IMAGE_SEPARATE_DEBUG_HEADER* separateDebugHead;
unsigned nb_dbg;
@@ -1108,12 +1112,12 @@ static void dump_debug(void)
dump_stabs(stabs, szstabs, stabstr, szstr);
}
-void pe_dump(const void* pmt)
+void pe_dump(void)
{
int all = (globals.dumpsect != NULL) && strcmp(globals.dumpsect, "ALL") == 0;
- PE_nt_headers = get_nt_header(pmt);
- if (is_fake_dll(pmt)) printf( "*** This is a Wine fake DLL ***\n\n" );
+ PE_nt_headers = get_nt_header();
+ if (is_fake_dll()) printf( "*** This is a Wine fake DLL ***\n\n" );
if (globals.do_dumpheader)
{
@@ -1188,7 +1192,7 @@ static void dll_close (void)
}
*/
-static void do_grab_sym( enum FileSig sig, const void* pmt )
+static void do_grab_sym( enum FileSig sig )
{
const IMAGE_EXPORT_DIRECTORY*exportDir;
unsigned i, j;
@@ -1198,7 +1202,7 @@ static void do_grab_sym( enum FileSig si
const char* ptr;
DWORD* map;
- PE_nt_headers = get_nt_header(pmt);
+ PE_nt_headers = get_nt_header();
if (!(exportDir = get_dir(IMAGE_FILE_EXPORT_DIRECTORY))) return;
pName = RVA(exportDir->AddressOfNames, exportDir->NumberOfNames * sizeof(DWORD));
diff --git a/tools/winedump/pe.h b/tools/winedump/pe.h
index c69a8f1..c564174 100644
--- a/tools/winedump/pe.h
+++ b/tools/winedump/pe.h
@@ -21,5 +21,4 @@
extern void dump_codeview(unsigned long ptr, unsigned long len);
extern void dump_coff(unsigned long coffbase, unsigned long len, const void* sect_map);
extern void dump_frame_pointer_omission(unsigned long base, unsigned long len);
-extern void dump_separate_dbg(void);
-extern void pe_dump(const void*);
+
diff --git a/tools/winedump/winedump.h b/tools/winedump/winedump.h
index bb7f966..aa257f3 100644
--- a/tools/winedump/winedump.h
+++ b/tools/winedump/winedump.h
@@ -229,7 +229,7 @@ enum FileSig {SIG_UNKNOWN, SIG_DOS, SIG_
const void* PRD(unsigned long prd, unsigned long len);
unsigned long Offset(const void* ptr);
-typedef void (*file_dumper)(enum FileSig, const void*);
+typedef void (*file_dumper)(enum FileSig sig);
int dump_analysis(const char*, file_dumper, enum FileSig);
void dump_data( const unsigned char *ptr, unsigned int size, const char *prefix );
@@ -237,10 +237,12 @@ const char* get_time_str( unsigned long
unsigned int strlenW( const unsigned short *str );
void dump_unicode_str( const unsigned short *str, int len );
-void ne_dump( const void *exe, size_t exe_size );
-void le_dump( const void *exe, size_t exe_size );
+void ne_dump( void );
+void le_dump( void );
void mdmp_dump( void );
void lib_dump( const char *lib_base, unsigned long lib_size );
+void dbg_dump( void );
+void pe_dump( void );
void dump_stabs(const void* pv_stabs, unsigned szstabs, const char* stabstr, unsigned szstr);
More information about the wine-patches
mailing list