#!/usr/bin/perl ## objdump-addresses.pl ## by Mike Melanson (mike at multimedia.cx) ## This Perl script parses the output of an 'objdump -Trd' command to ## collect the addresses and names of the functions contained therein. ## The general usage is: ## ## objdump -Trd binfile | objdump-addresses.pl [offset] ## ## binfile is the binary to be examined. The optional [offset] parameter ## will be applied to all function offsets. The offset is assumed to be ## in hexadecimal, without any qualifiers in front. use strict; my $offset = shift; my @functions; my $i; if (!defined $offset) { $offset = 0; } else { $offset = hex($offset); } # accumulate all of the function names and start addresses while ($_ = ) { if (/([0-9A-Fa-f]{8}) <(.*)>:/) { $#functions++; $functions[$#functions]->{'first_address'} = hex($1) + $offset; $functions[$#functions]->{'name'} = $2; } } # fill in the last addresses, assuming that the last address in the # function's range is 1 less than the first address of the next range for ($i = 0; $i < $#functions; $i++) { $functions[$i]->{'last_address'} = $functions[$i + 1]->{'first_address'} - 1; } # special case for the last function $functions[$#functions]->{'last_address'} = hex("FFFFFFFF"); for ($i = 0; $i <= $#functions; $i++) { printf ("function: %08X -> %08X: $functions[$i]->{'name'}\n", $functions[$i]->{'first_address'}, $functions[$i]->{'last_address'}); }