a few fixes to winedump

eric pouech eric.pouech at wanadoo.fr
Tue Oct 30 15:29:13 CST 2001


this patch fixes a few bugs in winedump
- first of all, all input files are not DLLs (or don't necessarly have
their name end with .dll)
- it also enhances a bit the function pointer parameter demangling
(still ugly, but better than nothing)

A+
-- 
---------------
Eric Pouech (http://perso.wanadoo.fr/eric.pouech/)
"The future will be better tomorrow", Vice President Dan Quayle
-------------- next part --------------
Name: winedump
ChangeLog: fixed and globalized some path and module name handling
	tweaked the demangling of function pointers as function parameters
GenDate: 2001/10/30 21:23:50 UTC
ModifiedFiles: tools/winedump/main.c tools/winedump/msmangle.c tools/winedump/output.c tools/winedump/pe.c tools/winedump/winedump.h
AddedFiles: 
===================================================================
RCS file: /usr/share/cvs/cvsroot/wine/wine/tools/winedump/main.c,v
retrieving revision 1.4
diff -u -u -r1.4 main.c
--- tools/winedump/main.c	2001/10/16 21:46:58	1.4
+++ tools/winedump/main.c	2001/10/27 06:32:15
@@ -36,7 +36,7 @@
 {
     if (globals.mode != NONE) fatal("Only one mode can be specified\n");
     globals.mode = SPEC;
-    globals.input_name = strip_ext (arg);
+    globals.input_name = arg;
 }
 
 
@@ -162,7 +162,7 @@
   {"-e",    SPEC, 1, do_end,      "-e num       End prototype search after symbol 'num'"},
   {"-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, 2, do_dump,     "dump <dll>   Dumps the content of the dll named <dll>"},
+  {"dump",  DUMP, 2, do_dump,     "dump <mod>   Dumps the content of the module (dll, exe...) named <mod>"},
   {"-C",    DUMP, 0, do_symdmngl, "-C           Turns on symbol demangling"},
   {"-f",    DUMP, 0, do_dumphead, "-f           Dumps file header information"},
   {"-j",    DUMP, 1, do_dumpsect, "-j sect_name Dumps only the content of section sect_name (import, export, debug)"},
@@ -247,6 +247,29 @@
     fatal ("Options -v and -q are mutually exclusive");
 }
 
+static void set_module_name(unsigned setUC)
+{
+    const char*	ptr;
+    char*	buf;
+    int		len;
+
+    /* FIXME: we shouldn't assume all module extensions are .dll in winedump
+     * in some cases, we could have some .drv for example
+     */
+    /* get module name from name */
+    if ((ptr = strrchr (globals.input_name, '/')))
+	ptr++;
+    else
+	ptr = globals.input_name;
+    len = strlen(ptr);
+    if (len > 4 && strcmp(ptr + len - 4, ".dll") == 0)
+	len -= 4;
+    buf = malloc(len + 1);
+    memcpy(buf, (void*)ptr, len);
+    buf[len] = 0;
+    globals.input_module = buf;
+    OUTPUT_UC_DLL_NAME = (setUC) ? str_toupper( strdup (OUTPUT_DLL_NAME)) : "";
+}
 
 /*******************************************************************
  *         main
@@ -274,6 +297,7 @@
 	VERBOSE = 1;
 
 	symbol_init (&symbol, globals.input_name);
+	globals.input_module = "";
 	if (symbol_demangle (&symbol) == -1)
 	    fatal( "Symbol hasn't got a mangled name\n");
 	if (symbol.flags & SYM_DATA)
@@ -285,6 +309,7 @@
 	break;
 
     case SPEC:
+	set_module_name(1);
 	dll_open (globals.input_name);
 
 	output_spec_preamble ();
@@ -335,7 +360,7 @@
 	do_usage();
 	break;
     case DUMP:
-	globals.uc_dll_name = "";
+	set_module_name(0);
 	dump_file(globals.input_name);
 	break;
     }
Index: tools/winedump/msmangle.c
===================================================================
RCS file: /usr/share/cvs/cvsroot/wine/wine/tools/winedump/msmangle.c,v
retrieving revision 1.3
diff -u -u -r1.3 msmangle.c
--- tools/winedump/msmangle.c	2001/09/21 21:03:53	1.3
+++ tools/winedump/msmangle.c	2001/10/27 04:49:48
@@ -487,15 +487,43 @@
         /* FIXME: P6 = Function pointer, others who knows.. */
         if (isdigit (*iter))
 	{
-	  if (*iter == '6') printf("Function pointer in argument list is not handled yet\n");
-          return NULL;
+	  if (*iter == '6') 
+	  {
+	      /* FIXME: there are a tons of memory leaks here */
+	      /* FIXME: this is still broken in some cases and it has to be
+	       * merged with the function prototype parsing above...
+	       */
+	      iter += 3; /* FIXME */
+	      if (!demangle_datatype (&iter, &sub_ct, sym))
+		  return NULL;
+	      ct->expression = str_create(2, sub_ct.expression, " (*)(");
+	      if (*iter != '@')
+	      {
+		  while (*iter != 'Z')
+		  {
+		      FREE_CT (sub_ct);
+		      INIT_CT (sub_ct);
+		      if (!demangle_datatype (&iter, &sub_ct, sym))
+			  return NULL;
+		      ct->expression = str_create(3, ct->expression, ", ", sub_ct.expression);
+		      while (*iter == '@') iter++;
+		  }
+	      } else while (*iter == '@') iter++;
+	      iter++;
+	      ct->expression = str_create(2, ct->expression, ")");
+	      FREE_CT (sub_ct);
+	  }
+	  else 
+	      return NULL;
 	}
+	else
+	{
+	    /* Recurse to get the pointed-to type */
+	    if (!demangle_datatype (&iter, &sub_ct, sym))
+		return NULL;
 
-        /* Recurse to get the pointed-to type */
-        if (!demangle_datatype (&iter, &sub_ct, sym))
-          return NULL;
-
-        ct->expression = get_pointer_type_string (ct, sub_ct.expression);
+	    ct->expression = get_pointer_type_string (ct, sub_ct.expression);
+	}
 
         FREE_CT (sub_ct);
       }
