[Scripts][Perl] unmangle指定文件中所有mangle过的C++符号名

#!/usr/bin/perl
# un-mangle c++ symbol
# assuming the c++filt command is available

use strict;
use warnings;

if ($#ARGV != 0) {
    print "usage:\n";
    print "program filename\n";
}

my $in_filename = $ARGV[0];
open(my $in, "<", $in_filename) or die "Can't not open file $in_filename: $!\n";

$/ = undef;
my $body = <$in>;


while ($body =~ /\<(_Z\w+)[\+|\>]/g) {

    my $mangled_symbol_full = $&;
    my $mangled_symbol = $1;

    my $unmangled_symbol = `c++filt '$mangled_symbol'`;
    $unmangled_symbol =~ tr/\n//d;

    #print $mangled_symbol;
    #print "\n";
    #print $unmangled_symbol;
    #print "\n";

    $body =~ s/$mangled_symbol/$unmangled_symbol/g;
}

print $body;
print "\n";

close $in or die "$in: $!\n";

 

 

注:如果你拿到的是objdump出来的东西,就没必要这么复杂了,objdump -C就可以unmangle好了。

 

你可能感兴趣的:([Scripts][Perl] unmangle指定文件中所有mangle过的C++符号名)