查找並複製程序用到的庫

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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章