Advertisement
Guest User

Untitled

a guest
Nov 27th, 2015
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.76 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. ###############################################################################
  4. #
  5. # Modified by Tomonobu Saito (Tomonobu.Saito@jp.sony.com)
  6. #
  7. # Version 1.0 on Nov 10, 2015
  8. #
  9. # This program performs recursive objdump checks for binaries and libraries
  10. # It recurses through entire objdump tree for every listed binary and library
  11. # It completes when no matches found in the specified branch (see $root).
  12. # Same limitations to standard objdump apply
  13. # objdump cannot check libraries with no permissions
  14. #
  15. ###############################################################################
  16.  
  17. # Original script :
  18.  
  19. ###############################################################################
  20. #
  21. # Written by Igor Ljubuncic (igor.ljubuncic@intel.com)
  22. # Yuval Nissan (yuval.nissan@intel.com)
  23. #
  24. # Version 1.0 on Mar 29, 2011
  25. #
  26. # This program performs recursive ldd checks for binaries and libraries
  27. # It recurses through entire ldd tree for every listed binary and library
  28. # It completes when no matches found in the current branch
  29. # Same limitations to standard ldd apply
  30. # ldd cannot check libraries with no permissions
  31. #
  32. ###############################################################################
  33.  
  34. # /*
  35. #
  36. # This file is provided under a dual BSD/GPLv2 license. When using or
  37. # redistributing this file, you may do so under either license.
  38. #
  39. # GPL LICENSE SUMMARY
  40. #
  41. # Copyright(c) 2011 Intel Corporation. All rights reserved.
  42. #
  43. # This program is free software; you can redistribute it and/or modify
  44. # it under the terms of version 2 of the GNU General Public License as
  45. # published by the Free Software Foundation.
  46. #
  47. # This program is distributed in the hope that it will be useful, but
  48. # WITHOUT ANY WARRANTY; without even the implied warranty of
  49. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  50. # General Public License for more details.
  51. #
  52. # You should have received a copy of the GNU General Public License
  53. # along with this program; if not, write to the Free Software
  54. # Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  55. # The full GNU General Public License is included in this distribution
  56. # in the file called LICENSE.GPL.
  57. #
  58. # Contact Information:
  59. # Igor Ljubuncic, igor.ljubuncic@intel.com
  60. # P.O.B 1659, MATAM, 31015 Haifa, Israel
  61. #
  62. # BSD LICENSE
  63. #
  64. # Copyright(c) 2011 Intel Corporation. All rights reserved.
  65. # All rights reserved.
  66. #
  67. # Redistribution and use in source and binary forms, with or without
  68. # modification, are permitted provided that the following conditions
  69. # are met:
  70. #
  71. # * Redistributions of source code must retain the above copyright
  72. # notice, this list of conditions and the following disclaimer.
  73. # * Redistributions in binary form must reproduce the above copyright
  74. # notice, this list of conditions and the following disclaimer in
  75. # the documentation and/or other materials provided with the
  76. # distribution.
  77. # * Neither the name of Intel Corporation nor the names of its
  78. # contributors may be used to endorse or promote products derived
  79. # from this software without specific prior written permission.
  80. #
  81. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  82. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  83. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  84. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  85. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  86. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  87. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  88. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  89. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  90. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  91. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  92. #
  93. # */
  94.  
  95.  
  96. use strict;
  97. use Data::Dumper;
  98. use Getopt::Long;
  99. use File::Basename;
  100.  
  101. # global variables
  102. # ----------------
  103.  
  104. my $result;
  105. my @inputs = ();
  106. my $helpoption=0;
  107. my $debug=0;
  108. my $verbose=0;
  109. my $sep;
  110. my $print_vars;
  111. my $uniq;
  112. my %uniq;
  113.  
  114. ### (saito) Root directory for finding xxx.so
  115. my $root = "~/release_MPKG/l-pdk/device/mediatek_common/";
  116.  
  117. #############################################
  118. #############################################
  119. ### ###
  120. ### FUNCTION MAIN ###
  121. ### ###
  122. #############################################
  123. #############################################
  124.  
  125.  
  126. GetOptions('h|help+' => \$helpoption,
  127. 'debug+' => \$verbose,
  128. 't=s' => \$sep,
  129. 'l' => \$print_vars,
  130. 'uniq' => \$uniq
  131. );
  132.  
  133. if ($verbose==1) {
  134. # Print messages for debug purposes
  135. $debug = 1;
  136. }
  137.  
  138. if (($helpoption==1) || ($ARGV[0] eq "")) {
  139. print "\nRecursive ldd v1.00\n";
  140. print "Written by Igor Ljubuncic (igor.ljubuncic\@intel.com)\n";
  141. print "Written by Yuval Nissan (yuval.nissan\@intel.com)\n\n";
  142. print "Usage mode:\n\n";
  143. print "-d\t\tverbose output\n";
  144. print "-h|help\t\tprint help\n";
  145. print "-t\t\tdelimiter\n";
  146. print "-l\t\tprint env. variables\n";
  147. print "-uniq\t\tprint unique values only\n\n";
  148. exit 0;
  149. }
  150.  
  151. $sep ||= "\t";
  152.  
  153. push @inputs, @ARGV;
  154.  
  155. if($print_vars) {
  156. print "ldd output can be affected by:\n";
  157. print "\$LD_LIBRARY_PATH = '".$ENV{LD_LIBRARY_PATH}."'\n";
  158. print "\$LD_PRELOAD = '".$ENV{LD_PRELOAD}."'\n\n";
  159. }
  160.  
  161. &recurseLibs($inputs[0], 0);
  162. delete $uniq{$inputs[0]};
  163. print join("\n", keys(%uniq))."\n" if $uniq;
  164.  
  165. print "\n";
  166.  
  167. exit 0;
  168.  
  169. ##############################
  170. ##############################
  171. ## ##
  172. ## FUNCTIONS ##
  173. ## ##
  174. ##############################
  175. ##############################
  176.  
  177. sub recurseLibs
  178. {
  179. my $filename=shift;
  180. my $depth = shift;
  181. print ">>>>> Working on file: $filename\n" if $debug;
  182. print "$sep"x$depth if not $uniq;
  183. ++$depth;
  184. return if $uniq{$filename} and $uniq;
  185. $uniq{$filename} = 1;
  186. print basename($filename) . "\n" if not $uniq;
  187. chomp(my @libraries = `/usr/bin/objdump -x "$filename" | grep NEEDED`);
  188. print "Libraries:\n@libraries\n" if $debug;
  189.  
  190. foreach my $line (@libraries) {
  191. next if not $line;
  192. $line =~ s/^\s+//g;
  193. $line =~ s/\s+$//g;
  194. # If static or else
  195. if (($line =~ /statically linked/) or ($line =~ /not a dynamic executable/)) {
  196. return;
  197. }
  198. elsif($line =~ /not found/) {
  199. print "$sep"x$depth if not $uniq;
  200. print "$line\n" if not $uniq;
  201. $uniq{$line} = 1;
  202. next;
  203. }
  204.  
  205.  
  206. # Split and recurse on libraries (third value is the lib path):
  207. my @newlibs = split(/\s+/,$line);
  208. print Dumper(\@newlibs) if $debug;
  209.  
  210. # find lib file from $root
  211. chomp(my @realfile = `/usr/bin/find $root -name $newlibs[1]`);
  212.  
  213. # Skip if no mapped or directly linked
  214. # Sane output comes with four elements
  215. if (scalar(@realfile) < 1) {
  216. print "$sep"x$depth if not $uniq;
  217. print $newlibs[1] . " (not found)\n" if not $uniq;
  218. $uniq{$newlibs[1]} = 1;
  219. next;
  220. }
  221.  
  222. print "\nI'm gonna enter recursion with $realfile[0].\n\n" if $debug;
  223. &recurseLibs($realfile[0], $depth);
  224.  
  225. }
  226.  
  227. print "<<<<< Working on file: $filename\n" if $debug;
  228. return;
  229. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement