Corinna Vinschen wrote: > Well, I had a few tiny problems: > > - VERSION wasn't defined for some reason.
Yeah, oops. That was -Ddefined by the makefile rule. > - Just for kicks, try `peflags --show-image-characteristics=tsaware /bin/bash' > (note: tsaware is a dll-characteristic, not an image-characteristic...) My fault when de-binutils-ifying Dave's patch. einfo() never returns, but I replaced it with fprintf(stderr,...). Fixed. > - Stuff like `./peflags.exe --show-dll-characteristics=tsaware' prints > nothing at all. I guess it should print a help message due to a missing > parameter instead. Fixed. > - peflags --help is missing linebreaks (line 1004 is missing a backslash Typo. '.' is right next to '\'. Patch attached (and gzipped copy of fully-patched .c file). Still need to compile using -DVERSION='"2.4.5"' or something: gcc -o peflags.exe -DVERSION='"2.4.5"' peflags.c Dave: none of Corinna's comments, nor my changes in addressing them, point to any issues with your original patch for binutils. -- Chuck
--- old/peflags.c 2009-03-04 01:00:38.895200000 -0500 +++ new/peflags.c 2009-03-04 22:01:26.361200000 -0500 @@ -184,10 +184,12 @@ int verbose = 0; const char *file_list = 0; const char *stdin_file_list = "-"; +int mark_any = 0; int main (int argc, char *argv[]) { + int files_attempted = 0; int i = 0; parse_args (argc, argv); @@ -198,35 +200,57 @@ int status = 0; char filename[MAX_PATH + 2]; FILE *file = file_list_fopen (file_list); + if (!file) exit (2); while (file_list_fgets (filename, MAX_PATH + 2, file)) { + files_attempted++; if ((status = do_mark (filename)) != 0) break; } file_list_fclose (file); + + if (files_attempted == 0) + { + /* warn the user */ + fprintf (stderr, + "Error: Could not find any filenames in %s\n", + (strcmp(file_list, stdin_file_list) == 0 ? "<stdin>" : file_list)); + exit (2); + } if (status != 0) exit (2); } - /* Operate on files listed as command line arguments. */ + /* Operate on files listed as command line arguments. + * Don't reset files_attempted because we do not require + * any args if -T filelist + */ for (i = args_index; i < argc; i++) { const char *filename = argv[i]; + files_attempted++; if (do_mark (filename) != 0) exit (2); } + if (files_attempted == 0) + { + /* warn the user */ + fprintf (stderr, "Error: no files to process\n"); + short_usage (stderr); + exit (2); + } + exit (0); } int do_mark (const char *pathname) { - int mark_any = FALSE; int has_relocs; int is_executable; int is_dll; @@ -243,12 +267,6 @@ return 0; } - /* determine if we are actually to write anything. Skip - entries in init[] that are display oriented */ - for (i = 0; init[i].ptr; i++) - if (!strendswith (init[i].symbol, SHOWSTR)) - mark_any |= init[i].inited; - if (mark_any) { /* Skip if not writable. */ @@ -619,6 +637,13 @@ *(long *) init[c].ptr = val; else abort (); } + + /* determine if we are actually to write anything. Skip + entries in init[] that are display oriented */ + for (c = 0; init[c].ptr; c++) + if (!strendswith (init[c].symbol, SHOWSTR)) + mark_any |= init[c].inited; + } int @@ -901,8 +926,12 @@ if (flag) flags |= flag->value; else - fprintf (stderr, "Error: unrecognised integer/flag '%s' for PE parameter '%s'\n", - optarg, name); + { + fprintf (stderr, "Error: unrecognised integer/flag '%s' for PE parameter '%s'\n", + optarg, name); + short_usage (stderr); + exit (1); + } if (someVar->inited) someVar->value |= flags; @@ -966,15 +995,23 @@ long value; value = strtoul (optarg, &end, 0); if (end == optarg) - fprintf (stderr, "Error: unrecognised integer/flag '%s' for PE parameter '%s'\n", - optarg, name); + { + fprintf (stderr, "Error: unrecognised integer/flag '%s' for PE parameter '%s'\n", + optarg, name); + short_usage (stderr); + exit (1); + } flags |= value; optarg = end; } /* If there's any more, we do insist on at least one separator. */ if (*optarg && !is_flag_sep (*optarg)) - fprintf (stderr, "Error: unparseable at '%s' for PE parameter '%s'\n", - optarg, name); + { + fprintf (stderr, "Error: unparseable at '%s' for PE parameter '%s'\n", + optarg, name); + short_usage (stderr); + exit (1); + } } set_pe_name (name, flags); @@ -983,7 +1020,7 @@ static void short_usage (FILE *f) { - fputs ("Usage: peflags [OPTIONS] file...\n", f); + fputs ("Usage: peflags [OPTIONS] file(s)...\n", f); fputs ("Sets or clears various flags in PE files (that is, exes and dlls)\n", f); fputs ("Use --help for full help text\n", f); } @@ -991,7 +1028,7 @@ static void help (FILE *f) { - fputs ("Usage: peflags [OPTIONS] file...\n", f); + fputs ("Usage: peflags [OPTIONS] file(s)...\n", f); fputs ("Sets or clears various flags in PE files (that is, exes and dlls)\n", f); fputs (" -d, --dynbase=BOOL Sets or clears the dynbase flag\n", f); fputs (" -t, --tsaware=BOOL Sets or clears the tsaware flag\n", f); @@ -999,14 +1036,17 @@ fputs (" --set-image-characteristics=SPECSTR Set or clear various flags in the\n", f); fputs (" --clr-image-characteristics=SPECSTR 'Characteristics' field of the PE\n", f); fputs (" --show-image-characteristics=SPECSTR file's ImageFileHeader. See winnt.h\n", f); - fputs (" for possible values. The --show-*h\n", f); - fputs (" option indicates which flags to\n", f); - fputs (" display symbolically.n", f); + fputs (" for possible values.\n", f); + fputs (" --show-image-characteristics=SPECSTR Indicates which flags for this field\n", f); + fputs (" to display symbolically. Default: none\n", f); fputs (" --set-dll-characteristics=SPECSTR Set or clear various flags in the\n", f); fputs (" --clr-dll-characteristics=SPECSTR 'DllCharacteristics' field of the\n", f); - fputs (" --show-dll-characteristics=SPECSTR PE file's ImageOptionalHeader. See\n", f); + fputs (" PE file's ImageOptionalHeader. See\n", f); fputs (" winnt.h for possible values; this\n", f); - fputs (" field is not only for DLLs\n", f); + fputs (" field is not only for DLLs.\n", f); + fputs (" --show-dll-characteristics=SPECSTR Indicates which flags for this field\n", f); + fputs (" to display symbolically. Default:\n", f); + fputs (" 'dynbase,nxcompat,tsaware'\n", f); fputs (" -T, --filelist FILE Indicate that FILE contains a list\n", f); fputs (" of PE files to process\n", f); fputs (" --verbose display diagnostic information\n", f); @@ -1028,26 +1068,34 @@ int i; fputs ("Flag help: peflags [OPTIONS] file...\n", f); - fputs ("The --set-* and --clr-* options accept as an argument a specification\n", f); - fputs ("string of the following form:\n", f); + fputs ("The --set-*, --clr-*, and --show-* options accept as an argument a\n", f); + fputs ("specification string of the following form:\n", f); + fputs ("\n", f); fputs (" <name>|<integer>[(+|,:)<name>|<integer>[...]]\n", f); + fputs ("\n", f); fputs ("That is, flag values may be expressed using a combination of numeric\n", f); fputs ("values and symbolic names. For example:\n", f); + fputs ("\n", f); fputs (" --set-dll-characteristics=0x0400|0x0100\n", f); fputs (" --set-dll-characteristics=1+128+1024,noseh,nobind\n", f); fputs (" --set-dll-characteristics=noseh:nobind:tsaware\n", f); + fputs ("\n", f); fputs ("There are a number of these symbolic names, which are listed below\n", f); + fputs ("\n", f); fputs (" --[set|clr|show]-dll-characteristics:\n", f); /* Loop over symbolic names */ for (i = 0; dllchrctnames[i].name; i++) - fprintf (f, " %s\n", dllchrctnames[i].name); + fprintf (f, " 0x%04x = %s\n", + dllchrctnames[i].value, dllchrctnames[i].name); + fputs ("\n", f); fputs (" --[set|clr|show]-image-characteristics:\n", f); /* Loop over symbolic names */ for (i = 0; imgfilechrctnames[i].name; i++) - fprintf (f, " %s\n", imgfilechrctnames[i].name); + fprintf (f, " 0x%04x = %s\n", + imgfilechrctnames[i].value, imgfilechrctnames[i].name); } static void
peflags.c.20090304.gz
Description: application/gzip
-- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/