From daa6a7a97d021f371585b18d761e122e258676b9 Mon Sep 17 00:00:00 2001 From: "Guy L. Albertelli" Date: Tue, 16 Oct 2001 21:46:58 +0000 Subject: [PATCH] - eliminate different segmentation faults. - when attempting to open a dll, append ".dll" to find it (was stripped previously). - identify named exports so that the ordinal number is "@" in .spec file. - setup output dll name prior to creating ordinal symbols. - don't overlay the named exports with the ordinal exports. - correct test for last symbol. - fix generated install script to match current make files. --- tools/winedump/main.c | 1 + tools/winedump/output.c | 24 ++++++++++---------- tools/winedump/pe.c | 49 ++++++++++++++++++++++++++--------------- 3 files changed, 44 insertions(+), 30 deletions(-) diff --git a/tools/winedump/main.c b/tools/winedump/main.c index 0127bec4b8d..700bc00870d 100644 --- a/tools/winedump/main.c +++ b/tools/winedump/main.c @@ -261,6 +261,7 @@ int main (int argc, char *argv[]) int count = 0; globals.mode = NONE; + globals.forward_dll = NULL; parse_options (argv); diff --git a/tools/winedump/output.c b/tools/winedump/output.c index 213ed1344de..b9ebee019fc 100644 --- a/tools/winedump/output.c +++ b/tools/winedump/output.c @@ -57,7 +57,7 @@ void output_spec_symbol (const parsed_symbol *sym) assert (specfile); assert (sym && sym->symbol); - if (globals.do_ordinals) + if (sym->ordinal >= 0) snprintf(ord_spec, 8, "%d", sym->ordinal); else { @@ -455,22 +455,22 @@ void output_install_script (void) "\texit 1\nfi\n\necho Adding DLL %s to Wine build tree...\n" "echo\n\nmkdir $1/dlls/%s\ncp %s.spec $1/dlls/%s\n" "cp %s_main.c $1/dlls/%s\ncp %s_dll.h $1/dlls/%s\n" - "cp Makefile.in $1/dlls/%s\necho Copied DLL files\n\n" + "cp Makefile.in $1/dlls/%s/Makefile.in\necho Copied DLL files\n\n" "cd $1\n\nsed '/dlls\\/" "x11drv\\/Makefile/{G;s/$/dlls\\/%s\\/Makefile/;}' configure.in" " >t.tmp\nmv -f t.tmp configure.in\necho Patched configure.in\n\n" - "sed '/ws2_32/{G;s/$/\\^%s \\\\/;}' Make.rules.in | tr ^ \\\\t" - " >t.tmp\nmv -f t.tmp Make.rules.in\necho Patched Make.rules.in" - "\n\nsed '/DLLFILES =/{G;s/$/\\^%s\\/lib%s.so \\\\/;}'" + "sed '/all:/{G;s/$/\\^lib%s.so \\\\/;}'" " dlls/Makefile.in| tr ^ \\\\t >t.tmp\n" "sed '/SUBDIRS =/{G;s/$/\\^%s \\\\/;}' t.tmp | tr ^ \\\\t >t.tmp2" "\nsed '/Map library name /{G;s/$/^\\$(RM) \\$\\@ \\&\\& \\$\\" - "(LN_S\\) %s\\/lib%s.\\@LIBEXT\\@ \\$\\@/;}' t.tmp2 | tr ^ \\\\t" - " > t.tmp\nsed '/Map library name /{G;s/$/lib%s.\\@LIBEXT\\@: " - "%s\\/lib%s.\\@LIBEXT\\@/;}' t.tmp > t.tmp2\nsed '/dll " - "dependencies /{G;s/$/%s\\/lib%s.\\@LIBEXT\\@\\: libkernel32." - "\\@LIBEXT\\@ libntdll.\\@LIBEXT\\@/;}' t.tmp2 > t.tmp\n" - "mv -f t.tmp dlls/Makefile.in\nrm -f t.tmp2\necho Patched dlls/" + "(LN_S\\) %s\\/lib%s.\\$(LIBEXT) \\$\\@/;}' t.tmp2 | tr ^ \\\\t" + " > t.tmp\nsed '/Map library name /{G;s/$/lib%s.\\$(LIBEXT): " + "%s\\/lib%s.\\$(LIBEXT)/;}' t.tmp > t.tmp2\nsed '/dll " + "dependencies/{G;s/$/^\\@cd %s \\&\\& \\$(MAKE) lib%s.\\$(LIBEXT)" + "/;}' t.tmp2 | tr ^ \\\\t > t.tmp\nsed '/dll " + "dependencies/{G;s/$/%s\\/lib%s.\\$(LIBEXT)\\: libkernel32." + "\\$(LIBEXT) libntdll.\\$(LIBEXT)/;}' t.tmp > t.tmp2\n" + "mv -f t.tmp2 dlls/Makefile.in\nrm -f t.tmp\necho Patched dlls/" "Makefile.in\n\necho\necho ...done.\necho Run \\'autoconf\\', " "\\'./configure\\' then \\'make\\' to rebuild Wine\n\n", OUTPUT_DLL_NAME, OUTPUT_DLL_NAME, OUTPUT_DLL_NAME, OUTPUT_DLL_NAME, @@ -520,7 +520,7 @@ void output_c_banner (const parsed_symbol *sym) char ord_spec[16]; size_t i; - if (globals.do_ordinals) + if (sym->ordinal >= 0) snprintf(ord_spec, sizeof (ord_spec), "%d", sym->ordinal); else { diff --git a/tools/winedump/pe.c b/tools/winedump/pe.c index b98b4c878aa..bd6e21de4b3 100644 --- a/tools/winedump/pe.c +++ b/tools/winedump/pe.c @@ -653,13 +653,20 @@ static enum FileSig check_headers(void) 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); - fd = open(name, O_RDONLY); + len = strlen(name) + 5; + name_suffix = malloc(len); + strcpy(name_suffix, name); + strcat(name_suffix, ".dll"); + + fd = open(name_suffix, O_RDONLY); if (fd == -1) fatal("Can't open file"); if (fstat(fd, &s) < 0) fatal("Can't get size"); @@ -740,7 +747,10 @@ static int symbol_cmp(const void *left, const void *right) static void dll_close (void) { dll_symbol* ds; - + + if (!dll_symbols) { + fatal("No symbols"); + } for (ds = dll_symbols; ds->symbol; ds++) free(ds->symbol); free (dll_symbols); @@ -750,7 +760,7 @@ static void dll_close (void) static void do_grab_sym(void) { IMAGE_EXPORT_DIRECTORY *exportDir = get_dir(IMAGE_FILE_EXPORT_DIRECTORY); - unsigned i; + unsigned i, j; DWORD* pName; DWORD* pFunc; WORD* pOrdl; @@ -764,7 +774,7 @@ static void do_grab_sym(void) pOrdl = RVA(exportDir->AddressOfNameOrdinals, exportDir->NumberOfNames * sizeof(WORD)); if (!pOrdl) {printf("Can't grab functions' ordinal table\n"); return;} - dll_close(); + /* dll_close(); */ if (!(dll_symbols = (dll_symbol *) malloc((exportDir->NumberOfFunctions + 1) * sizeof (dll_symbol)))) @@ -776,19 +786,26 @@ static void do_grab_sym(void) map = calloc(((exportDir->NumberOfFunctions + 31) & ~31) / 32, sizeof(DWORD)); if (!map) fatal("no memory"); - for (i = 0; i < exportDir->NumberOfNames; i++) + for (j = 0; j < exportDir->NumberOfNames; j++, pOrdl++) { map[*pOrdl / 32] |= 1 << (*pOrdl % 32); ptr = RVA(*pName++, sizeof(DWORD)); if (!ptr) ptr = "cant_get_function"; - dll_symbols[i].symbol = strdup(ptr); - assert(dll_symbols[i].symbol); + dll_symbols[j].symbol = strdup(ptr); + dll_symbols[j].ordinal = -1; /* indicate non-ordinal symbol */ + assert(dll_symbols[j].symbol); } 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 (!(map[i / 32] & (1 << (i % 32)))) + if (pFunc[i] && !(map[i / 32] & (1 << (i % 32)))) { char ordinal_text[256]; /* Ordinal only entry */ @@ -796,9 +813,11 @@ static void do_grab_sym(void) globals.forward_dll ? globals.forward_dll : OUTPUT_UC_DLL_NAME, exportDir->Base + i); str_toupper(ordinal_text); - dll_symbols[i].symbol = strdup(ordinal_text); - assert(dll_symbols[i].symbol); - dll_symbols[i].ordinal = exportDir->Base + i; + dll_symbols[j].symbol = strdup(ordinal_text); + assert(dll_symbols[j].symbol); + dll_symbols[j].ordinal = exportDir->Base + i; + j++; + assert(j <= exportDir->NumberOfFunctions); } } free(map); @@ -812,12 +831,6 @@ static void do_grab_sym(void) dll_symbols[exportDir->NumberOfFunctions].symbol = NULL; dll_current_symbol = dll_symbols; - - /* 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)); } /******************************************************************* @@ -837,7 +850,7 @@ void dll_open (const char *dll_name) */ int dll_next_symbol (parsed_symbol * sym) { - if (!dll_current_symbol) + if (!dll_current_symbol->symbol) return 1; assert (dll_symbols);