Linux:
1. 利用ldd查看可執行程序的依賴庫
-
-
[root@~]# ldd /usr/local/php/bin/php
-
linux-vdso.so.1 => ( 0x00007fff753f5000
注:ldd通過調用動態鏈接器來獲取可執行程序的依賴庫,但是並不推薦在未知的可執行程序上執行業ldd來獲取其依賴庫,因為部分版本的ldd會直接通過調用該可執行程序來獲取其依賴庫,這存在安全風險。
如果某個依賴的庫不存在,會打印類似“xxx.so not found”的提示。
2. 利用pmap工具查詢未知的可執行程序的依賴庫
-
[root@~]# objdump -p /usr/local/php/bin/php |grep NEEDED
-
NEEDED libcrypt.so.1
-
NEEDED librt.so.1
-
NEEDED libmysqlclient.so.18
-
NEEDED libmcrypt.so.4
-
NEEDED libiconv.so.2
-
NEEDED libcurl.so.4
-
NEEDED libm.so.6
-
NEEDED libdl.so.2
-
NEEDED libnsl.so.1
-
NEEDED libxml2.so.2
-
NEEDED libz.so.1
-
NEEDED libssl.so.10
-
NEEDED libcrypto.so.10
-
NEEDED libpthread.so.0
-
NEEDED libc.so.6
-
NEEDED libresolv.so.2
3. 利用pmap查看正在運行時的進程的依賴庫
利用pldd工具既可以獲取進程的內存映射信息,也可以獲取進程的依賴共享庫信息:
-
[root@~/software/pldd]# ps -ef|grep php-fpm
-
root 26534 1 0 2014 ? 00:01:34 php-fpm: master process (/usr/local/php-5.3.29/etc/php-fpm.conf)
-
nobody 26535 26534 0 2014 ? 00:00:04 php-fpm: pool www
-
nobody 26536 26534 0 2014 ? 00:00:05 php-fpm: pool www
-
root 30510 30324 0 00:39 pts/0 00:00:00 grep php-fpm
-
[root@~/software/pldd]# pmap 26534 |head
-
26534: php-fpm: master process (/usr/local/php-5.3.29/etc/php-fpm.conf)
-
0000000000400000 10452K r-x-- /usr/local/php-5.3.29/sbin/php-fpm
-
0000000001035000 76K rw--- /usr/local/php-5.3.29/sbin/php-fpm
-
0000000001048000 104K rw--- [ anon ]
-
0000000002a65000 3448K rw--- [ anon ]
-
000000311c600000 388K r-x-- /usr/lib64/libssl.so.1.0.1e
-
000000311c661000 2048K ----- /usr/lib64/libssl.so.1.0.1e
-
000000311c861000 16K r---- /usr/lib64/libssl.so.1.0.1e
-
000000311c865000 28K rw--- /usr/lib64/libssl.so.1.0.1e
-
1.查看依賴的庫:
objdump -x xxx.so | grep NEEDED
2.查看可執行程序依賴的庫:
objdump -x 可執行程序名 | grep NEEDED
3.查看缺少的庫:
ldd xxx.so
windows:
有時候我們想查看一個exe引用了哪些動態庫,或者我們想看某個動態庫包含哪些接口函數,這個時候可以使用dumpbin.exe工具:
1.輸入Dumpbin -imports calldll.exe查看它的輸入信息,可以看到它加載了***.dll
2.輸入dumpbin –exports dlltest.dll,列出導出函數
開始->所有程序->Microsoft Visual Studio 2010->Visual Studio Tools ->“Visual Studio 命令提示(2010)”后,
就像普通的cmd一樣的命令行環境,就可以正常使用VS的一些工具,其中就包括dumpbin。
輸入如下命令,查看dll信息:
D:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>
dumpbin -exports D:\WorkSpace\DLLTutorial\Debug\DLLTutorial.dll
\dumpbin /dependents your-file.dll
1.輸入Dumpbin -imports calldll.exe查看它的輸入信息,可以看到它加載了***.dll
2.輸入dumpbin –exports dlltest.dll,列出導出函數
/DEPENDENTS:
查看依賴項; 如: dumpbin /dependents vlc.exe
ps:1. 如果有Image has the following delay load dependencies
,列出的為 運行時動態加載的dll。
2. 如果有Image has the following dependencies
,列出的為載入程序時加載的dll。
windows下,進程查看器(ProcessExplorer)可以用來查看進程(實時運行)依賴的dll文件;DependencyWalker可以用來查看dll或exe依賴的dll文件。
linux下,ldd可以用來查看bin文件或dll文件依賴的dll.
用來查看鏈接庫的依賴關系的軟件,名稱為:Dependency Walker.
它的官方網站如下:
http://www.dependencywalker.com/
關於Dependency Walker的介紹:
Dependency Walker is a free utility that scans any 32-bit or 64-bit Windows module (exe, dll, ocx, sys, etc.) and builds a hierarchical tree diagram of all dependent modules. For each module found, it lists all the functions that are exported by that module, and which of those functions are actually being called by other modules. Another view displays the minimum set of required files, along with detailed information about each file including a full path to the file, base address, version numbers, machine type, debug information, and more.
Dependency Walker is also very useful for troubleshooting system errors related to loading and executing modules. Dependency Walker detects many common application problems such as missing modules, invalid modules, import/export mismatches, circular dependency errors, mismatched machine types of modules, and module initialization failures.
Dependency Walker runs on Windows 95, 98, Me, NT, 2000, XP, 2003, Vista, 7, and 8. It can process any 32-bit or 64-bit Windows module, including ones designed for Windows CE. It can be run as graphical application or as a console application. Dependency Walker handles all types of module dependencies, including implicit, explicit (dynamic / runtime), forwarded, delay-loaded, and injected. A detailed help is included.