查找并复制程序用到的库

mklibs或mklibs-copy是个好东西(ubuntu中是两个单独的软件包),可以把一个ELF文件用到的库给找出来,然后复制到一个指定的地方。

基本用法是一样的:
mklibs/mklibs-copy -d DEST_DIR FILE
其中:DEST_DIR是用来存放找出来的so库的,FILE是要用来分析的文件。

mklibs从符号对文件进行分析,mklibs-copy啥都不说把找到的都直接给放上去了。还有个mklibs-readelf用来打印ELF文件相关信息的,下面是相关的说明:
stlxv@stlxvcomputer:~/tmp$ mklibs-readelf --help
Usage: mklibs-readelf [OPTION]
... FILE...
Prints informations about ELF shared objects and executables
.

Mandatory arguments to long options are mandatory 
for short options too.
  -i
, --print-interp                    Print interpreter of executable
  -n
, --print-needed                    Print needed shared libs
  -R
, --print-rpath                     Print rpath setting
  -s
, --print-soname                    Print soname of shared object
  -p
, --print-symbols-provided          Print provided symbols
  -u
, --print-symbols-undefined         Print undefined symbols
      --help                            Display this help and 
exit
      --version                         Output version information and 
exit

下面是两个例子:

mklibs
stlxv@stlxvcomputer:~$ mklibs -d tmp/ /usr/bin/ruby
I: Using ld-linux
.so.2 as dynamic linker.
I: library reduction pass 
1
7 symbols, 7 unresolved
I: library reduction pass 
2
285 symbols, 16 unresolved
I: library reduction pass 
3
285 symbols, 3 unresolved
I: library reduction pass 
4
285 symbols, 3 unresolved
stlxv@stlxvcomputer:~
$ ls -lh tmp/
总用量 
2.3M
-rwxr-xr-x 
1 stlxv stlxv 107K 2007-07-19 20:31 ld-linux.so.2
-rw-r--r-- 
1 stlxv stlxv  22K 2007-07-19 20:31 libcrypt.so.1
-rw-r--r-- 
1 stlxv stlxv 1.2M 2007-07-19 20:31 libc.so.6
-rw-r--r-- 
1 stlxv stlxv 9.5K 2007-07-19 20:31 libdl.so.2
-rw-r--r-- 
1 stlxv stlxv 146K 2007-07-19 20:31 libm.so.6
-rw-r--r-- 
1 stlxv stlxv  79K 2007-07-19 20:31 libpthread.so.0
-rw-r--r-- 
1 stlxv stlxv 762K 2007-07-19 20:31 libruby1.8.so.1.8
stlxv@stlxvcomputer:~
$ ldd /usr/bin/ruby
        linux-gate
.so.1 =>  (0xffffe000)
        libruby1
.8.so.1.8 => /usr/lib/libruby1.8.so.1.8 (0xb7e04000)
        libpthread
.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0xb7ded000)
        libdl
.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7de8000)
        libcrypt
.so.1 => /lib/tls/i686/cmov/libcrypt.so.1 (0xb7dba000)
        libm
.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7d93000)
        libc
.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7c52000)
        
/lib/ld-linux.so.2 (0xb7eee000)
mklibs-copy
stlxv@stlxvcomputer:~$ mklibs-copy -d tmp/ /usr/bin/ruby
stlxv@stlxvcomputer:~
$ ls -lh tmp/
总用量 
2.4M
-rwxr-xr-x 
1 stlxv stlxv 107K 2007-07-19 20:33 ld-linux.so.2
-rw-r--r-- 
1 stlxv stlxv  22K 2007-07-19 20:33 libcrypt.so.1
-rwxr-xr-x 
1 stlxv stlxv 1.2M 2007-07-19 20:33 libc.so.6
-rw-r--r-- 
1 stlxv stlxv 9.5K 2007-07-19 20:33 libdl.so.2
-rw-r--r-- 
1 stlxv stlxv 146K 2007-07-19 20:33 libm.so.6
-rwxr-xr-x 
1 stlxv stlxv 106K 2007-07-19 20:33 libpthread.so.0
-rw-r--r-- 
1 stlxv stlxv 762K 2007-07-19 20:33 libruby1.8.so.1.8
stlxv@stlxvcomputer:~
$ mklibs-readelf -n /usr/bin/ruby
libruby1
.8.so.1.8
libpthread
.so.0
libdl
.so.2
libcrypt
.so.1
libm
.so.6
libc
.so.6





发布了110 篇原创文章 · 获赞 4 · 访问量 28万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章