From 8745eafadc9d43dbd9f9a0d2cc33e12f11ca1cd6 Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Mon, 23 Dec 2002 10:37:38 +0000 Subject: [PATCH] Add support for 'S' encoding to strings - display 8-bit characters. --- binutils/ChangeLog | 11 ++++++++ binutils/NEWS | 2 ++ binutils/doc/binutils.texi | 10 +++---- binutils/strings.c | 53 +++++++++++++++++++------------------- 4 files changed, 45 insertions(+), 31 deletions(-) diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 3f165a2706..f411fcdba6 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,14 @@ +2002-12-23 Nick Clifton + + * strings.c (isgraphic): Replace definition with STRING_ISGRAPHIC + macro. Handle 'S' encoding, accepting 8-bit characters. + (main): Parse 'S' encoding. + (get_char): Accept 'S' encoding. + (print_strings): Use STRING_ISGRAPHIC. + (usage): Document support of 'S' encoding. + * doc/binutils.texi: Document support of 'S' encoding/ + * NEWS: Mention new feature. + 2002-12-20 Alan Modra * README : Don't use libibery's needed_list or diff --git a/binutils/NEWS b/binutils/NEWS index 1e74e93daa..e9e4f40f9d 100644 --- a/binutils/NEWS +++ b/binutils/NEWS @@ -1,5 +1,7 @@ -*- text -*- +* Added 'S' encoding to strings to allow the display of 8-bit characters. + * Added --prefix-symbols=, --prefix-sections= and --prefix-alloc-sections= to objcopy. diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi index 57103f0e84..26ed7f9a3e 100644 --- a/binutils/doc/binutils.texi +++ b/binutils/doc/binutils.texi @@ -1956,11 +1956,11 @@ octal, @samp{x} for hexadecimal, or @samp{d} for decimal. @item -e @var{encoding} @itemx --encoding=@var{encoding} Select the character encoding of the strings that are to be found. -Possible values for @var{encoding} are: @samp{s} = single-byte -characters (ASCII, ISO 8859, etc., default), @samp{b} = 16-bit -Bigendian, @samp{l} = 16-bit Littleendian, @samp{B} = 32-bit Bigendian, -@samp{L} = 32-bit Littleendian. Useful for finding wide character -strings. +Possible values for @var{encoding} are: @samp{s} = single-7-bit-byte +characters (ASCII, ISO 8859, etc., default), @samp{S} = +single-8-bit-byte characters, @samp{b} = 16-bit bigendian, @samp{l} = +16-bit littleendian, @samp{B} = 32-bit bigendian, @samp{L} = 32-bit +littleendian. Useful for finding wide character strings. @item --target=@var{bfdname} @cindex object code format diff --git a/binutils/strings.c b/binutils/strings.c index f1222e0c3f..b5e88d0586 100644 --- a/binutils/strings.c +++ b/binutils/strings.c @@ -39,10 +39,11 @@ -o Like -to. (Some other implementations have -o like -to, others like -td. We chose one arbitrarily.) - --encoding={s,b,l,B,L} - -e {s,b,l,B,L} - Select character encoding: single-byte, bigendian 16-bit, - littleendian 16-bit, bigendian 32-bit, littleendian 32-bit + --encoding={s,S,b,l,B,L} + -e {s,S,b,l,B,L} + Select character encoding: 7-bit-character, 8-bit-character, + bigendian 16-bit, littleendian 16-bit, bigendian 32-bit, + littleendian 32-bit. --target=BFDNAME Specify a non-default object file format. @@ -80,11 +81,14 @@ #endif #if O_BINARY #include -#define SET_BINARY(f) do { if (!isatty(f)) setmode(f,O_BINARY); } while (0) +#define SET_BINARY(f) do { if (!isatty (f)) setmode (f,O_BINARY); } while (0) #endif #endif -#define isgraphic(c) (ISPRINT (c) || (c) == '\t') +#define STRING_ISGRAPHIC(c) \ + ( (c) >= 0 \ + && (c) <= 255 \ + && ((c) == '\t' || ISPRINT (c) || (encoding == 'S' && (c) > 127))) #ifndef errno extern int errno; @@ -95,10 +99,10 @@ extern int errno; #ifdef HAVE_FOPEN64 typedef off64_t file_off; -#define file_open(s,m) fopen64(s,m) +#define file_open(s,m) fopen64(s, m) #else typedef off_t file_off; -#define file_open(s,m) fopen(s,m) +#define file_open(s,m) fopen(s, m) #endif /* Radix for printing addresses (must be 8, 10 or 16). */ @@ -148,12 +152,11 @@ static bfd_boolean strings_file static int integer_arg PARAMS ((char *s)); static void print_strings - PARAMS ((const char *filename, FILE *stream, file_off address, - int stop_point, int magiccount, char *magic)); + PARAMS ((const char *, FILE *, file_off, int, int, char *)); static void usage - PARAMS ((FILE *stream, int status)); + PARAMS ((FILE *, int)); static long get_char - PARAMS ((FILE *stream, file_off *address, int *magiccount, char **magic)); + PARAMS ((FILE *, file_off *, int *, char **)); int main PARAMS ((int, char **)); @@ -202,9 +205,7 @@ main (argc, argv) case 'n': string_min = integer_arg (optarg); if (string_min < 1) - { - fatal (_("invalid number %s"), optarg); - } + fatal (_("invalid number %s"), optarg); break; case 'o': @@ -267,6 +268,7 @@ main (argc, argv) switch (encoding) { + case 'S': case 's': encoding_bytes = 1; break; @@ -330,6 +332,7 @@ strings_a_section (abfd, sect, filearg) { bfd_size_type sz = bfd_get_section_size_before_reloc (sect); PTR mem = xmalloc (sz); + if (bfd_get_section_contents (abfd, sect, mem, (file_ptr) 0, sz)) { got_a_section = TRUE; @@ -352,10 +355,8 @@ strings_object_file (file) bfd *abfd = bfd_openr (file, target); if (abfd == NULL) - { - /* Treat the file as a non-object file. */ - return FALSE; - } + /* Treat the file as a non-object file. */ + return FALSE; /* This call is mainly for its side effect of reading in the sections. We follow the traditional behavior of `strings' in that we don't @@ -460,6 +461,7 @@ get_char (stream, address, magiccount, magic) switch (encoding) { + case 'S': case 's': r = buf[0]; break; @@ -524,7 +526,7 @@ print_strings (filename, stream, address, stop_point, magiccount, magic) c = get_char (stream, &address, &magiccount, &magic); if (c == EOF) return; - if (c > 255 || c < 0 || !isgraphic (c)) + if (! STRING_ISGRAPHIC (c)) /* Found a non-graphic. Try again starting with next char. */ goto tryline; buf[i] = c; @@ -592,7 +594,7 @@ print_strings (filename, stream, address, stop_point, magiccount, magic) c = get_char (stream, &address, &magiccount, &magic); if (c == EOF) break; - if (c > 255 || c < 0 || !isgraphic (c)) + if (! STRING_ISGRAPHIC (c)) break; putchar (c); } @@ -642,9 +644,8 @@ integer_arg (s) p--; if (*p) - { - fatal (_("invalid integer argument %s"), s); - } + fatal (_("invalid integer argument %s"), s); + return value; } @@ -663,8 +664,8 @@ usage (stream, status) -t --radix={o,x,d} Print the location of the string in base 8, 10 or 16\n\ -o An alias for --radix=o\n\ -T --target= Specify the binary file format\n\ - -e --encoding={s,b,l,B,L} Select character size and endianness:\n\ - s = 8-bit, {b,l} = 16-bit, {B,L} = 32-bit\n\ + -e --encoding={s,S,b,l,B,L} Select character size and endianness:\n\ + s = 7-bit, S = 8-bit, {b,l} = 16-bit, {B,L} = 32-bit\n\ -h --help Display this information\n\ -v --version Print the program's version number\n")); list_supported_targets (program_name, stream);