|
|
9cc3a9 |
diff -rup binutils.orig/binutils/NEWS binutils-2.30/binutils/NEWS
|
|
|
9cc3a9 |
--- binutils.orig/binutils/NEWS 2021-10-20 12:39:41.715008273 +0100
|
|
|
9cc3a9 |
+++ binutils-2.30/binutils/NEWS 2021-10-20 12:41:30.895327968 +0100
|
|
|
9cc3a9 |
@@ -1,5 +1,14 @@
|
|
|
9cc3a9 |
-*- text -*-
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
+* Tools which display names or strings (readelf, strings, nm, objdump)
|
|
|
9cc3a9 |
+ have a new command line option which controls how unicode characters are
|
|
|
9cc3a9 |
+ handled. By default they are treated as normal for the tool. Using
|
|
|
9cc3a9 |
+ --unicode=locale will display them according to the current locale.
|
|
|
9cc3a9 |
+ Using --unicode=hex will display them as hex byte values, whilst
|
|
|
9cc3a9 |
+ --unicode=escape will display them as escape sequences. In addition
|
|
|
9cc3a9 |
+ using --unicode=highlight will display them as unicode escape sequences
|
|
|
9cc3a9 |
+ highlighted in red (if supported by the output device).
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
* Add support for disassembling netronome Flow Processor (NFP) firmware files.
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
Changes in 2.30:
|
|
|
9cc3a9 |
diff -rup binutils.orig/binutils/doc/binutils.texi binutils-2.30/binutils/doc/binutils.texi
|
|
|
9cc3a9 |
--- binutils.orig/binutils/doc/binutils.texi 2021-10-20 12:39:41.701008360 +0100
|
|
|
9cc3a9 |
+++ binutils-2.30/binutils/doc/binutils.texi 2021-10-20 13:00:11.801327501 +0100
|
|
|
9cc3a9 |
@@ -762,6 +762,7 @@ nm [@option{-A}|@option{-o}|@option{--pr
|
|
|
9cc3a9 |
[@option{-D}|@option{--dynamic}] [@option{-f}@var{format}|@option{--format=}@var{format}]
|
|
|
9cc3a9 |
[@option{-g}|@option{--extern-only}] [@option{-h}|@option{--help}]
|
|
|
9cc3a9 |
[@option{-l}|@option{--line-numbers}] [@option{--inlines}]
|
|
|
9cc3a9 |
+ [@option{-U} @var{method}] [@option{--unicode=}@var{method}]
|
|
|
9cc3a9 |
[@option{-n}|@option{-v}|@option{--numeric-sort}]
|
|
|
9cc3a9 |
[@option{-P}|@option{--portability}] [@option{-p}|@option{--no-sort}]
|
|
|
9cc3a9 |
[@option{-r}|@option{--reverse-sort}] [@option{-S}|@option{--print-size}]
|
|
|
9cc3a9 |
@@ -1026,6 +1027,21 @@ Use @var{radix} as the radix for printin
|
|
|
9cc3a9 |
@cindex undefined symbols
|
|
|
9cc3a9 |
Display only undefined symbols (those external to each object file).
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
+@item -U @var{[d|i|l|e|x|h]}
|
|
|
9cc3a9 |
+@itemx --unicode=@var{[default|invalid|locale|escape|hex|highlight]}
|
|
|
9cc3a9 |
+Controls the display of UTF-8 encoded mulibyte characters in strings.
|
|
|
9cc3a9 |
+The default (@option{--unicode=default}) is to give them no special
|
|
|
9cc3a9 |
+treatment. The @option{--unicode=locale} option displays the sequence
|
|
|
9cc3a9 |
+in the current locale, which may or may not support them. The options
|
|
|
9cc3a9 |
+@option{--unicode=hex} and @option{--unicode=invalid} display them as
|
|
|
9cc3a9 |
+hex byte sequences enclosed by either angle brackets or curly braces.
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+The @option{--unicode=escape} option displays them as escape sequences
|
|
|
9cc3a9 |
+(@var{\uxxxx}) and the @option{--unicode=highlight} option displays
|
|
|
9cc3a9 |
+them as escape sequences highlighted in red (if supported by the
|
|
|
9cc3a9 |
+output device). The colouring is intended to draw attention to the
|
|
|
9cc3a9 |
+presence of unicode sequences where they might not be expected.
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
@item -V
|
|
|
9cc3a9 |
@itemx --version
|
|
|
9cc3a9 |
Show the version number of @command{nm} and exit.
|
|
|
9cc3a9 |
@@ -2093,6 +2109,7 @@ objdump [@option{-a}|@option{--archive-h
|
|
|
9cc3a9 |
[@option{--prefix=}@var{prefix}]
|
|
|
9cc3a9 |
[@option{--prefix-strip=}@var{level}]
|
|
|
9cc3a9 |
[@option{--insn-width=}@var{width}]
|
|
|
9cc3a9 |
+ [@option{-U} @var{method}] [@option{--unicode=}@var{method}]
|
|
|
9cc3a9 |
[@option{-V}|@option{--version}]
|
|
|
9cc3a9 |
[@option{-H}|@option{--help}]
|
|
|
9cc3a9 |
@var{objfile}@dots{}
|
|
|
9cc3a9 |
@@ -2697,6 +2714,21 @@ When displaying symbols include those wh
|
|
|
9cc3a9 |
special in some way and which would not normally be of interest to the
|
|
|
9cc3a9 |
user.
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
+@item -U @var{[d|i|l|e|x|h]}
|
|
|
9cc3a9 |
+@itemx --unicode=@var{[default|invalid|locale|escape|hex|highlight]}
|
|
|
9cc3a9 |
+Controls the display of UTF-8 encoded mulibyte characters in strings.
|
|
|
9cc3a9 |
+The default (@option{--unicode=default}) is to give them no special
|
|
|
9cc3a9 |
+treatment. The @option{--unicode=locale} option displays the sequence
|
|
|
9cc3a9 |
+in the current locale, which may or may not support them. The options
|
|
|
9cc3a9 |
+@option{--unicode=hex} and @option{--unicode=invalid} display them as
|
|
|
9cc3a9 |
+hex byte sequences enclosed by either angle brackets or curly braces.
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+The @option{--unicode=escape} option displays them as escape sequences
|
|
|
9cc3a9 |
+(@var{\uxxxx}) and the @option{--unicode=highlight} option displays
|
|
|
9cc3a9 |
+them as escape sequences highlighted in red (if supported by the
|
|
|
9cc3a9 |
+output device). The colouring is intended to draw attention to the
|
|
|
9cc3a9 |
+presence of unicode sequences where they might not be expected.
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
@item -V
|
|
|
9cc3a9 |
@itemx --version
|
|
|
9cc3a9 |
Print the version number of @command{objdump} and exit.
|
|
|
9cc3a9 |
@@ -2952,6 +2984,7 @@ strings [@option{-afovV}] [@option{-}@va
|
|
|
9cc3a9 |
[@option{-n} @var{min-len}] [@option{--bytes=}@var{min-len}]
|
|
|
9cc3a9 |
[@option{-t} @var{radix}] [@option{--radix=}@var{radix}]
|
|
|
9cc3a9 |
[@option{-e} @var{encoding}] [@option{--encoding=}@var{encoding}]
|
|
|
9cc3a9 |
+ [@option{-U} @var{method}] [@option{--unicode=}@var{method}]
|
|
|
9cc3a9 |
[@option{-}] [@option{--all}] [@option{--print-file-name}]
|
|
|
9cc3a9 |
[@option{-T} @var{bfdname}] [@option{--target=}@var{bfdname}]
|
|
|
9cc3a9 |
[@option{-w}] [@option{--include-all-whitespace}]
|
|
|
9cc3a9 |
@@ -3043,6 +3076,28 @@ single-8-bit-byte characters, @samp{b} =
|
|
|
9cc3a9 |
littleendian. Useful for finding wide character strings. (@samp{l}
|
|
|
9cc3a9 |
and @samp{b} apply to, for example, Unicode UTF-16/UCS-2 encodings).
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
+@item -U @var{[d|i|l|e|x|h]}
|
|
|
9cc3a9 |
+@itemx --unicode=@var{[default|invalid|locale|escape|hex|highlight]}
|
|
|
9cc3a9 |
+Controls the display of UTF-8 encoded mulibyte characters in strings.
|
|
|
9cc3a9 |
+The default (@option{--unicode=default}) is to give them no special
|
|
|
9cc3a9 |
+treatment, and instead rely upon the setting of the
|
|
|
9cc3a9 |
+@option{--encoding} option. The other values for this option
|
|
|
9cc3a9 |
+automatically enable @option{--encoding=S}.
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+The @option{--unicode=invalid} option treats them as non-graphic
|
|
|
9cc3a9 |
+characters and hence not part of a valid string. All the remaining
|
|
|
9cc3a9 |
+options treat them as valid string characters.
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+The @option{--unicode=locale} option displays them in the current
|
|
|
9cc3a9 |
+locale, which may or may not support UTF-8 encoding. The
|
|
|
9cc3a9 |
+@option{--unicode=hex} option displays them as hex byte sequences
|
|
|
9cc3a9 |
+enclosed between @var{<>} characters. The @option{--unicode=escape}
|
|
|
9cc3a9 |
+option displays them as escape sequences (@var{\uxxxx}) and the
|
|
|
9cc3a9 |
+@option{--unicode=highlight} option displays them as escape sequences
|
|
|
9cc3a9 |
+highlighted in red (if supported by the output device). The colouring
|
|
|
9cc3a9 |
+is intended to draw attention to the presence of unicode sequences
|
|
|
9cc3a9 |
+where they might not be expected.
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
@item -T @var{bfdname}
|
|
|
9cc3a9 |
@itemx --target=@var{bfdname}
|
|
|
9cc3a9 |
@cindex object code format
|
|
|
9cc3a9 |
@@ -4603,6 +4658,7 @@ readelf [@option{-a}|@option{--all}]
|
|
|
9cc3a9 |
[@option{-v}|@option{--version}]
|
|
|
9cc3a9 |
[@option{-W}|@option{--wide}]
|
|
|
9cc3a9 |
[@option{-H}|@option{--help}]
|
|
|
9cc3a9 |
+ [@option{-U} @var{method}|@option{--unicode=}@var{method}]
|
|
|
9cc3a9 |
@var{elffile}@dots{}
|
|
|
9cc3a9 |
@c man end
|
|
|
9cc3a9 |
@end smallexample
|
|
|
9cc3a9 |
@@ -4692,6 +4748,28 @@ Displays the entries in dynamic symbol t
|
|
|
9cc3a9 |
has one. The output format is the same as the format used by the
|
|
|
9cc3a9 |
@option{--syms} option.
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
+@item -U @var{[d|i|l|e|x|h]}
|
|
|
9cc3a9 |
+@itemx --unicode=[default|invalid|locale|escape|hex|highlight]
|
|
|
9cc3a9 |
+Controls the display of non-ASCII characters in identifier names.
|
|
|
9cc3a9 |
+The default (@option{--unicode=locale} or @option{--unicode=default}) is
|
|
|
9cc3a9 |
+to treat them as multibyte characters and display them in the current
|
|
|
9cc3a9 |
+locale. All other versions of this option treat the bytes as UTF-8
|
|
|
9cc3a9 |
+encoded values and attempt to interpret them. If they cannot be
|
|
|
9cc3a9 |
+interpreted or if the @option{--unicode=invalid} option is used then
|
|
|
9cc3a9 |
+they are displayed as a sequence of hex bytes, encloses in curly
|
|
|
9cc3a9 |
+parethesis characters.
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+Using the @option{--unicode=escape} option will display the characters
|
|
|
9cc3a9 |
+as as unicode escape sequences (@var{\uxxxx}). Using the
|
|
|
9cc3a9 |
+@option{--unicode=hex} will display the characters as hex byte
|
|
|
9cc3a9 |
+sequences enclosed between angle brackets.
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+Using the @option{--unicode=highlight} will display the characters as
|
|
|
9cc3a9 |
+unicode escape sequences but it will also highlighted them in red,
|
|
|
9cc3a9 |
+assuming that colouring is supported by the output device. The
|
|
|
9cc3a9 |
+colouring is intended to draw attention to the presence of unicode
|
|
|
9cc3a9 |
+sequences when they might not be expected.
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
@item -e
|
|
|
9cc3a9 |
@itemx --headers
|
|
|
9cc3a9 |
Display all the headers in the file. Equivalent to @option{-h -l -S}.
|
|
|
9cc3a9 |
diff -rup binutils.orig/binutils/nm.c binutils-2.30/binutils/nm.c
|
|
|
9cc3a9 |
--- binutils.orig/binutils/nm.c 2021-10-20 12:39:41.681008485 +0100
|
|
|
9cc3a9 |
+++ binutils-2.30/binutils/nm.c 2021-10-20 12:52:26.731237376 +0100
|
|
|
9cc3a9 |
@@ -38,6 +38,11 @@
|
|
|
9cc3a9 |
#include "bucomm.h"
|
|
|
9cc3a9 |
#include "plugin-api.h"
|
|
|
9cc3a9 |
#include "plugin.h"
|
|
|
9cc3a9 |
+#include "safe-ctype.h"
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+#ifndef streq
|
|
|
9cc3a9 |
+#define streq(a,b) (strcmp ((a),(b)) == 0)
|
|
|
9cc3a9 |
+#endif
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
/* When sorting by size, we use this structure to hold the size and a
|
|
|
9cc3a9 |
pointer to the minisymbol. */
|
|
|
9cc3a9 |
@@ -194,6 +199,18 @@ static const char *plugin_target = NULL;
|
|
|
9cc3a9 |
static bfd *lineno_cache_bfd;
|
|
|
9cc3a9 |
static bfd *lineno_cache_rel_bfd;
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
+typedef enum unicode_display_type
|
|
|
9cc3a9 |
+{
|
|
|
9cc3a9 |
+ unicode_default = 0,
|
|
|
9cc3a9 |
+ unicode_locale,
|
|
|
9cc3a9 |
+ unicode_escape,
|
|
|
9cc3a9 |
+ unicode_hex,
|
|
|
9cc3a9 |
+ unicode_highlight,
|
|
|
9cc3a9 |
+ unicode_invalid
|
|
|
9cc3a9 |
+} unicode_display_type;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+static unicode_display_type unicode_display = unicode_default;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
#define OPTION_TARGET 200
|
|
|
9cc3a9 |
#define OPTION_PLUGIN (OPTION_TARGET + 1)
|
|
|
9cc3a9 |
#define OPTION_SIZE_SORT (OPTION_PLUGIN + 1)
|
|
|
9cc3a9 |
@@ -224,6 +241,7 @@ static struct option long_options[] =
|
|
|
9cc3a9 |
{"target", required_argument, 0, OPTION_TARGET},
|
|
|
9cc3a9 |
{"defined-only", no_argument, &defined_only, 1},
|
|
|
9cc3a9 |
{"undefined-only", no_argument, &undefined_only, 1},
|
|
|
9cc3a9 |
+ {"unicode", required_argument, NULL, 'U'},
|
|
|
9cc3a9 |
{"version", no_argument, &show_version, 1},
|
|
|
9cc3a9 |
{"with-symbol-versions", no_argument, &with_symbol_versions, 1},
|
|
|
9cc3a9 |
{0, no_argument, 0, 0}
|
|
|
9cc3a9 |
@@ -271,6 +289,8 @@ usage (FILE *stream, int status)
|
|
|
9cc3a9 |
-t, --radix=RADIX Use RADIX for printing symbol values\n\
|
|
|
9cc3a9 |
--target=BFDNAME Specify the target object format as BFDNAME\n\
|
|
|
9cc3a9 |
-u, --undefined-only Display only undefined symbols\n\
|
|
|
9cc3a9 |
+ -U {d|s|i|x|e|h} Specify how to treat UTF-8 encoded unicode characters\n\
|
|
|
9cc3a9 |
+ --unicode={default|show|invalid|hex|escape|highlight}\n\
|
|
|
9cc3a9 |
--with-symbol-versions Display version strings after symbol names\n\
|
|
|
9cc3a9 |
-X 32_64 (ignored)\n\
|
|
|
9cc3a9 |
@FILE Read options from FILE\n\
|
|
|
9cc3a9 |
@@ -399,6 +419,189 @@ get_coff_symbol_type (const struct inter
|
|
|
9cc3a9 |
return bufp;
|
|
|
9cc3a9 |
}
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
+/* Convert a potential UTF-8 encoded sequence in IN into characters in OUT.
|
|
|
9cc3a9 |
+ The conversion format is controlled by the unicode_display variable.
|
|
|
9cc3a9 |
+ Returns the number of characters added to OUT.
|
|
|
9cc3a9 |
+ Returns the number of bytes consumed from IN in CONSUMED.
|
|
|
9cc3a9 |
+ Always consumes at least one byte and displays at least one character. */
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+static unsigned int
|
|
|
9cc3a9 |
+display_utf8 (const unsigned char * in, char * out, unsigned int * consumed)
|
|
|
9cc3a9 |
+{
|
|
|
9cc3a9 |
+ char * orig_out = out;
|
|
|
9cc3a9 |
+ unsigned int nchars = 0;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (unicode_display == unicode_default)
|
|
|
9cc3a9 |
+ goto invalid;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (in[0] < 0xc0)
|
|
|
9cc3a9 |
+ goto invalid;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((in[1] & 0xc0) != 0x80)
|
|
|
9cc3a9 |
+ goto invalid;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((in[0] & 0x20) == 0)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ nchars = 2;
|
|
|
9cc3a9 |
+ goto valid;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((in[2] & 0xc0) != 0x80)
|
|
|
9cc3a9 |
+ goto invalid;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((in[0] & 0x10) == 0)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ nchars = 3;
|
|
|
9cc3a9 |
+ goto valid;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((in[3] & 0xc0) != 0x80)
|
|
|
9cc3a9 |
+ goto invalid;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ nchars = 4;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ valid:
|
|
|
9cc3a9 |
+ switch (unicode_display)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ case unicode_locale:
|
|
|
9cc3a9 |
+ /* Copy the bytes into the output buffer as is. */
|
|
|
9cc3a9 |
+ memcpy (out, in, nchars);
|
|
|
9cc3a9 |
+ out += nchars;
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ case unicode_invalid:
|
|
|
9cc3a9 |
+ case unicode_hex:
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ unsigned int j;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ out += sprintf (out, "%c", unicode_display == unicode_hex ? '<' : '{');
|
|
|
9cc3a9 |
+ for (j = 0; j < nchars; j++)
|
|
|
9cc3a9 |
+ out += sprintf (out, "%02x", in [j]);
|
|
|
9cc3a9 |
+ out += sprintf (out, "%c", unicode_display == unicode_hex ? '>' : '}');
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ case unicode_highlight:
|
|
|
9cc3a9 |
+ if (isatty (1))
|
|
|
9cc3a9 |
+ out += sprintf (out, "\x1B[31;47m"); /* Red. */
|
|
|
9cc3a9 |
+ /* Fall through. */
|
|
|
9cc3a9 |
+ case unicode_escape:
|
|
|
9cc3a9 |
+ switch (nchars)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ case 2:
|
|
|
9cc3a9 |
+ out += sprintf (out, "\\u%02x%02x",
|
|
|
9cc3a9 |
+ ((in[0] & 0x1c) >> 2),
|
|
|
9cc3a9 |
+ ((in[0] & 0x03) << 6) | (in[1] & 0x3f));
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ case 3:
|
|
|
9cc3a9 |
+ out += sprintf (out, "\\u%02x%02x",
|
|
|
9cc3a9 |
+ ((in[0] & 0x0f) << 4) | ((in[1] & 0x3c) >> 2),
|
|
|
9cc3a9 |
+ ((in[1] & 0x03) << 6) | ((in[2] & 0x3f)));
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ case 4:
|
|
|
9cc3a9 |
+ out += sprintf (out, "\\u%02x%02x%02x",
|
|
|
9cc3a9 |
+ ((in[0] & 0x07) << 6) | ((in[1] & 0x3c) >> 2),
|
|
|
9cc3a9 |
+ ((in[1] & 0x03) << 6) | ((in[2] & 0x3c) >> 2),
|
|
|
9cc3a9 |
+ ((in[2] & 0x03) << 6) | ((in[3] & 0x3f)));
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ default:
|
|
|
9cc3a9 |
+ /* URG. */
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (unicode_display == unicode_highlight && isatty (1))
|
|
|
9cc3a9 |
+ out += sprintf (out, "\033[0m"); /* Default colour. */
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ default:
|
|
|
9cc3a9 |
+ /* URG */
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ * consumed = nchars;
|
|
|
9cc3a9 |
+ return out - orig_out;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ invalid:
|
|
|
9cc3a9 |
+ /* Not a valid UTF-8 sequence. */
|
|
|
9cc3a9 |
+ *out = *in;
|
|
|
9cc3a9 |
+ * consumed = 1;
|
|
|
9cc3a9 |
+ return 1;
|
|
|
9cc3a9 |
+}
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+/* Convert any UTF-8 encoded characters in NAME into the form specified by
|
|
|
9cc3a9 |
+ unicode_display. Also converts control characters. Returns a static
|
|
|
9cc3a9 |
+ buffer if conversion was necessary.
|
|
|
9cc3a9 |
+ Code stolen from objdump.c:sanitize_string(). */
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+static const char *
|
|
|
9cc3a9 |
+convert_utf8 (const char * in)
|
|
|
9cc3a9 |
+{
|
|
|
9cc3a9 |
+ static char * buffer = NULL;
|
|
|
9cc3a9 |
+ static size_t buffer_len = 0;
|
|
|
9cc3a9 |
+ const char * original = in;
|
|
|
9cc3a9 |
+ char * out;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ /* Paranoia. */
|
|
|
9cc3a9 |
+ if (in == NULL)
|
|
|
9cc3a9 |
+ return "";
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ /* See if any conversion is necessary.
|
|
|
9cc3a9 |
+ In the majority of cases it will not be needed. */
|
|
|
9cc3a9 |
+ do
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ unsigned char c = *in++;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (c == 0)
|
|
|
9cc3a9 |
+ return original;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (ISCNTRL (c))
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (unicode_display != unicode_default && c >= 0xc0)
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ while (1);
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ /* Copy the input, translating as needed. */
|
|
|
9cc3a9 |
+ in = original;
|
|
|
9cc3a9 |
+ if (buffer_len < (strlen (in) * 9))
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ free ((void *) buffer);
|
|
|
9cc3a9 |
+ buffer_len = strlen (in) * 9;
|
|
|
9cc3a9 |
+ buffer = xmalloc (buffer_len + 1);
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ out = buffer;
|
|
|
9cc3a9 |
+ do
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ unsigned char c = *in++;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (c == 0)
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (ISCNTRL (c))
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ *out++ = '^';
|
|
|
9cc3a9 |
+ *out++ = c + 0x40;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else if (unicode_display != unicode_default && c >= 0xc0)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ unsigned int num_consumed;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ out += display_utf8 ((const unsigned char *)(in - 1), out, & num_consumed);
|
|
|
9cc3a9 |
+ in += num_consumed - 1;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ *out++ = c;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ while (1);
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ *out = 0;
|
|
|
9cc3a9 |
+ return buffer;
|
|
|
9cc3a9 |
+}
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
/* Print symbol name NAME, read from ABFD, with printf format FORM,
|
|
|
9cc3a9 |
demangling it if requested. */
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
@@ -417,6 +618,9 @@ print_symname (const char *form, const c
|
|
|
9cc3a9 |
}
|
|
|
9cc3a9 |
}
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
+ if (unicode_display != unicode_default)
|
|
|
9cc3a9 |
+ name = convert_utf8 (name);
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
printf (form, name);
|
|
|
9cc3a9 |
}
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
@@ -1657,7 +1861,7 @@ main (int argc, char **argv)
|
|
|
9cc3a9 |
bfd_init ();
|
|
|
9cc3a9 |
set_default_bfd_target ();
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
- while ((c = getopt_long (argc, argv, "aABCDef:gHhlnopPrSst:uvVvX:",
|
|
|
9cc3a9 |
+ while ((c = getopt_long (argc, argv, "aABCDef:gHhlnopPrSst:uU:vVvX:",
|
|
|
9cc3a9 |
long_options, (int *) 0)) != EOF)
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
switch (c)
|
|
|
9cc3a9 |
@@ -1738,6 +1942,24 @@ main (int argc, char **argv)
|
|
|
9cc3a9 |
case 'u':
|
|
|
9cc3a9 |
undefined_only = 1;
|
|
|
9cc3a9 |
break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ case 'U':
|
|
|
9cc3a9 |
+ if (streq (optarg, "default") || streq (optarg, "d"))
|
|
|
9cc3a9 |
+ unicode_display = unicode_default;
|
|
|
9cc3a9 |
+ else if (streq (optarg, "locale") || streq (optarg, "l"))
|
|
|
9cc3a9 |
+ unicode_display = unicode_locale;
|
|
|
9cc3a9 |
+ else if (streq (optarg, "escape") || streq (optarg, "e"))
|
|
|
9cc3a9 |
+ unicode_display = unicode_escape;
|
|
|
9cc3a9 |
+ else if (streq (optarg, "invalid") || streq (optarg, "i"))
|
|
|
9cc3a9 |
+ unicode_display = unicode_invalid;
|
|
|
9cc3a9 |
+ else if (streq (optarg, "hex") || streq (optarg, "x"))
|
|
|
9cc3a9 |
+ unicode_display = unicode_hex;
|
|
|
9cc3a9 |
+ else if (streq (optarg, "highlight") || streq (optarg, "h"))
|
|
|
9cc3a9 |
+ unicode_display = unicode_highlight;
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ fatal (_("invalid argument to -U/--unicode: %s"), optarg);
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
case 'V':
|
|
|
9cc3a9 |
show_version = 1;
|
|
|
9cc3a9 |
break;
|
|
|
9cc3a9 |
diff -rup binutils.orig/binutils/objdump.c binutils-2.30/binutils/objdump.c
|
|
|
9cc3a9 |
--- binutils.orig/binutils/objdump.c 2021-10-20 12:39:41.677008510 +0100
|
|
|
9cc3a9 |
+++ binutils-2.30/binutils/objdump.c 2021-10-20 13:24:11.009293189 +0100
|
|
|
9cc3a9 |
@@ -192,6 +192,18 @@ static const struct objdump_private_desc
|
|
|
9cc3a9 |
OBJDUMP_PRIVATE_VECTORS
|
|
|
9cc3a9 |
NULL
|
|
|
9cc3a9 |
};
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+typedef enum unicode_display_type
|
|
|
9cc3a9 |
+{
|
|
|
9cc3a9 |
+ unicode_default = 0,
|
|
|
9cc3a9 |
+ unicode_locale,
|
|
|
9cc3a9 |
+ unicode_escape,
|
|
|
9cc3a9 |
+ unicode_hex,
|
|
|
9cc3a9 |
+ unicode_highlight,
|
|
|
9cc3a9 |
+ unicode_invalid
|
|
|
9cc3a9 |
+} unicode_display_type;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+static unicode_display_type unicode_display = unicode_default;
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
static void usage (FILE *, int) ATTRIBUTE_NORETURN;
|
|
|
9cc3a9 |
static void
|
|
|
9cc3a9 |
@@ -225,6 +237,9 @@ usage (FILE *stream, int status)
|
|
|
9cc3a9 |
-r, --reloc Display the relocation entries in the file\n\
|
|
|
9cc3a9 |
-R, --dynamic-reloc Display the dynamic relocation entries in the file\n\
|
|
|
9cc3a9 |
@<file> Read options from <file>\n\
|
|
|
9cc3a9 |
+ -U[d|l|i|x|e|h] Controls the display of UTF-8 unicode characters\n\
|
|
|
9cc3a9 |
+ --unicode=[default|locale|invalid|hex|escape|highlight]\n"));
|
|
|
9cc3a9 |
+ fprintf (stream, _("\
|
|
|
9cc3a9 |
-v, --version Display this program's version number\n\
|
|
|
9cc3a9 |
-i, --info List object formats and architectures supported\n\
|
|
|
9cc3a9 |
-H, --help Display this information\n\
|
|
|
9cc3a9 |
@@ -343,6 +358,7 @@ static struct option long_options[]=
|
|
|
9cc3a9 |
{"stop-address", required_argument, NULL, OPTION_STOP_ADDRESS},
|
|
|
9cc3a9 |
{"syms", no_argument, NULL, 't'},
|
|
|
9cc3a9 |
{"target", required_argument, NULL, 'b'},
|
|
|
9cc3a9 |
+ {"unicode", required_argument, NULL, 'U'},
|
|
|
9cc3a9 |
{"version", no_argument, NULL, 'V'},
|
|
|
9cc3a9 |
{"wide", no_argument, NULL, 'w'},
|
|
|
9cc3a9 |
{"prefix", required_argument, NULL, OPTION_PREFIX},
|
|
|
9cc3a9 |
@@ -362,6 +378,191 @@ nonfatal (const char *msg)
|
|
|
9cc3a9 |
exit_status = 1;
|
|
|
9cc3a9 |
}
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
+/* Convert a potential UTF-8 encoded sequence in IN into characters in OUT.
|
|
|
9cc3a9 |
+ The conversion format is controlled by the unicode_display variable.
|
|
|
9cc3a9 |
+ Returns the number of characters added to OUT.
|
|
|
9cc3a9 |
+ Returns the number of bytes consumed from IN in CONSUMED.
|
|
|
9cc3a9 |
+ Always consumes at least one byte and displays at least one character. */
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+static unsigned int
|
|
|
9cc3a9 |
+display_utf8 (const unsigned char * in, char * out, unsigned int * consumed)
|
|
|
9cc3a9 |
+{
|
|
|
9cc3a9 |
+ char * orig_out = out;
|
|
|
9cc3a9 |
+ unsigned int nchars = 0;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (unicode_display == unicode_default)
|
|
|
9cc3a9 |
+ goto invalid;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (in[0] < 0xc0)
|
|
|
9cc3a9 |
+ goto invalid;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((in[1] & 0xc0) != 0x80)
|
|
|
9cc3a9 |
+ goto invalid;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((in[0] & 0x20) == 0)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ nchars = 2;
|
|
|
9cc3a9 |
+ goto valid;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((in[2] & 0xc0) != 0x80)
|
|
|
9cc3a9 |
+ goto invalid;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((in[0] & 0x10) == 0)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ nchars = 3;
|
|
|
9cc3a9 |
+ goto valid;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((in[3] & 0xc0) != 0x80)
|
|
|
9cc3a9 |
+ goto invalid;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ nchars = 4;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ valid:
|
|
|
9cc3a9 |
+ switch (unicode_display)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ case unicode_locale:
|
|
|
9cc3a9 |
+ /* Copy the bytes into the output buffer as is. */
|
|
|
9cc3a9 |
+ memcpy (out, in, nchars);
|
|
|
9cc3a9 |
+ out += nchars;
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ case unicode_invalid:
|
|
|
9cc3a9 |
+ case unicode_hex:
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ unsigned int j;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ out += sprintf (out, "%c", unicode_display == unicode_hex ? '<' : '{');
|
|
|
9cc3a9 |
+ for (j = 0; j < nchars; j++)
|
|
|
9cc3a9 |
+ out += sprintf (out, "%02x", in [j]);
|
|
|
9cc3a9 |
+ out += sprintf (out, "%c", unicode_display == unicode_hex ? '>' : '}');
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ case unicode_highlight:
|
|
|
9cc3a9 |
+ if (isatty (1))
|
|
|
9cc3a9 |
+ out += sprintf (out, "\x1B[31;47m"); /* Red. */
|
|
|
9cc3a9 |
+ /* Fall through. */
|
|
|
9cc3a9 |
+ case unicode_escape:
|
|
|
9cc3a9 |
+ switch (nchars)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ case 2:
|
|
|
9cc3a9 |
+ out += sprintf (out, "\\u%02x%02x",
|
|
|
9cc3a9 |
+ ((in[0] & 0x1c) >> 2),
|
|
|
9cc3a9 |
+ ((in[0] & 0x03) << 6) | (in[1] & 0x3f));
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ case 3:
|
|
|
9cc3a9 |
+ out += sprintf (out, "\\u%02x%02x",
|
|
|
9cc3a9 |
+ ((in[0] & 0x0f) << 4) | ((in[1] & 0x3c) >> 2),
|
|
|
9cc3a9 |
+ ((in[1] & 0x03) << 6) | ((in[2] & 0x3f)));
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ case 4:
|
|
|
9cc3a9 |
+ out += sprintf (out, "\\u%02x%02x%02x",
|
|
|
9cc3a9 |
+ ((in[0] & 0x07) << 6) | ((in[1] & 0x3c) >> 2),
|
|
|
9cc3a9 |
+ ((in[1] & 0x03) << 6) | ((in[2] & 0x3c) >> 2),
|
|
|
9cc3a9 |
+ ((in[2] & 0x03) << 6) | ((in[3] & 0x3f)));
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ default:
|
|
|
9cc3a9 |
+ /* URG. */
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (unicode_display == unicode_highlight && isatty (1))
|
|
|
9cc3a9 |
+ out += sprintf (out, "\033[0m"); /* Default colour. */
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ default:
|
|
|
9cc3a9 |
+ /* URG */
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ * consumed = nchars;
|
|
|
9cc3a9 |
+ return out - orig_out;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ invalid:
|
|
|
9cc3a9 |
+ /* Not a valid UTF-8 sequence. */
|
|
|
9cc3a9 |
+ *out = *in;
|
|
|
9cc3a9 |
+ * consumed = 1;
|
|
|
9cc3a9 |
+ return 1;
|
|
|
9cc3a9 |
+}
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+/* Returns a version of IN with any control characters
|
|
|
9cc3a9 |
+ replaced by escape sequences. Uses a static buffer
|
|
|
9cc3a9 |
+ if necessary.
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ If unicode display is enabled, then also handles the
|
|
|
9cc3a9 |
+ conversion of unicode characters. */
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+static const char *
|
|
|
9cc3a9 |
+sanitize_string (const char * in)
|
|
|
9cc3a9 |
+{
|
|
|
9cc3a9 |
+ static char * buffer = NULL;
|
|
|
9cc3a9 |
+ static size_t buffer_len = 0;
|
|
|
9cc3a9 |
+ const char * original = in;
|
|
|
9cc3a9 |
+ char * out;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ /* Paranoia. */
|
|
|
9cc3a9 |
+ if (in == NULL)
|
|
|
9cc3a9 |
+ return "";
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ /* See if any conversion is necessary. In the majority
|
|
|
9cc3a9 |
+ of cases it will not be needed. */
|
|
|
9cc3a9 |
+ do
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ unsigned char c = *in++;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (c == 0)
|
|
|
9cc3a9 |
+ return original;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (ISCNTRL (c))
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (unicode_display != unicode_default && c >= 0xc0)
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ while (1);
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ /* Copy the input, translating as needed. */
|
|
|
9cc3a9 |
+ in = original;
|
|
|
9cc3a9 |
+ if (buffer_len < (strlen (in) * 9))
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ free ((void *) buffer);
|
|
|
9cc3a9 |
+ buffer_len = strlen (in) * 9;
|
|
|
9cc3a9 |
+ buffer = xmalloc (buffer_len + 1);
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ out = buffer;
|
|
|
9cc3a9 |
+ do
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ unsigned char c = *in++;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (c == 0)
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (ISCNTRL (c))
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ *out++ = '^';
|
|
|
9cc3a9 |
+ *out++ = c + 0x40;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else if (unicode_display != unicode_default && c >= 0xc0)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ unsigned int num_consumed;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ out += display_utf8 ((const unsigned char *)(in - 1), out, & num_consumed);
|
|
|
9cc3a9 |
+ in += num_consumed - 1;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ *out++ = c;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ while (1);
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ *out = 0;
|
|
|
9cc3a9 |
+ return buffer;
|
|
|
9cc3a9 |
+}
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
/* Returns TRUE if the specified section should be dumped. */
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
static bfd_boolean
|
|
|
9cc3a9 |
@@ -458,8 +657,8 @@ dump_section_header (bfd *abfd, asection
|
|
|
9cc3a9 |
return;
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
printf ("%3d %-*s %08lx ", section->index, longest_section_name,
|
|
|
9cc3a9 |
- bfd_get_section_name (abfd, section),
|
|
|
9cc3a9 |
- (unsigned long) bfd_section_size (abfd, section) / opb);
|
|
|
9cc3a9 |
+ sanitize_string (bfd_section_name (abfd, section)),
|
|
|
9cc3a9 |
+ (unsigned long) bfd_section_size (abfd, section) / opb);
|
|
|
9cc3a9 |
bfd_printf_vma (abfd, bfd_get_section_vma (abfd, section));
|
|
|
9cc3a9 |
printf (" ");
|
|
|
9cc3a9 |
bfd_printf_vma (abfd, section->lma);
|
|
|
9cc3a9 |
@@ -892,6 +1091,8 @@ objdump_print_symname (bfd *abfd, struct
|
|
|
9cc3a9 |
if (bfd_is_und_section (bfd_get_section (sym)))
|
|
|
9cc3a9 |
hidden = TRUE;
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
+ name = sanitize_string (name);
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
if (inf != NULL)
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
(*inf->fprintf_func) (inf->stream, "%s", name);
|
|
|
9cc3a9 |
@@ -1141,7 +1342,7 @@ objdump_print_addr_with_sym (bfd *abfd,
|
|
|
9cc3a9 |
bfd_vma secaddr;
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
(*inf->fprintf_func) (inf->stream, " <%s",
|
|
|
9cc3a9 |
- bfd_get_section_name (abfd, sec));
|
|
|
9cc3a9 |
+ sanitize_string (bfd_section_name (abfd, sec)));
|
|
|
9cc3a9 |
secaddr = bfd_get_section_vma (abfd, sec);
|
|
|
9cc3a9 |
if (vma < secaddr)
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
@@ -1563,7 +1764,7 @@ show_line (bfd *abfd, asection *section,
|
|
|
9cc3a9 |
&& (prev_functionname == NULL
|
|
|
9cc3a9 |
|| strcmp (functionname, prev_functionname) != 0))
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
- printf ("%s():\n", functionname);
|
|
|
9cc3a9 |
+ printf ("%s():\n", sanitize_string (functionname));
|
|
|
9cc3a9 |
prev_line = -1;
|
|
|
9cc3a9 |
}
|
|
|
9cc3a9 |
if (linenumber > 0
|
|
|
9cc3a9 |
@@ -1572,10 +1773,10 @@ show_line (bfd *abfd, asection *section,
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
if (discriminator > 0)
|
|
|
9cc3a9 |
printf ("%s:%u (discriminator %u)\n",
|
|
|
9cc3a9 |
- filename == NULL ? "???" : filename,
|
|
|
9cc3a9 |
+ filename == NULL ? "???" : sanitize_string (filename),
|
|
|
9cc3a9 |
linenumber, discriminator);
|
|
|
9cc3a9 |
else
|
|
|
9cc3a9 |
- printf ("%s:%u\n", filename == NULL ? "???" : filename,
|
|
|
9cc3a9 |
+ printf ("%s:%u\n", filename == NULL ? "???" : sanitize_string (filename),
|
|
|
9cc3a9 |
linenumber);
|
|
|
9cc3a9 |
}
|
|
|
9cc3a9 |
if (unwind_inlines)
|
|
|
9cc3a9 |
@@ -1586,8 +1787,10 @@ show_line (bfd *abfd, asection *section,
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
while (bfd_find_inliner_info (abfd, &filename2, &functionname2,
|
|
|
9cc3a9 |
&line2))
|
|
|
9cc3a9 |
- printf ("inlined by %s:%u (%s)\n", filename2, line2,
|
|
|
9cc3a9 |
- functionname2);
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ printf ("inlined by %s:%u", sanitize_string (filename2), line2);
|
|
|
9cc3a9 |
+ printf (" (%s)\n", sanitize_string (functionname2));
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
}
|
|
|
9cc3a9 |
}
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
@@ -2081,7 +2284,7 @@ disassemble_bytes (struct disassemble_in
|
|
|
9cc3a9 |
sym_name = bfd_get_section_name (aux->abfd, sym_sec);
|
|
|
9cc3a9 |
if (sym_name == NULL || *sym_name == '\0')
|
|
|
9cc3a9 |
sym_name = "*unknown*";
|
|
|
9cc3a9 |
- printf ("%s", sym_name);
|
|
|
9cc3a9 |
+ printf ("%s", sanitize_string (sym_name));
|
|
|
9cc3a9 |
}
|
|
|
9cc3a9 |
}
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
@@ -2228,7 +2431,7 @@ disassemble_section (bfd *abfd, asection
|
|
|
9cc3a9 |
&& (*rel_pp)->address < rel_offset + addr_offset)
|
|
|
9cc3a9 |
++rel_pp;
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
- printf (_("\nDisassembly of section %s:\n"), section->name);
|
|
|
9cc3a9 |
+ printf (_("\nDisassembly of section %s:\n"), sanitize_string (section->name));
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
/* Find the nearest symbol forwards from our current position. */
|
|
|
9cc3a9 |
paux->require_sec = TRUE;
|
|
|
9cc3a9 |
@@ -2512,7 +2715,7 @@ load_specific_debug_section (enum dwarf_
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
free_debug_section (debug);
|
|
|
9cc3a9 |
printf (_("\nCan't get contents for section '%s'.\n"),
|
|
|
9cc3a9 |
- section->name);
|
|
|
9cc3a9 |
+ sanitize_string (section->name));
|
|
|
9cc3a9 |
return FALSE;
|
|
|
9cc3a9 |
}
|
|
|
9cc3a9 |
/* Ensure any string section has a terminating NUL. */
|
|
|
9cc3a9 |
@@ -2534,7 +2737,7 @@ load_specific_debug_section (enum dwarf_
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
free_debug_section (debug);
|
|
|
9cc3a9 |
printf (_("\nCan't get contents for section '%s'.\n"),
|
|
|
9cc3a9 |
- section->name);
|
|
|
9cc3a9 |
+ sanitize_string (section->name));
|
|
|
9cc3a9 |
return FALSE;
|
|
|
9cc3a9 |
}
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
@@ -2780,14 +2983,14 @@ read_section_stabs (bfd *abfd, const cha
|
|
|
9cc3a9 |
stabsect = bfd_get_section_by_name (abfd, sect_name);
|
|
|
9cc3a9 |
if (stabsect == NULL)
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
- printf (_("No %s section present\n\n"), sect_name);
|
|
|
9cc3a9 |
+ printf (_("No %s section present\n\n"), sanitize_string (sect_name));
|
|
|
9cc3a9 |
return FALSE;
|
|
|
9cc3a9 |
}
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
if (!bfd_malloc_and_get_section (abfd, stabsect, &contents))
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
non_fatal (_("reading %s section of %s failed: %s"),
|
|
|
9cc3a9 |
- sect_name, bfd_get_filename (abfd),
|
|
|
9cc3a9 |
+ sanitize_string (sect_name), bfd_get_filename (abfd),
|
|
|
9cc3a9 |
bfd_errmsg (bfd_get_error ()));
|
|
|
9cc3a9 |
exit_status = 1;
|
|
|
9cc3a9 |
free (contents);
|
|
|
9cc3a9 |
@@ -2830,7 +3033,7 @@ print_section_stabs (bfd *abfd,
|
|
|
9cc3a9 |
stabp = stabs;
|
|
|
9cc3a9 |
stabs_end = stabp + stab_size;
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
- printf (_("Contents of %s section:\n\n"), stabsect_name);
|
|
|
9cc3a9 |
+ printf (_("Contents of %s section:\n\n"), sanitize_string (stabsect_name));
|
|
|
9cc3a9 |
printf ("Symnum n_type n_othr n_desc n_value n_strx String\n");
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
/* Loop through all symbols and print them.
|
|
|
9cc3a9 |
@@ -3093,7 +3296,7 @@ dump_section (bfd *abfd, asection *secti
|
|
|
9cc3a9 |
if (start_offset >= stop_offset)
|
|
|
9cc3a9 |
return;
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
- printf (_("Contents of section %s:"), section->name);
|
|
|
9cc3a9 |
+ printf (_("Contents of section %s:"), sanitize_string (section->name));
|
|
|
9cc3a9 |
if (display_file_offsets)
|
|
|
9cc3a9 |
printf (_(" (Starting at file offset: 0x%lx)"),
|
|
|
9cc3a9 |
(unsigned long) (section->filepos + start_offset));
|
|
|
9cc3a9 |
@@ -3102,7 +3305,7 @@ dump_section (bfd *abfd, asection *secti
|
|
|
9cc3a9 |
if (!bfd_get_full_section_contents (abfd, section, &data))
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
non_fatal (_("Reading section %s failed because: %s"),
|
|
|
9cc3a9 |
- section->name, bfd_errmsg (bfd_get_error ()));
|
|
|
9cc3a9 |
+ sanitize_string (section->name), bfd_errmsg (bfd_get_error ()));
|
|
|
9cc3a9 |
return;
|
|
|
9cc3a9 |
}
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
@@ -3242,6 +3445,24 @@ dump_symbols (bfd *abfd ATTRIBUTE_UNUSED
|
|
|
9cc3a9 |
free (alloc);
|
|
|
9cc3a9 |
}
|
|
|
9cc3a9 |
}
|
|
|
9cc3a9 |
+ else if (unicode_display != unicode_default
|
|
|
9cc3a9 |
+ && name != NULL && *name != '\0')
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ const char * sanitized_name;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ /* If we want to sanitize the name, we do it here, and
|
|
|
9cc3a9 |
+ temporarily clobber it while calling bfd_print_symbol.
|
|
|
9cc3a9 |
+ FIXME: This is a gross hack. */
|
|
|
9cc3a9 |
+ sanitized_name = sanitize_string (name);
|
|
|
9cc3a9 |
+ if (sanitized_name != name)
|
|
|
9cc3a9 |
+ (*current)->name = sanitized_name;
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ sanitized_name = NULL;
|
|
|
9cc3a9 |
+ bfd_print_symbol (cur_bfd, stdout, *current,
|
|
|
9cc3a9 |
+ bfd_print_symbol_all);
|
|
|
9cc3a9 |
+ if (sanitized_name != NULL)
|
|
|
9cc3a9 |
+ (*current)->name = name;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
else
|
|
|
9cc3a9 |
bfd_print_symbol (cur_bfd, stdout, *current,
|
|
|
9cc3a9 |
bfd_print_symbol_all);
|
|
|
9cc3a9 |
@@ -3307,7 +3528,7 @@ dump_reloc_set (bfd *abfd, asection *sec
|
|
|
9cc3a9 |
&& (last_functionname == NULL
|
|
|
9cc3a9 |
|| strcmp (functionname, last_functionname) != 0))
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
- printf ("%s():\n", functionname);
|
|
|
9cc3a9 |
+ printf ("%s():\n", sanitize_string (functionname));
|
|
|
9cc3a9 |
if (last_functionname != NULL)
|
|
|
9cc3a9 |
free (last_functionname);
|
|
|
9cc3a9 |
last_functionname = xstrdup (functionname);
|
|
|
9cc3a9 |
@@ -3321,9 +3542,9 @@ dump_reloc_set (bfd *abfd, asection *sec
|
|
|
9cc3a9 |
|| (discriminator != last_discriminator)))
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
if (discriminator > 0)
|
|
|
9cc3a9 |
- printf ("%s:%u\n", filename == NULL ? "???" : filename, linenumber);
|
|
|
9cc3a9 |
+ printf ("%s:%u\n", filename == NULL ? "???" : sanitize_string (filename), linenumber);
|
|
|
9cc3a9 |
else
|
|
|
9cc3a9 |
- printf ("%s:%u (discriminator %u)\n", filename == NULL ? "???" : filename,
|
|
|
9cc3a9 |
+ printf ("%s:%u (discriminator %u)\n", filename == NULL ? "???" : sanitize_string (filename),
|
|
|
9cc3a9 |
linenumber, discriminator);
|
|
|
9cc3a9 |
last_line = linenumber;
|
|
|
9cc3a9 |
last_discriminator = discriminator;
|
|
|
9cc3a9 |
@@ -3393,7 +3614,7 @@ dump_reloc_set (bfd *abfd, asection *sec
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
if (section_name == NULL)
|
|
|
9cc3a9 |
section_name = "*unknown*";
|
|
|
9cc3a9 |
- printf ("[%s]", section_name);
|
|
|
9cc3a9 |
+ printf ("[%s]", sanitize_string (section_name));
|
|
|
9cc3a9 |
}
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
if (q->addend)
|
|
|
9cc3a9 |
@@ -3443,7 +3664,7 @@ dump_relocs_in_section (bfd *abfd,
|
|
|
9cc3a9 |
if (relsize < 0)
|
|
|
9cc3a9 |
bfd_fatal (bfd_get_filename (abfd));
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
- printf ("RELOCATION RECORDS FOR [%s]:", section->name);
|
|
|
9cc3a9 |
+ printf ("RELOCATION RECORDS FOR [%s]:", sanitize_string (section->name));
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
if (relsize == 0)
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
@@ -3835,7 +4056,7 @@ main (int argc, char **argv)
|
|
|
9cc3a9 |
set_default_bfd_target ();
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
while ((c = getopt_long (argc, argv,
|
|
|
9cc3a9 |
- "pP:ib:m:M:VvCdDlfFaHhrRtTxsSI:j:wE:zgeGW::",
|
|
|
9cc3a9 |
+ "pP:ib:m:M:VvCdDlfFaHhrRtTxsSI:j:wE:zgeGW::U:",
|
|
|
9cc3a9 |
long_options, (int *) 0))
|
|
|
9cc3a9 |
!= EOF)
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
@@ -4069,6 +4290,23 @@ main (int argc, char **argv)
|
|
|
9cc3a9 |
seenflag = TRUE;
|
|
|
9cc3a9 |
break;
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
+ case 'U':
|
|
|
9cc3a9 |
+ if (streq (optarg, "default") || streq (optarg, "d"))
|
|
|
9cc3a9 |
+ unicode_display = unicode_default;
|
|
|
9cc3a9 |
+ else if (streq (optarg, "locale") || streq (optarg, "l"))
|
|
|
9cc3a9 |
+ unicode_display = unicode_locale;
|
|
|
9cc3a9 |
+ else if (streq (optarg, "escape") || streq (optarg, "e"))
|
|
|
9cc3a9 |
+ unicode_display = unicode_escape;
|
|
|
9cc3a9 |
+ else if (streq (optarg, "invalid") || streq (optarg, "i"))
|
|
|
9cc3a9 |
+ unicode_display = unicode_invalid;
|
|
|
9cc3a9 |
+ else if (streq (optarg, "hex") || streq (optarg, "x"))
|
|
|
9cc3a9 |
+ unicode_display = unicode_hex;
|
|
|
9cc3a9 |
+ else if (streq (optarg, "highlight") || streq (optarg, "h"))
|
|
|
9cc3a9 |
+ unicode_display = unicode_highlight;
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ fatal (_("invalid argument to -U/--unicode: %s"), optarg);
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
case 'H':
|
|
|
9cc3a9 |
usage (stdout, 0);
|
|
|
9cc3a9 |
/* No need to set seenflag or to break - usage() does not return. */
|
|
|
9cc3a9 |
diff -rup binutils.orig/binutils/strings.c binutils-2.30/binutils/strings.c
|
|
|
9cc3a9 |
--- binutils.orig/binutils/strings.c 2021-10-20 12:39:41.686008454 +0100
|
|
|
9cc3a9 |
+++ binutils-2.30/binutils/strings.c 2021-10-20 13:32:22.029182908 +0100
|
|
|
9cc3a9 |
@@ -55,6 +55,19 @@
|
|
|
9cc3a9 |
-T {bfdname}
|
|
|
9cc3a9 |
Specify a non-default object file format.
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
+ --unicode={default|locale|invalid|hex|escape|highlight}
|
|
|
9cc3a9 |
+ -U {d|l|i|x|e|h}
|
|
|
9cc3a9 |
+ Determine how to handle UTF-8 unicode characters. The default
|
|
|
9cc3a9 |
+ is no special treatment. All other versions of this option
|
|
|
9cc3a9 |
+ only apply if the encoding is valid and enabling the option
|
|
|
9cc3a9 |
+ implies --encoding=S.
|
|
|
9cc3a9 |
+ The 'locale' option displays the characters according to the
|
|
|
9cc3a9 |
+ current locale. The 'invalid' option treats them as
|
|
|
9cc3a9 |
+ non-string characters. The 'hex' option displays them as hex
|
|
|
9cc3a9 |
+ byte sequences. The 'escape' option displays them as escape
|
|
|
9cc3a9 |
+ sequences and the 'highlight' option displays them as
|
|
|
9cc3a9 |
+ coloured escape sequences.
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
--output-separator=sep_string
|
|
|
9cc3a9 |
-s sep_string String used to separate parsed strings in output.
|
|
|
9cc3a9 |
Default is newline.
|
|
|
9cc3a9 |
@@ -76,6 +89,22 @@
|
|
|
9cc3a9 |
#include "safe-ctype.h"
|
|
|
9cc3a9 |
#include "bucomm.h"
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
+#ifndef streq
|
|
|
9cc3a9 |
+#define streq(a,b) (strcmp ((a),(b)) == 0)
|
|
|
9cc3a9 |
+#endif
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+typedef enum unicode_display_type
|
|
|
9cc3a9 |
+{
|
|
|
9cc3a9 |
+ unicode_default = 0,
|
|
|
9cc3a9 |
+ unicode_locale,
|
|
|
9cc3a9 |
+ unicode_escape,
|
|
|
9cc3a9 |
+ unicode_hex,
|
|
|
9cc3a9 |
+ unicode_highlight,
|
|
|
9cc3a9 |
+ unicode_invalid
|
|
|
9cc3a9 |
+} unicode_display_type;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+static unicode_display_type unicode_display = unicode_default;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
#define STRING_ISGRAPHIC(c) \
|
|
|
9cc3a9 |
( (c) >= 0 \
|
|
|
9cc3a9 |
&& (c) <= 255 \
|
|
|
9cc3a9 |
@@ -94,7 +123,7 @@ extern int errno;
|
|
|
9cc3a9 |
static int address_radix;
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
/* Minimum length of sequence of graphic chars to trigger output. */
|
|
|
9cc3a9 |
-static int string_min;
|
|
|
9cc3a9 |
+static uint string_min;
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
/* Whether or not we include all whitespace as a graphic char. */
|
|
|
9cc3a9 |
static bfd_boolean include_all_whitespace;
|
|
|
9cc3a9 |
@@ -130,6 +159,7 @@ static struct option long_options[] =
|
|
|
9cc3a9 |
{"target", required_argument, NULL, 'T'},
|
|
|
9cc3a9 |
{"output-separator", required_argument, NULL, 's'},
|
|
|
9cc3a9 |
{"help", no_argument, NULL, 'h'},
|
|
|
9cc3a9 |
+ {"unicode", required_argument, NULL, 'U'},
|
|
|
9cc3a9 |
{"version", no_argument, NULL, 'v'},
|
|
|
9cc3a9 |
{NULL, 0, NULL, 0}
|
|
|
9cc3a9 |
};
|
|
|
9cc3a9 |
@@ -173,7 +203,7 @@ main (int argc, char **argv)
|
|
|
9cc3a9 |
encoding = 's';
|
|
|
9cc3a9 |
output_separator = NULL;
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
- while ((optc = getopt_long (argc, argv, "adfhHn:wot:e:T:s:Vv0123456789",
|
|
|
9cc3a9 |
+ while ((optc = getopt_long (argc, argv, "adfhHn:wot:e:T:s:U:Vv0123456789",
|
|
|
9cc3a9 |
long_options, (int *) 0)) != EOF)
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
switch (optc)
|
|
|
9cc3a9 |
@@ -246,6 +276,23 @@ main (int argc, char **argv)
|
|
|
9cc3a9 |
output_separator = optarg;
|
|
|
9cc3a9 |
break;
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
+ case 'U':
|
|
|
9cc3a9 |
+ if (streq (optarg, "default") || streq (optarg, "d"))
|
|
|
9cc3a9 |
+ unicode_display = unicode_default;
|
|
|
9cc3a9 |
+ else if (streq (optarg, "locale") || streq (optarg, "l"))
|
|
|
9cc3a9 |
+ unicode_display = unicode_locale;
|
|
|
9cc3a9 |
+ else if (streq (optarg, "escape") || streq (optarg, "e"))
|
|
|
9cc3a9 |
+ unicode_display = unicode_escape;
|
|
|
9cc3a9 |
+ else if (streq (optarg, "invalid") || streq (optarg, "i"))
|
|
|
9cc3a9 |
+ unicode_display = unicode_invalid;
|
|
|
9cc3a9 |
+ else if (streq (optarg, "hex") || streq (optarg, "x"))
|
|
|
9cc3a9 |
+ unicode_display = unicode_hex;
|
|
|
9cc3a9 |
+ else if (streq (optarg, "highlight") || streq (optarg, "h"))
|
|
|
9cc3a9 |
+ unicode_display = unicode_highlight;
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ fatal (_("invalid argument to -U/--unicode: %s"), optarg);
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
case 'V':
|
|
|
9cc3a9 |
case 'v':
|
|
|
9cc3a9 |
print_version ("strings");
|
|
|
9cc3a9 |
@@ -260,6 +307,9 @@ main (int argc, char **argv)
|
|
|
9cc3a9 |
}
|
|
|
9cc3a9 |
}
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
+ if (unicode_display != unicode_default)
|
|
|
9cc3a9 |
+ encoding = 'S';
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
if (numeric_opt != 0)
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
string_min = (int) strtoul (argv[numeric_opt - 1] + 1, &s, 0);
|
|
|
9cc3a9 |
@@ -501,11 +551,629 @@ get_char (FILE *stream, file_ptr *addres
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
return r;
|
|
|
9cc3a9 |
}
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+static void
|
|
|
9cc3a9 |
+print_filename_and_address (const char * filename, file_ptr address)
|
|
|
9cc3a9 |
+{
|
|
|
9cc3a9 |
+ if (print_filenames)
|
|
|
9cc3a9 |
+ printf ("%s: ", filename);
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (! print_addresses)
|
|
|
9cc3a9 |
+ return;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ switch (address_radix)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ case 8:
|
|
|
9cc3a9 |
+ if (sizeof (address) > sizeof (long))
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+#ifndef __MSVCRT__
|
|
|
9cc3a9 |
+ printf ("%7llo ", (unsigned long long) address);
|
|
|
9cc3a9 |
+#else
|
|
|
9cc3a9 |
+ printf ("%7I64o ", (unsigned long long) address);
|
|
|
9cc3a9 |
+#endif
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ printf ("%7lo ", (unsigned long) address);
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ case 10:
|
|
|
9cc3a9 |
+ if (sizeof (address) > sizeof (long))
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+#ifndef __MSVCRT__
|
|
|
9cc3a9 |
+ printf ("%7llu ", (unsigned long long) address);
|
|
|
9cc3a9 |
+#else
|
|
|
9cc3a9 |
+ printf ("%7I64d ", (unsigned long long) address);
|
|
|
9cc3a9 |
+#endif
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ printf ("%7ld ", (long) address);
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ case 16:
|
|
|
9cc3a9 |
+ if (sizeof (address) > sizeof (long))
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+#ifndef __MSVCRT__
|
|
|
9cc3a9 |
+ printf ("%7llx ", (unsigned long long) address);
|
|
|
9cc3a9 |
+#else
|
|
|
9cc3a9 |
+ printf ("%7I64x ", (unsigned long long) address);
|
|
|
9cc3a9 |
+#endif
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ printf ("%7lx ", (unsigned long) address);
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+}
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+/* Return non-zero if the bytes starting at BUFFER form a valid UTF-8 encoding.
|
|
|
9cc3a9 |
+ If the encoding is valid then returns the number of bytes it uses. */
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+static unsigned int
|
|
|
9cc3a9 |
+is_valid_utf8 (const unsigned char * buffer, unsigned long buflen)
|
|
|
9cc3a9 |
+{
|
|
|
9cc3a9 |
+ if (buffer[0] < 0xc0)
|
|
|
9cc3a9 |
+ return 0;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (buflen < 2)
|
|
|
9cc3a9 |
+ return 0;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((buffer[1] & 0xc0) != 0x80)
|
|
|
9cc3a9 |
+ return 0;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((buffer[0] & 0x20) == 0)
|
|
|
9cc3a9 |
+ return 2;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (buflen < 3)
|
|
|
9cc3a9 |
+ return 0;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((buffer[2] & 0xc0) != 0x80)
|
|
|
9cc3a9 |
+ return 0;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((buffer[0] & 0x10) == 0)
|
|
|
9cc3a9 |
+ return 3;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (buflen < 4)
|
|
|
9cc3a9 |
+ return 0;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((buffer[3] & 0xc0) != 0x80)
|
|
|
9cc3a9 |
+ return 0;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ return 4;
|
|
|
9cc3a9 |
+}
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+/* Display a UTF-8 encoded character in BUFFER according to the setting
|
|
|
9cc3a9 |
+ of unicode_display. The character is known to be valid.
|
|
|
9cc3a9 |
+ Returns the number of bytes consumed. */
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+static unsigned int
|
|
|
9cc3a9 |
+display_utf8_char (const unsigned char * buffer)
|
|
|
9cc3a9 |
+{
|
|
|
9cc3a9 |
+ unsigned int j;
|
|
|
9cc3a9 |
+ unsigned int utf8_len;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ switch (buffer[0] & 0x30)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ case 0x00:
|
|
|
9cc3a9 |
+ case 0x10:
|
|
|
9cc3a9 |
+ utf8_len = 2;
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ case 0x20:
|
|
|
9cc3a9 |
+ utf8_len = 3;
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ default:
|
|
|
9cc3a9 |
+ utf8_len = 4;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ switch (unicode_display)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ default:
|
|
|
9cc3a9 |
+ fprintf (stderr, "ICE: unexpected unicode display type\n");
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ case unicode_escape:
|
|
|
9cc3a9 |
+ case unicode_highlight:
|
|
|
9cc3a9 |
+ if (unicode_display == unicode_highlight && isatty (1))
|
|
|
9cc3a9 |
+ printf ("\x1B[31;47m"); /* Red. */
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ switch (utf8_len)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ case 2:
|
|
|
9cc3a9 |
+ printf ("\\u%02x%02x",
|
|
|
9cc3a9 |
+ ((buffer[0] & 0x1c) >> 2),
|
|
|
9cc3a9 |
+ ((buffer[0] & 0x03) << 6) | (buffer[1] & 0x3f));
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ case 3:
|
|
|
9cc3a9 |
+ printf ("\\u%02x%02x",
|
|
|
9cc3a9 |
+ ((buffer[0] & 0x0f) << 4) | ((buffer[1] & 0x3c) >> 2),
|
|
|
9cc3a9 |
+ ((buffer[1] & 0x03) << 6) | ((buffer[2] & 0x3f)));
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ case 4:
|
|
|
9cc3a9 |
+ printf ("\\u%02x%02x%02x",
|
|
|
9cc3a9 |
+ ((buffer[0] & 0x07) << 6) | ((buffer[1] & 0x3c) >> 2),
|
|
|
9cc3a9 |
+ ((buffer[1] & 0x03) << 6) | ((buffer[2] & 0x3c) >> 2),
|
|
|
9cc3a9 |
+ ((buffer[2] & 0x03) << 6) | ((buffer[3] & 0x3f)));
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ default:
|
|
|
9cc3a9 |
+ /* URG. */
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (unicode_display == unicode_highlight && isatty (1))
|
|
|
9cc3a9 |
+ printf ("\033[0m"); /* Default colour. */
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ case unicode_hex:
|
|
|
9cc3a9 |
+ putchar ('<');
|
|
|
9cc3a9 |
+ for (j = 0; j < utf8_len; j++)
|
|
|
9cc3a9 |
+ printf ("%02x", buffer [j]);
|
|
|
9cc3a9 |
+ putchar ('>');
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ case unicode_locale:
|
|
|
9cc3a9 |
+ printf ("%.1s", buffer);
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ return utf8_len;
|
|
|
9cc3a9 |
+}
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+/* Display strings in BUFFER. Treat any UTF-8 encoded characters encountered
|
|
|
9cc3a9 |
+ according to the setting of the unicode_display variable. The buffer
|
|
|
9cc3a9 |
+ contains BUFLEN bytes.
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ Display the characters as if they started at ADDRESS and are contained in
|
|
|
9cc3a9 |
+ FILENAME. */
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+static void
|
|
|
9cc3a9 |
+print_unicode_buffer (const char * filename,
|
|
|
9cc3a9 |
+ file_ptr address,
|
|
|
9cc3a9 |
+ const unsigned char * buffer,
|
|
|
9cc3a9 |
+ unsigned long buflen)
|
|
|
9cc3a9 |
+{
|
|
|
9cc3a9 |
+ /* Paranoia checks... */
|
|
|
9cc3a9 |
+ if (filename == NULL
|
|
|
9cc3a9 |
+ || buffer == NULL
|
|
|
9cc3a9 |
+ || unicode_display == unicode_default
|
|
|
9cc3a9 |
+ || encoding != 'S'
|
|
|
9cc3a9 |
+ || encoding_bytes != 1)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ fprintf (stderr, "ICE: bad arguments to print_unicode_buffer\n");
|
|
|
9cc3a9 |
+ return;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (buflen == 0)
|
|
|
9cc3a9 |
+ return;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ /* We must only display strings that are at least string_min *characters*
|
|
|
9cc3a9 |
+ long. So we scan the buffer in two stages. First we locate the start
|
|
|
9cc3a9 |
+ of a potential string. Then we walk along it until we have found
|
|
|
9cc3a9 |
+ string_min characters. Then we go back to the start point and start
|
|
|
9cc3a9 |
+ displaying characters according to the unicode_display setting. */
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ unsigned long start_point = 0;
|
|
|
9cc3a9 |
+ unsigned long i = 0;
|
|
|
9cc3a9 |
+ unsigned int char_len = 1;
|
|
|
9cc3a9 |
+ unsigned int num_found = 0;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ for (i = 0; i < buflen; i += char_len)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ int c = buffer[i];
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ char_len = 1;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ /* Find the first potential character of a string. */
|
|
|
9cc3a9 |
+ if (! STRING_ISGRAPHIC (c))
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ num_found = 0;
|
|
|
9cc3a9 |
+ continue;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (c > 126)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ if (c < 0xc0)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ num_found = 0;
|
|
|
9cc3a9 |
+ continue;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((char_len = is_valid_utf8 (buffer + i, buflen - i)) == 0)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ char_len = 1;
|
|
|
9cc3a9 |
+ num_found = 0;
|
|
|
9cc3a9 |
+ continue;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (unicode_display == unicode_invalid)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ /* We have found a valid UTF-8 character, but we treat it as non-graphic. */
|
|
|
9cc3a9 |
+ num_found = 0;
|
|
|
9cc3a9 |
+ continue;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (num_found == 0)
|
|
|
9cc3a9 |
+ /* We have found a potential starting point for a string. */
|
|
|
9cc3a9 |
+ start_point = i;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ ++ num_found;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (num_found >= string_min)
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (num_found < string_min)
|
|
|
9cc3a9 |
+ return;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ print_filename_and_address (filename, address + start_point);
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ /* We have found string_min characters. Display them and any
|
|
|
9cc3a9 |
+ more that follow. */
|
|
|
9cc3a9 |
+ for (i = start_point; i < buflen; i += char_len)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ int c = buffer[i];
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ char_len = 1;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (! STRING_ISGRAPHIC (c))
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ else if (c < 127)
|
|
|
9cc3a9 |
+ putchar (c);
|
|
|
9cc3a9 |
+ else if (! is_valid_utf8 (buffer + i, buflen - i))
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ else if (unicode_display == unicode_invalid)
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ char_len = display_utf8_char (buffer + i);
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (output_separator)
|
|
|
9cc3a9 |
+ fputs (output_separator, stdout);
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ putchar ('\n');
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ /* FIXME: Using tail recursion here is lazy programming... */
|
|
|
9cc3a9 |
+ print_unicode_buffer (filename, address + i, buffer + i, buflen - i);
|
|
|
9cc3a9 |
+}
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+static int
|
|
|
9cc3a9 |
+get_unicode_byte (FILE * stream,
|
|
|
9cc3a9 |
+ unsigned char * putback,
|
|
|
9cc3a9 |
+ unsigned int * num_putback,
|
|
|
9cc3a9 |
+ unsigned int * num_read)
|
|
|
9cc3a9 |
+{
|
|
|
9cc3a9 |
+ if (* num_putback > 0)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ * num_putback = * num_putback - 1;
|
|
|
9cc3a9 |
+ return putback [* num_putback];
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ * num_read = * num_read + 1;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+#if defined(HAVE_GETC_UNLOCKED) && HAVE_DECL_GETC_UNLOCKED
|
|
|
9cc3a9 |
+ return getc_unlocked (stream);
|
|
|
9cc3a9 |
+#else
|
|
|
9cc3a9 |
+ return getc (stream);
|
|
|
9cc3a9 |
+#endif
|
|
|
9cc3a9 |
+}
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+/* Helper function for print_unicode_stream. */
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+static void
|
|
|
9cc3a9 |
+print_unicode_stream_body (const char * filename,
|
|
|
9cc3a9 |
+ file_ptr address,
|
|
|
9cc3a9 |
+ FILE * stream,
|
|
|
9cc3a9 |
+ unsigned char * putback_buf,
|
|
|
9cc3a9 |
+ unsigned int num_putback,
|
|
|
9cc3a9 |
+ unsigned char * print_buf)
|
|
|
9cc3a9 |
+{
|
|
|
9cc3a9 |
+ /* It would be nice if we could just read the stream into a buffer
|
|
|
9cc3a9 |
+ and then process if with print_unicode_buffer. But the input
|
|
|
9cc3a9 |
+ might be huge or it might time-locked (eg stdin). So instead
|
|
|
9cc3a9 |
+ we go one byte at a time... */
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ file_ptr start_point = 0;
|
|
|
9cc3a9 |
+ unsigned int num_read = 0;
|
|
|
9cc3a9 |
+ unsigned int num_chars = 0;
|
|
|
9cc3a9 |
+ unsigned int num_print = 0;
|
|
|
9cc3a9 |
+ int c;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ /* Find a series of string_min characters. Put them into print_buf. */
|
|
|
9cc3a9 |
+ do
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ if (num_chars >= string_min)
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ c = get_unicode_byte (stream, putback_buf, & num_putback, & num_read);
|
|
|
9cc3a9 |
+ if (c == EOF)
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (! STRING_ISGRAPHIC (c))
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ num_chars = num_print = 0;
|
|
|
9cc3a9 |
+ continue;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (num_chars == 0)
|
|
|
9cc3a9 |
+ start_point = num_read - 1;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (c < 127)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ print_buf[num_print] = c;
|
|
|
9cc3a9 |
+ num_chars ++;
|
|
|
9cc3a9 |
+ num_print ++;
|
|
|
9cc3a9 |
+ continue;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (c < 0xc0)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ num_chars = num_print = 0;
|
|
|
9cc3a9 |
+ continue;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ /* We *might* have a UTF-8 sequence. Time to start peeking. */
|
|
|
9cc3a9 |
+ char utf8[4];
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ utf8[0] = c;
|
|
|
9cc3a9 |
+ c = get_unicode_byte (stream, putback_buf, & num_putback, & num_read);
|
|
|
9cc3a9 |
+ if (c == EOF)
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ utf8[1] = c;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((utf8[1] & 0xc0) != 0x80)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ /* Invalid UTF-8. */
|
|
|
9cc3a9 |
+ putback_buf[num_putback++] = utf8[1];
|
|
|
9cc3a9 |
+ num_chars = num_print = 0;
|
|
|
9cc3a9 |
+ continue;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else if ((utf8[0] & 0x20) == 0)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ /* A valid 2-byte UTF-8 encoding. */
|
|
|
9cc3a9 |
+ if (unicode_display == unicode_invalid)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ putback_buf[num_putback++] = utf8[1];
|
|
|
9cc3a9 |
+ num_chars = num_print = 0;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ print_buf[num_print ++] = utf8[0];
|
|
|
9cc3a9 |
+ print_buf[num_print ++] = utf8[1];
|
|
|
9cc3a9 |
+ num_chars ++;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ continue;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ c = get_unicode_byte (stream, putback_buf, & num_putback, & num_read);
|
|
|
9cc3a9 |
+ if (c == EOF)
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ utf8[2] = c;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((utf8[2] & 0xc0) != 0x80)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ /* Invalid UTF-8. */
|
|
|
9cc3a9 |
+ putback_buf[num_putback++] = utf8[2];
|
|
|
9cc3a9 |
+ putback_buf[num_putback++] = utf8[1];
|
|
|
9cc3a9 |
+ num_chars = num_print = 0;
|
|
|
9cc3a9 |
+ continue;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else if ((utf8[0] & 0x10) == 0)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ /* A valid 3-byte UTF-8 encoding. */
|
|
|
9cc3a9 |
+ if (unicode_display == unicode_invalid)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ putback_buf[num_putback++] = utf8[2];
|
|
|
9cc3a9 |
+ putback_buf[num_putback++] = utf8[1];
|
|
|
9cc3a9 |
+ num_chars = num_print = 0;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ print_buf[num_print ++] = utf8[0];
|
|
|
9cc3a9 |
+ print_buf[num_print ++] = utf8[1];
|
|
|
9cc3a9 |
+ print_buf[num_print ++] = utf8[2];
|
|
|
9cc3a9 |
+ num_chars ++;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ continue;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ c = get_unicode_byte (stream, putback_buf, & num_putback, & num_read);
|
|
|
9cc3a9 |
+ if (c == EOF)
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ utf8[3] = c;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((utf8[3] & 0xc0) != 0x80)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ /* Invalid UTF-8. */
|
|
|
9cc3a9 |
+ putback_buf[num_putback++] = utf8[3];
|
|
|
9cc3a9 |
+ putback_buf[num_putback++] = utf8[2];
|
|
|
9cc3a9 |
+ putback_buf[num_putback++] = utf8[1];
|
|
|
9cc3a9 |
+ num_chars = num_print = 0;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ /* We have a valid 4-byte UTF-8 encoding. */
|
|
|
9cc3a9 |
+ else if (unicode_display == unicode_invalid)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ putback_buf[num_putback++] = utf8[3];
|
|
|
9cc3a9 |
+ putback_buf[num_putback++] = utf8[1];
|
|
|
9cc3a9 |
+ putback_buf[num_putback++] = utf8[2];
|
|
|
9cc3a9 |
+ num_chars = num_print = 0;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ print_buf[num_print ++] = utf8[0];
|
|
|
9cc3a9 |
+ print_buf[num_print ++] = utf8[1];
|
|
|
9cc3a9 |
+ print_buf[num_print ++] = utf8[2];
|
|
|
9cc3a9 |
+ print_buf[num_print ++] = utf8[3];
|
|
|
9cc3a9 |
+ num_chars ++;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ while (1);
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (num_chars >= string_min)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ /* We know that we have string_min valid characters in print_buf,
|
|
|
9cc3a9 |
+ and there may be more to come in the stream. Start displaying
|
|
|
9cc3a9 |
+ them. */
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ print_filename_and_address (filename, address + start_point);
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ unsigned int i;
|
|
|
9cc3a9 |
+ for (i = 0; i < num_print;)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ if (print_buf[i] < 127)
|
|
|
9cc3a9 |
+ putchar (print_buf[i++]);
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ i += display_utf8_char (print_buf + i);
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ /* OK so now we have to start read unchecked bytes. */
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ /* Find a series of string_min characters. Put them into print_buf. */
|
|
|
9cc3a9 |
+ do
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ c = get_unicode_byte (stream, putback_buf, & num_putback, & num_read);
|
|
|
9cc3a9 |
+ if (c == EOF)
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (! STRING_ISGRAPHIC (c))
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (c < 127)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ putchar (c);
|
|
|
9cc3a9 |
+ continue;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (c < 0xc0)
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ /* We *might* have a UTF-8 sequence. Time to start peeking. */
|
|
|
9cc3a9 |
+ unsigned char utf8[4];
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ utf8[0] = c;
|
|
|
9cc3a9 |
+ c = get_unicode_byte (stream, putback_buf, & num_putback, & num_read);
|
|
|
9cc3a9 |
+ if (c == EOF)
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ utf8[1] = c;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((utf8[1] & 0xc0) != 0x80)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ /* Invalid UTF-8. */
|
|
|
9cc3a9 |
+ putback_buf[num_putback++] = utf8[1];
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else if ((utf8[0] & 0x20) == 0)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ /* Valid 2-byte UTF-8. */
|
|
|
9cc3a9 |
+ if (unicode_display == unicode_invalid)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ putback_buf[num_putback++] = utf8[1];
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ (void) display_utf8_char (utf8);
|
|
|
9cc3a9 |
+ continue;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ c = get_unicode_byte (stream, putback_buf, & num_putback, & num_read);
|
|
|
9cc3a9 |
+ if (c == EOF)
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ utf8[2] = c;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((utf8[2] & 0xc0) != 0x80)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ /* Invalid UTF-8. */
|
|
|
9cc3a9 |
+ putback_buf[num_putback++] = utf8[2];
|
|
|
9cc3a9 |
+ putback_buf[num_putback++] = utf8[1];
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else if ((utf8[0] & 0x10) == 0)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ /* Valid 3-byte UTF-8. */
|
|
|
9cc3a9 |
+ if (unicode_display == unicode_invalid)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ putback_buf[num_putback++] = utf8[2];
|
|
|
9cc3a9 |
+ putback_buf[num_putback++] = utf8[1];
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ (void) display_utf8_char (utf8);
|
|
|
9cc3a9 |
+ continue;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ c = get_unicode_byte (stream, putback_buf, & num_putback, & num_read);
|
|
|
9cc3a9 |
+ if (c == EOF)
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ utf8[3] = c;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((utf8[3] & 0xc0) != 0x80)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ /* Invalid UTF-8. */
|
|
|
9cc3a9 |
+ putback_buf[num_putback++] = utf8[3];
|
|
|
9cc3a9 |
+ putback_buf[num_putback++] = utf8[2];
|
|
|
9cc3a9 |
+ putback_buf[num_putback++] = utf8[1];
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else if (unicode_display == unicode_invalid)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ putback_buf[num_putback++] = utf8[3];
|
|
|
9cc3a9 |
+ putback_buf[num_putback++] = utf8[2];
|
|
|
9cc3a9 |
+ putback_buf[num_putback++] = utf8[1];
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ /* A valid 4-byte UTF-8 encoding. */
|
|
|
9cc3a9 |
+ (void) display_utf8_char (utf8);
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ while (1);
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (output_separator)
|
|
|
9cc3a9 |
+ fputs (output_separator, stdout);
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ putchar ('\n');
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (c != EOF)
|
|
|
9cc3a9 |
+ /* FIXME: Using tail recursion here is lazy, but it works. */
|
|
|
9cc3a9 |
+ print_unicode_stream_body (filename, address + num_read, stream, putback_buf, num_putback, print_buf);
|
|
|
9cc3a9 |
+}
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+/* Display strings read in from STREAM. Treat any UTF-8 encoded characters
|
|
|
9cc3a9 |
+ encountered according to the setting of the unicode_display variable.
|
|
|
9cc3a9 |
+ The stream is positioned at ADDRESS and is attached to FILENAME. */
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+static void
|
|
|
9cc3a9 |
+print_unicode_stream (const char * filename,
|
|
|
9cc3a9 |
+ file_ptr address,
|
|
|
9cc3a9 |
+ FILE * stream)
|
|
|
9cc3a9 |
+{
|
|
|
9cc3a9 |
+ /* Paranoia checks... */
|
|
|
9cc3a9 |
+ if (filename == NULL
|
|
|
9cc3a9 |
+ || stream == NULL
|
|
|
9cc3a9 |
+ || unicode_display == unicode_default
|
|
|
9cc3a9 |
+ || encoding != 'S'
|
|
|
9cc3a9 |
+ || encoding_bytes != 1)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ fprintf (stderr, "ICE: bad arguments to print_unicode_stream\n");
|
|
|
9cc3a9 |
+ return;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ /* Allocate space for string_min 4-byte utf-8 characters. */
|
|
|
9cc3a9 |
+ unsigned char * print_buf = xmalloc ((4 * string_min) + 1);
|
|
|
9cc3a9 |
+ /* We should never have to put back more than 4 bytes. */
|
|
|
9cc3a9 |
+ unsigned char putback_buf[5];
|
|
|
9cc3a9 |
+ unsigned int num_putback = 0;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ print_unicode_stream_body (filename, address, stream, putback_buf, num_putback, print_buf);
|
|
|
9cc3a9 |
+ free (print_buf);
|
|
|
9cc3a9 |
+}
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
/* Find the strings in file FILENAME, read from STREAM.
|
|
|
9cc3a9 |
Assume that STREAM is positioned so that the next byte read
|
|
|
9cc3a9 |
is at address ADDRESS in the file.
|
|
|
9cc3a9 |
- Stop reading at address STOP_POINT in the file, if nonzero.
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
If STREAM is NULL, do not read from it.
|
|
|
9cc3a9 |
The caller can supply a buffer of characters
|
|
|
9cc3a9 |
@@ -516,20 +1184,29 @@ get_char (FILE *stream, file_ptr *addres
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
static void
|
|
|
9cc3a9 |
print_strings (const char *filename, FILE *stream, file_ptr address,
|
|
|
9cc3a9 |
- int stop_point, int magiccount, char *magic)
|
|
|
9cc3a9 |
+ int stop_point, int magiccount, char *magic)
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
+ if (unicode_display != unicode_default)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ if (magic != NULL)
|
|
|
9cc3a9 |
+ print_unicode_buffer (filename, address,
|
|
|
9cc3a9 |
+ (const unsigned char *) magic, magiccount);
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (stream != NULL)
|
|
|
9cc3a9 |
+ print_unicode_stream (filename, address, stream);
|
|
|
9cc3a9 |
+ return;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
char *buf = (char *) xmalloc (sizeof (char) * (string_min + 1));
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
while (1)
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
file_ptr start;
|
|
|
9cc3a9 |
- int i;
|
|
|
9cc3a9 |
+ unsigned int i;
|
|
|
9cc3a9 |
long c;
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
/* See if the next `string_min' chars are all graphic chars. */
|
|
|
9cc3a9 |
tryline:
|
|
|
9cc3a9 |
- if (stop_point && address >= stop_point)
|
|
|
9cc3a9 |
- break;
|
|
|
9cc3a9 |
start = address;
|
|
|
9cc3a9 |
for (i = 0; i < string_min; i++)
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
@@ -659,6 +1336,8 @@ usage (FILE *stream, int status)
|
|
|
9cc3a9 |
-T --target=<BFDNAME> Specify the binary file format\n\
|
|
|
9cc3a9 |
-e --encoding={s,S,b,l,B,L} Select character size and endianness:\n\
|
|
|
9cc3a9 |
s = 7-bit, S = 8-bit, {b,l} = 16-bit, {B,L} = 32-bit\n\
|
|
|
9cc3a9 |
+ --unicode={default|show|invalid|hex|escape|highlight}\n\
|
|
|
9cc3a9 |
+ -U {d|s|i|x|e|h} Specify how to treat UTF-8 encoded unicode characters\n\
|
|
|
9cc3a9 |
-s --output-separator=<string> String used to separate strings in output.\n\
|
|
|
9cc3a9 |
@<file> Read options from <file>\n\
|
|
|
9cc3a9 |
-h --help Display this information\n\
|
|
|
9cc3a9 |
--- binutils.orig/binutils/readelf.c 2021-10-20 12:39:41.715008273 +0100
|
|
|
9cc3a9 |
+++ binutils-2.30/binutils/readelf.c 2021-10-20 14:05:42.242326079 +0100
|
|
|
9cc3a9 |
@@ -287,6 +287,18 @@ typedef enum print_mode
|
|
|
9cc3a9 |
}
|
|
|
9cc3a9 |
print_mode;
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
+typedef enum unicode_display_type
|
|
|
9cc3a9 |
+{
|
|
|
9cc3a9 |
+ unicode_locale,
|
|
|
9cc3a9 |
+ unicode_escape,
|
|
|
9cc3a9 |
+ unicode_hex,
|
|
|
9cc3a9 |
+ unicode_highlight,
|
|
|
9cc3a9 |
+ unicode_invalid
|
|
|
9cc3a9 |
+} unicode_display_type;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+static unicode_display_type unicode_display = unicode_locale;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
/* Versioned symbol info. */
|
|
|
9cc3a9 |
enum versioned_symbol_info
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
@@ -538,11 +550,18 @@ print_symbol (signed int width, const ch
|
|
|
9cc3a9 |
if (c == 0)
|
|
|
9cc3a9 |
break;
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
- /* Do not print control characters directly as they can affect terminal
|
|
|
9cc3a9 |
- settings. Such characters usually appear in the names generated
|
|
|
9cc3a9 |
- by the assembler for local labels. */
|
|
|
9cc3a9 |
- if (ISCNTRL (c))
|
|
|
9cc3a9 |
+ if (ISPRINT (c))
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ putchar (c);
|
|
|
9cc3a9 |
+ width_remaining --;
|
|
|
9cc3a9 |
+ num_printed ++;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else if (ISCNTRL (c))
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
+ /* Do not print control characters directly as they can affect terminal
|
|
|
9cc3a9 |
+ settings. Such characters usually appear in the names generated
|
|
|
9cc3a9 |
+ by the assembler for local labels. */
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
if (width_remaining < 2)
|
|
|
9cc3a9 |
break;
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
@@ -550,11 +569,135 @@ print_symbol (signed int width, const ch
|
|
|
9cc3a9 |
width_remaining -= 2;
|
|
|
9cc3a9 |
num_printed += 2;
|
|
|
9cc3a9 |
}
|
|
|
9cc3a9 |
- else if (ISPRINT (c))
|
|
|
9cc3a9 |
+ else if (c == 0x7f)
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
- putchar (c);
|
|
|
9cc3a9 |
- width_remaining --;
|
|
|
9cc3a9 |
- num_printed ++;
|
|
|
9cc3a9 |
+ if (width_remaining < 5)
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ printf ("");
|
|
|
9cc3a9 |
+ width_remaining -= 5;
|
|
|
9cc3a9 |
+ num_printed += 5;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else if (unicode_display != unicode_locale)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ /* Display unicode characters as something else. */
|
|
|
9cc3a9 |
+ unsigned char bytes[4];
|
|
|
9cc3a9 |
+ bfd_boolean is_utf8;
|
|
|
9cc3a9 |
+ unsigned int nbytes;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ bytes[0] = c;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (bytes[0] < 0xc0)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ nbytes = 1;
|
|
|
9cc3a9 |
+ is_utf8 = FALSE;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ bytes[1] = *symbol++;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((bytes[1] & 0xc0) != 0x80)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ is_utf8 = FALSE;
|
|
|
9cc3a9 |
+ /* Do not consume this character. It may only
|
|
|
9cc3a9 |
+ be the first byte in the sequence that was
|
|
|
9cc3a9 |
+ corrupt. */
|
|
|
9cc3a9 |
+ --symbol;
|
|
|
9cc3a9 |
+ nbytes = 1;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else if ((bytes[0] & 0x20) == 0)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ is_utf8 = TRUE;
|
|
|
9cc3a9 |
+ nbytes = 2;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ bytes[2] = *symbol++;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((bytes[2] & 0xc0) != 0x80)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ is_utf8 = FALSE;
|
|
|
9cc3a9 |
+ symbol -= 2;
|
|
|
9cc3a9 |
+ nbytes = 1;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else if ((bytes[0] & 0x10) == 0)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ is_utf8 = TRUE;
|
|
|
9cc3a9 |
+ nbytes = 3;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ bytes[3] = *symbol++;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ nbytes = 4;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if ((bytes[3] & 0xc0) != 0x80)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ is_utf8 = FALSE;
|
|
|
9cc3a9 |
+ symbol -= 3;
|
|
|
9cc3a9 |
+ nbytes = 1;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ is_utf8 = TRUE;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (unicode_display == unicode_invalid)
|
|
|
9cc3a9 |
+ is_utf8 = FALSE;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (unicode_display == unicode_hex || ! is_utf8)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ unsigned int i;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (width_remaining < (nbytes * 2) + 2)
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ putchar (is_utf8 ? '<' : '{');
|
|
|
9cc3a9 |
+ for (i = 0; i < nbytes; i++)
|
|
|
9cc3a9 |
+ printf ("%02x", bytes[i]);
|
|
|
9cc3a9 |
+ putchar (is_utf8 ? '>' : '}');
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ if (unicode_display == unicode_highlight && isatty (1))
|
|
|
9cc3a9 |
+ printf ("\x1B[31;47m"); /* Red. */
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ switch (nbytes)
|
|
|
9cc3a9 |
+ {
|
|
|
9cc3a9 |
+ case 2:
|
|
|
9cc3a9 |
+ if (width_remaining < 6)
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ printf ("\\u%02x%02x",
|
|
|
9cc3a9 |
+ (bytes[0] & 0x1c) >> 2,
|
|
|
9cc3a9 |
+ ((bytes[0] & 0x03) << 6) | (bytes[1] & 0x3f));
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ case 3:
|
|
|
9cc3a9 |
+ if (width_remaining < 6)
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ printf ("\\u%02x%02x",
|
|
|
9cc3a9 |
+ ((bytes[0] & 0x0f) << 4) | ((bytes[1] & 0x3c) >> 2),
|
|
|
9cc3a9 |
+ ((bytes[1] & 0x03) << 6) | (bytes[2] & 0x3f));
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ case 4:
|
|
|
9cc3a9 |
+ if (width_remaining < 8)
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ printf ("\\u%02x%02x%02x",
|
|
|
9cc3a9 |
+ ((bytes[0] & 0x07) << 6) | ((bytes[1] & 0x3c) >> 2),
|
|
|
9cc3a9 |
+ ((bytes[1] & 0x03) << 6) | ((bytes[2] & 0x3c) >> 2),
|
|
|
9cc3a9 |
+ ((bytes[2] & 0x03) << 6) | (bytes[3] & 0x3f));
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ default:
|
|
|
9cc3a9 |
+ /* URG. */
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (unicode_display == unicode_highlight && isatty (1))
|
|
|
9cc3a9 |
+ printf ("\033[0m"); /* Default colour. */
|
|
|
9cc3a9 |
+ }
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
+ if (bytes[nbytes - 1] == 0)
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
}
|
|
|
9cc3a9 |
else
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
@@ -4375,6 +4518,7 @@ static struct option options[] =
|
|
|
9cc3a9 |
{"dwarf-start", required_argument, 0, OPTION_DWARF_START},
|
|
|
9cc3a9 |
{"dwarf-check", no_argument, 0, OPTION_DWARF_CHECK},
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
+ {"unicode", required_argument, 0, 'U'},
|
|
|
9cc3a9 |
{"version", no_argument, 0, 'v'},
|
|
|
9cc3a9 |
{"wide", no_argument, 0, 'W'},
|
|
|
9cc3a9 |
{"help", no_argument, 0, 'H'},
|
|
|
9cc3a9 |
@@ -4432,6 +4576,11 @@ usage (FILE * stream)
|
|
|
9cc3a9 |
fprintf (stream, _("\
|
|
|
9cc3a9 |
-I --histogram Display histogram of bucket list lengths\n\
|
|
|
9cc3a9 |
-W --wide Allow output width to exceed 80 characters\n\
|
|
|
9cc3a9 |
+ -U --unicode=[locale|escape|hex|highlight|invalid]\n\
|
|
|
9cc3a9 |
+ Display unicode characters as determined by the current locale\n\
|
|
|
9cc3a9 |
+ (default), escape sequences, \"<hex sequences>\", highlighted\n\
|
|
|
9cc3a9 |
+ escape sequences, or treat them as invalid and display as\n\
|
|
|
9cc3a9 |
+ \"{hex sequences}\"\n\
|
|
|
9cc3a9 |
@<file> Read options from <file>\n\
|
|
|
9cc3a9 |
-H --help Display this information\n\
|
|
|
9cc3a9 |
-v --version Display the version number of readelf\n"));
|
|
|
9cc3a9 |
@@ -4525,7 +4674,7 @@ parse_args (Filedata * filedata, int arg
|
|
|
9cc3a9 |
usage (stderr);
|
|
|
9cc3a9 |
|
|
|
9cc3a9 |
while ((c = getopt_long
|
|
|
9cc3a9 |
- (argc, argv, "ADHINR:SVWacdeghi:lnp:rstuvw::x:z", options, NULL)) != EOF)
|
|
|
9cc3a9 |
+ (argc, argv, "ADHINR:SU:VWacdeghi:lnp:rstuvw::x:z", options, NULL)) != EOF)
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
switch (c)
|
|
|
9cc3a9 |
{
|
|
|
9cc3a9 |
@@ -4659,6 +4808,25 @@ parse_args (Filedata * filedata, int arg
|
|
|
9cc3a9 |
request_dump (filedata, DISASS_DUMP);
|
|
|
9cc3a9 |
break;
|
|
|
9cc3a9 |
#endif
|
|
|
9cc3a9 |
+ case 'U':
|
|
|
9cc3a9 |
+ if (optarg == NULL)
|
|
|
9cc3a9 |
+ error (_("Missing arg to -U/--unicode")); /* Can this happen ? */
|
|
|
9cc3a9 |
+ else if (streq (optarg, "default") || streq (optarg, "d"))
|
|
|
9cc3a9 |
+ unicode_display = unicode_locale;
|
|
|
9cc3a9 |
+ else if (streq (optarg, "locale") || streq (optarg, "l"))
|
|
|
9cc3a9 |
+ unicode_display = unicode_locale;
|
|
|
9cc3a9 |
+ else if (streq (optarg, "escape") || streq (optarg, "e"))
|
|
|
9cc3a9 |
+ unicode_display = unicode_escape;
|
|
|
9cc3a9 |
+ else if (streq (optarg, "invalid") || streq (optarg, "i"))
|
|
|
9cc3a9 |
+ unicode_display = unicode_invalid;
|
|
|
9cc3a9 |
+ else if (streq (optarg, "hex") || streq (optarg, "x"))
|
|
|
9cc3a9 |
+ unicode_display = unicode_hex;
|
|
|
9cc3a9 |
+ else if (streq (optarg, "highlight") || streq (optarg, "h"))
|
|
|
9cc3a9 |
+ unicode_display = unicode_highlight;
|
|
|
9cc3a9 |
+ else
|
|
|
9cc3a9 |
+ error (_("unknown argument to -U/--unicode: %s"), optarg);
|
|
|
9cc3a9 |
+ break;
|
|
|
9cc3a9 |
+
|
|
|
9cc3a9 |
case 'v':
|
|
|
9cc3a9 |
print_version (program_name);
|
|
|
9cc3a9 |
break;
|