-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathldd-recursive.pl
executable file
·52 lines (43 loc) · 1.21 KB
/
ldd-recursive.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/perl
use strict;
my %uniq;
foreach my $arg (@ARGV) {
recurseLibs($arg);
delete $uniq{$arg};
}
print join( "\n", keys(%uniq) ) . "\n";
exit 0;
# Written by Igor Ljubuncic ([email protected])
# Yuval Nissan ([email protected])
# Modified by Amos Bird ([email protected])
sub recurseLibs {
my $filename = shift;
return if $uniq{$filename};
$uniq{$filename} = 1;
chomp( my @libraries = `/usr/bin/ldd $filename` );
foreach my $line (@libraries) {
next if not $line;
$line =~ s/^\s+//g;
$line =~ s/\s+$//g;
if ( ( $line =~ /statically linked/ )
or ( $line =~ /not a dynamic executable/ ) )
{
return;
}
elsif (( $line =~ /not found/ )
or ( $line =~ /linux-vdso.so/ ) )
{
next;
}
# Split and recurse on libraries (third value is the lib path):
my @newlibs = split( /\s+/, $line );
# Skip if no mapped or directly linked
# Sane output comes with four elements
if ( scalar(@newlibs) < 4 ) {
$uniq{ $newlibs[0] } = 1;
next;
}
&recurseLibs( $newlibs[2] );
}
return;
}