| abstract
| - use Data::Dumper; $Data::Dumper::Sortkeys = 1; if (@ARGV != 1) { print("Usage e.g.:
cat stubs_entry.S stubs_entry_2.S | $0 dump.bin.dis > outfile
"); exit; } $dissfile = $ARGV[0]; 1.
* $stubfile = $ARGV[1]; 1.
* 2. 1.
* 3. 2. 1.
* 4. 3. 2. 1.
* 5. 4. 3. 2. 1.
* print STDERR "scan stub file
"; my %nstub_names; # hash by name to eliminate doubles 1.
* open(IN, "<$stubfile") or die "cannot open $stubfile: $!"; while () { if (/^NH?STUB\((.*),.*0x(xdigit:*)/i) { my $addr = sprintf("%08x", hex($2)); #$nstub{$addr} = $1; $nstub_names{$1} = $addr; } } close IN; 1.
* hash by address my %nstub = reverse %nstub_names; $nstub{ff81000c} = "TEST start"; print Dumper(\%nstub); 1.
* exit; 1.
* 2. 1.
* 3. 2. 1.
* 4. 3. 2. 1.
* 5. 4. 3. 2. 1.
* print STDERR "scan diss file
"; open(IN, "<$dissfile") or die "cannot read $dissfile: $!"; while () { if ($_ eq " ...
") { print $_; next;} 1.
* print $_; my ($addr, $op, $line) = $_ =~ /^(xdigit:*): (xdigit:*) (.*)/; unless ($addr) { print $_; next; } $op_n = hex($op); if ( ($op_n & 0x0e000000) == 0x0a000000) { # any branch op # ff8771c4: ebfe91c5 bl ff81b8e0 <_binary_dump_bin_start+0xb8e0> my ($goto) = $line =~ / (xdigit:*)/; if (my $func = $nstub{$goto}) { $line =~ s/<.*>/<$func>/; } my $rel = hex($goto)-hex($addr); $rel = "+$rel" if ($rel>0); $line =~ s/<(.*)>/<$1 $rel>/; } $line = "$op $line"; 1.
* 2. 1.
* 3. 2.
* TODO: handle DEF() from stub_min.S
* 4. 3.
* if ( 5. 4.
* ($line =~ /^(.* ldr.*\[pc, #([-\d]+).*; )/) || 6. 5.
* ($line =~ /^(.* add.*pc, #([-\d]+).*; )/) 7. 6.
* ) { 8. 7.
* $line = $1; 9. 8.
* my $off = hex($addr) - hex($offset) + $2 + 8; 10. 9.
* my $point = sprintf("%08x", hex($addr) + $2 + 8); 11. 10.
* my $value = &get_word($off); 12. 11.
* $line .= "$point: ($value) "; 13. 12.
* if (my $str = $nstub{$point}) { 14. 13.
* $line .= qq| *"$str"|; 15. 14.
* } 16. 15.
* elsif (my $str = $nstub{$value}) { 17. 16.
* $line .= qq| **"$str"|;
* } 18. 17.
* } 19. 18.
* # ff815e1c: e24f0090 sub r0, pc, #144 ; 0x90 20. 19.
* elsif ($line =~ /^(.* sub.*pc, #([-\d]+).*; )/) {
* $line = $1; 21. 20.
* my $off = hex($addr) - hex($offset) - $2 + 8; 22. 21.
* my $point = sprintf("%08x", hex($addr) - $2 + 8);
* my $value = &get_word($off);
* $line .= "$point: ($value) ";
* if (my $str = $nstub{$point}) {
* $line .= qq| *"$str"|;
* }
* elsif (my $str = $nstub{$value}) {
* $line .= qq| **"$str"|;
* }
* } if (my $str = $nstub{$addr}) { print qq|
NSTUB($str, 0x$addr):
|; } print "$addr: $line
"; # progress print STDERR "0x$addr "; } close IN;
|