From 6995ea2c93e513d2b9aa55937bc3799fd4589946 Mon Sep 17 00:00:00 2001 From: pancake Date: Tue, 7 Jul 2015 00:38:51 +0200 Subject: [PATCH] Handle `rabin2 -D cxx -` like c++filt --- binr/rabin2/rabin2.c | 54 ++++++++++++++++++++++++++++++++------------ man/rabin2.1 | 6 ++--- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/binr/rabin2/rabin2.c b/binr/rabin2/rabin2.c index d036bfcf6a..e6abe891f1 100644 --- a/binr/rabin2/rabin2.c +++ b/binr/rabin2/rabin2.c @@ -535,20 +535,46 @@ int main(int argc, char **argv) { } type = r_bin_demangle_type (do_demangle); file = argv[optind +1]; - switch (type) { - case R_BIN_NM_CXX: res = r_bin_demangle_cxx (file); break; - case R_BIN_NM_JAVA: res = r_bin_demangle_java (file); break; - case R_BIN_NM_OBJC: res = r_bin_demangle_objc (NULL, file); break; - case R_BIN_NM_SWIFT: res = r_bin_demangle_swift (file); break; - case R_BIN_NM_MSVC: res = r_bin_demangle_msvc(file); break; - default: - eprintf ("Unknown lang to demangle. Use: cxx, java, objc, swift\n"); - return 1; - } - if (res && *res) { - printf ("%s\n", res); - free(res); - return 0; + if (!strcmp (file, "-")) { + for (;;) { + file = stdin_gets(); + if (!file || !*file) break; + switch (type) { + case R_BIN_NM_CXX: res = r_bin_demangle_cxx (file); break; + case R_BIN_NM_JAVA: res = r_bin_demangle_java (file); break; + case R_BIN_NM_OBJC: res = r_bin_demangle_objc (NULL, file); break; + case R_BIN_NM_SWIFT: res = r_bin_demangle_swift (file); break; + case R_BIN_NM_MSVC: res = r_bin_demangle_msvc(file); break; + default: + eprintf ("Unknown lang to demangle. Use: cxx, java, objc, swift\n"); + return 1; + } + if (res && *res) { + printf ("%s\n", res); + } else if (file && *file) { + printf ("%s\n", file); + } + R_FREE (res); + R_FREE (file); + } + } else { + switch (type) { + case R_BIN_NM_CXX: res = r_bin_demangle_cxx (file); break; + case R_BIN_NM_JAVA: res = r_bin_demangle_java (file); break; + case R_BIN_NM_OBJC: res = r_bin_demangle_objc (NULL, file); break; + case R_BIN_NM_SWIFT: res = r_bin_demangle_swift (file); break; + case R_BIN_NM_MSVC: res = r_bin_demangle_msvc(file); break; + default: + eprintf ("Unknown lang to demangle. Use: cxx, java, objc, swift\n"); + return 1; + } + if (res && *res) { + printf ("%s\n", res); + free(res); + return 0; + } else { + printf ("%s\n", file); + } } free (res); //eprintf ("%s\n", file); diff --git a/man/rabin2.1 b/man/rabin2.1 index 3af9fd1407..604ea03a93 100644 --- a/man/rabin2.1 +++ b/man/rabin2.1 @@ -10,7 +10,7 @@ .Op Fl b Ar bits .Op Fl B Ar addr .Op Fl C Ar fmt:C:[D] -.Op Fl D Ar lang +.Op Fl D Ar lang sym|- .Op Fl f Ar subbin .Op Fl k Ar query .Op Fl K Ar algo @@ -39,8 +39,8 @@ List classes Create [elf,mach0,pe] for arm and x86-32/64 tiny binaries where 'C' is an hexpair list of the code bytes and ':D' is an optional concatenation to describe the bytes for the data section. .It Fl d Show debug/dwarf information -.It Fl D Ar lang symbolname -Demangle symbol name for lang +.It Fl D Ar lang symbolname|- +Demangle symbol name (or - to read from stdin) for lang (cxx, swift, java, cxx, ..) .It Fl e Show entrypoints for disk and on-memory .It Fl f Ar subbin