winedump

Eric Pouech pouech-eric at wanadoo.fr
Wed Jan 14 15:19:41 CST 2004


this patch should make winedump a bit more robust while dumping 
information (it fixes btw a crash reported on wine-devel some time ago)
A+
-------------- next part --------------
Name:          wd_paranoid
ChangeLog:     being stricter about checks (especially in RVA translations)
License:       X11
GenDate:       2004/01/14 21:18:07 UTC
ModifiedFiles: tools/winedump/main.c tools/winedump/pe.c tools/winedump/winedump.h
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/tools/winedump/main.c,v
retrieving revision 1.13
diff -u -u -r1.13 main.c
--- tools/winedump/main.c	13 May 2003 04:47:53 -0000	1.13
+++ tools/winedump/main.c	1 Jan 2004 08:53:47 -0000
@@ -404,7 +404,8 @@
         if (globals.input_name == NULL)
             fatal("No file name has been given\n");
 	set_module_name(1);
-	dll_open (globals.input_name);
+	if (!dll_open (globals.input_name))
+            break;
 
 	output_spec_preamble ();
 	output_header_preamble ();
Index: tools/winedump/pe.c
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/tools/winedump/pe.c,v
retrieving revision 1.30
diff -u -u -r1.30 pe.c
--- tools/winedump/pe.c	11 Nov 2003 22:04:33 -0000	1.30
+++ tools/winedump/pe.c	1 Jan 2004 08:53:47 -0000
@@ -111,27 +111,23 @@
     IMAGE_SECTION_HEADER*	sectHead;
     int				i;
 
+    if (rva == 0) return NULL;
+
     sectHead = (IMAGE_SECTION_HEADER*)((char*)PE_nt_headers + sizeof(DWORD) +
 				       sizeof(IMAGE_FILE_HEADER) +
 				       PE_nt_headers->FileHeader.SizeOfOptionalHeader);
 
-    if (rva == 0) return NULL;
-
     for (i = PE_nt_headers->FileHeader.NumberOfSections - 1; i >= 0; i--)
     {
         if (sectHead[i].VirtualAddress <= rva &&
             rva + len <= (DWORD)sectHead[i].VirtualAddress + sectHead[i].SizeOfRawData)
-            break;
-    }
-
-    if (i < 0)
-    {
-	printf("rva not found in any section (%lu)\n", rva);
-        return NULL;
+        {
+            /* return image import directory offset */
+            return PRD(sectHead[i].PointerToRawData + rva - sectHead[i].VirtualAddress, len);
+        }
     }
 
-    /* return image import directory offset */
-    return PRD(sectHead[i].PointerToRawData + rva - sectHead[i].VirtualAddress, len);
+    return NULL;
 }
 
 static	void*	get_dir(unsigned idx)
@@ -170,7 +166,7 @@
     printf("  Machine:                      %04X (%s)\n",
 	   fileHeader->Machine, get_machine_str(fileHeader->Machine));
     printf("  Number of Sections:           %d\n", fileHeader->NumberOfSections);
-    printf("  TimeDateStamp:                %08lX (%s) offset %ld\n",
+    printf("  TimeDateStamp:                %08lX (%s) offset %lu\n",
 	   fileHeader->TimeDateStamp, get_time_str(fileHeader->TimeDateStamp),
 	   Offset(&(fileHeader->TimeDateStamp)));
     printf("  PointerToSymbolTable:         %08lX\n", fileHeader->PointerToSymbolTable);
@@ -591,8 +587,12 @@
     printf( "  Callbacks       %08lx -> {", (DWORD)dir->AddressOfCallBacks );
     if (dir->AddressOfCallBacks)
     {
-        callbacks = RVA((DWORD)dir->AddressOfCallBacks - PE_nt_headers->OptionalHeader.ImageBase,0);
-        while (*callbacks) printf( " %08lx", *callbacks++ );
+        DWORD   addr = (DWORD)dir->AddressOfCallBacks - PE_nt_headers->OptionalHeader.ImageBase;
+        while ((callbacks = RVA(addr, sizeof(DWORD))) && *callbacks)
+        {
+            printf( " %08lx", *callbacks );
+            addr += sizeof(DWORD);
+        }
     }
     printf(" }\n\n");
 }
@@ -704,6 +704,11 @@
     unsigned int i, j;
 
     printf( "%s", prefix );
+    if (!ptr)
+    {
+        printf("NULL\n");
+        return;
+    }
     for (i = 0; i < size; i++)
     {
         printf( "%02x%c", ptr[i], (i % 16 == 7) ? '-' : ' ' );
@@ -1224,9 +1229,9 @@
  *
  * Open a DLL and read in exported symbols
  */
-void  dll_open (const char *dll_name)
+int dll_open (const char *dll_name)
 {
-    pe_analysis(dll_name, do_grab_sym, SIG_PE);
+    return pe_analysis(dll_name, do_grab_sym, SIG_PE);
 }
 
 /*******************************************************************
Index: tools/winedump/winedump.h
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/tools/winedump/winedump.h,v
retrieving revision 1.8
diff -u -u -r1.8 winedump.h
--- tools/winedump/winedump.h	26 Nov 2003 03:55:01 -0000	1.8
+++ tools/winedump/winedump.h	1 Jan 2004 08:53:47 -0000
@@ -157,9 +157,9 @@
 void	dump_file(const char* name);
 
 /* DLL functions */
-void  dll_open (const char *dll_name);
+int   dll_open (const char *dll_name);
 
-int dll_next_symbol (parsed_symbol * sym);
+int   dll_next_symbol (parsed_symbol * sym);
 
 /* Symbol functions */
 int   symbol_init(parsed_symbol* symbol, const char* name);


More information about the wine-patches mailing list