#!/usr/bin/perl use strict; use warnings; sub ldlist; sub chk_ldd; my $ldd = '/usr/bin/ldd'; my @list = ('/sbin', '/bin', '/usr/sbin', '/usr/bin', '/usr/games','/usr/local/sbin','/usr/local/bin', '/lib','/usr/lib','/usr/local/lib', '/libexec', '/usr/libexec', '/usr/local/libexec'); my %libs = (); my %done = (); foreach my $dir_path (@list){ print "###################\n"; &ldlist($dir_path); } sub ldlist{ print "DIR ".$_[0]."\n"; my $top_dir = $_[0]; opendir(DIR,$top_dir); my @file = readdir(DIR); closedir(DIR); my $path; foreach(@file){ if($_ eq '.' || $_ eq '..'){ next; } $path = $top_dir.'/'.$_; if(-l $path){ $path = readlink($path); if($path =~ /^[^\/]/){ $path = $top_dir.'/'.$path; } } if(-d $path){ &ldlist($path); next; } if(-x $path){ &chk_ldd($path); }elsif($path =~ /\.so/){ &chk_ldd($path); } } } sub chk_ldd{ my $chk_file = $_[0]; my $i; if(exists $done{$chk_file}){ return; } $done{$chk_file} = 1; print $chk_file."\n"; my @res = `$ldd $chk_file`; for($i=1; $i<=$#res; $i++){ my $r = $res[$i]; if($r =~ /not/i){ print $r; }else{ $r =~ s/^\s*(.*?)\s*$/$1/; my @l = split(/ +/,$r); if(exists $libs{$l[0]}){ next; } $libs{$l[0]} = $l[2]; print "*\t".$l[0]."\t".$l[2]."\n"; &chk_ldd($l[2]); } } }