Index: tools/winedump/output.c
===================================================================
RCS file: /usr/share/cvs/cvsroot/wine/wine/tools/winedump/output.c,v
retrieving revision 1.2
diff -u -u -r1.2 output.c
--- tools/winedump/output.c	2001/10/16 21:46:58	1.2
+++ tools/winedump/output.c	2001/10/27 04:34:06
@@ -33,7 +33,7 @@
     puts ("Creating .spec preamble");
 
   fprintf (specfile,
-           "# Generated from %s.dll by winedump\nname    %s\n"
+           "# Generated from %s by winedump\nname    %s\n"
            "type    win32\ninit    %s_Init\n\nimport kernel32.dll\n"
            "import ntdll.dll\n", globals.input_name, OUTPUT_DLL_NAME,
            OUTPUT_UC_DLL_NAME);
@@ -199,7 +199,7 @@
   atexit (output_c_postamble);
 
   fprintf (cfile,
-           "/*\n * %s.dll\n *\n * Generated from %s.dll by winedump.\n *\n"
+           "/*\n * %s.dll\n *\n * Generated from %s by winedump.\n *\n"
            " * DO NOT SUBMIT GENERATED DLLS FOR INCLUSION INTO WINE!\n * \n */"
            "\n\n#include \"%s_dll.h\"\n\nDEFAULT_DEBUG_CHANNEL(%s);\n\n",
            OUTPUT_DLL_NAME, globals.input_name, OUTPUT_DLL_NAME,
@@ -419,7 +419,7 @@
     puts ("Creating makefile");
 
   fprintf (makefile,
-           "# Generated from %s.dll by winedump.\nTOPSRCDIR = @top_srcdir@\n"
+           "# Generated from %s by winedump.\nTOPSRCDIR = @top_srcdir@\n"
            "TOPOBJDIR = ../..\nSRCDIR    = @srcdir@\nVPATH     = @srcdir@\n"
            "MODULE    = %s\nEXTRALIBS = $(LIBUNICODE)\n\n"
            "LDDLLFLAGS = @LDDLLFLAGS@\nSYMBOLFILE = $(MODULE).tmp.o\n\n"
Index: tools/winedump/pe.c
===================================================================
RCS file: /usr/share/cvs/cvsroot/wine/wine/tools/winedump/pe.c,v
retrieving revision 1.5
diff -u -u -r1.5 pe.c
--- tools/winedump/pe.c	2001/10/16 21:46:58	1.5
+++ tools/winedump/pe.c	2001/10/27 04:33:44
@@ -653,20 +653,13 @@
 int pe_analysis(const char* name, void (*fn)(void), enum FileSig wanted_sig)
 {
     int			fd;
-    int                 len;
     enum FileSig	effective_sig;
     int			ret = 1;
     struct stat		s;
-    char                *name_suffix;
 
     setbuf(stdout, NULL);
-    
-    len = strlen(name) + 5;
-    name_suffix = malloc(len);
-    strcpy(name_suffix, name);
-    strcat(name_suffix, ".dll");
 
-    fd = open(name_suffix, O_RDONLY);
+    fd = open(name, O_RDONLY);
     if (fd == -1) fatal("Can't open file");
     
     if (fstat(fd, &s) < 0) fatal("Can't get size");
@@ -798,11 +791,6 @@
     pFunc = RVA(exportDir->AddressOfFunctions, exportDir->NumberOfFunctions * sizeof(DWORD));
     if (!pFunc) {printf("Can't grab functions' address table\n"); return;}
         
-    /* Set DLL output names */
-    if ((ptr = strrchr (globals.input_name, '/')))
-	globals.input_name = ptr + 1; /* Strip path */
-    OUTPUT_UC_DLL_NAME = str_toupper( strdup (OUTPUT_DLL_NAME));
-
     for (i = 0; i < exportDir->NumberOfFunctions; i++)
     {
 	if (pFunc[i] && !(map[i / 32] & (1 << (i % 32))))
Index: tools/winedump/winedump.h
===================================================================
RCS file: /usr/share/cvs/cvsroot/wine/wine/tools/winedump/winedump.h,v
retrieving revision 1.2
diff -u -u -r1.2 winedump.h
--- tools/winedump/winedump.h	2001/09/17 20:26:27	1.2
+++ tools/winedump/winedump.h	2001/10/27 04:31:30
@@ -88,6 +88,7 @@
 
   /* Option arguments: generic */
   const char *input_name;  /* */
+  const char *input_module; /* input module name generated after input_name according mode */
 
   /* Options: spec mode */
   int   do_code;           /* -c, -t, -f */
@@ -118,7 +119,7 @@
 
 /* Names to use for output DLL */
 #define OUTPUT_DLL_NAME \
-          (globals.dll_name ? globals.dll_name : globals.input_name)
+          (globals.dll_name ? globals.dll_name : (globals.input_module ? globals.input_module : globals.input_name))
 #define OUTPUT_UC_DLL_NAME globals.uc_dll_name
 
 /* Verbosity levels */


More information about the wine-patches mailing list