Linux 如何找出从共享对象导出的所有符号?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1237575/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do i find out what all symbols are exported from a shared object?
提问by chappar
I have a shared object(dll). How do i find out what all symbols are exported from that?
我有一个共享对象(dll)。我如何找出从中导出的所有符号?
采纳答案by Employed Russian
Do you have a "shared object" (usually a shared library on AIX), a UNIX shared library, or a Windows DLL? These are all different things, and your question conflates them all :-(
您是否有“共享对象”(通常是 AIX 上的共享库)、UNIX 共享库或 Windows DLL?这些都是不同的东西,你的问题把它们混为一谈:-(
- For an AIX shared object, use
dump -Tv /path/to/foo.o
. - For an ELF shared library, use
readelf -Ws /path/to/libfoo.so
, or (if you have GNU nm)nm -D /path/to/libfoo.so
. - For a non-ELF UNIX shared library, please state whichUNIX you are interested in.
- For a Windows DLL, use
dumpbin /EXPORTS foo.dll
.
- 对于 AIX 共享对象,请使用
dump -Tv /path/to/foo.o
. - 对于 ELF 共享库,请使用
readelf -Ws /path/to/libfoo.so
, 或(如果您有 GNU nm)nm -D /path/to/libfoo.so
。 - 对于非 ELF UNIX 共享库,请说明您对哪个UNIX 感兴趣。
- 对于 Windows DLL,请使用
dumpbin /EXPORTS foo.dll
.
回答by VolkerK
回答by Ryan Fox
Usually, you would also have a header file that you include in your code to access the symbols.
通常,您还会在代码中包含一个头文件来访问符号。
回答by smcameron
objdump is another good one on linux.
objdump 是 linux 上的另一个好工具。
回答by AllDayCpp
On *nix check nm. On windows use the program Dependency Walker
在 *nix 检查 nm。在 Windows 上使用程序Dependency Walker
回答by codebin
Use: nm --demangle <libname>.so
用: nm --demangle <libname>.so
回答by Bj?rn Lindqvist
If it is a Windows DLL file and your OS is Linux then use winedump:
如果它是 Windows DLL 文件并且您的操作系统是 Linux,则使用winedump:
$ winedump -j export pcre.dll
Contents of pcre.dll: 229888 bytes
Exports table:
Name: pcre.dll
Characteristics: 00000000
TimeDateStamp: 53BBA519 Tue Jul 8 10:00:25 2014
Version: 0.00
Ordinal base: 1
# of functions: 31
# of Names: 31
Addresses of functions: 000375C8
Addresses of name ordinals: 000376C0
Addresses of names: 00037644
Entry Pt Ordn Name
0001FDA0 1 pcre_assign_jit_stack
000380B8 2 pcre_callout
00009030 3 pcre_compile
...
回答by Hi-Angel
The cross-platform way (not only cross-platform itself, but also working, at the very least, with both *.so
and *.dll
)is using reverse-engineering framework radare2. E.g.:
跨平台方式(不仅是跨平台本身,而且至少可以同时*.so
*.dll
使用和)是使用逆向工程框架radare2。例如:
$ rabin2 -s glew32.dll | head -n 5
[Symbols]
vaddr=0x62afda8d paddr=0x0005ba8d ord=000 fwd=NONE sz=0 bind=GLOBAL type=FUNC name=glew32.dll___GLEW_3DFX_multisample
vaddr=0x62afda8e paddr=0x0005ba8e ord=001 fwd=NONE sz=0 bind=GLOBAL type=FUNC name=glew32.dll___GLEW_3DFX_tbuffer
vaddr=0x62afda8f paddr=0x0005ba8f ord=002 fwd=NONE sz=0 bind=GLOBAL type=FUNC name=glew32.dll___GLEW_3DFX_texture_compression_FXT1
vaddr=0x62afdab8 paddr=0x0005bab8 ord=003 fwd=NONE sz=0 bind=GLOBAL type=FUNC name=glew32.dll___GLEW_AMD_blend_minmax_factor
As a bonus, rabin2
recognizes C++ name mangling, for example (and also with .so
file):
作为奖励,可以rabin2
识别 C++ 名称修改,例如(以及.so
文件):
$ rabin2 -s /usr/lib/libabw-0.1.so.1.0.1 | head -n 5
[Symbols]
vaddr=0x00027590 paddr=0x00027590 ord=124 fwd=NONE sz=430 bind=GLOBAL type=FUNC name=libabw::AbiDocument::isFileFormatSupported
vaddr=0x0000a730 paddr=0x0000a730 ord=125 fwd=NONE sz=58 bind=UNKNOWN type=FUNC name=boost::exception::~exception
vaddr=0x00232680 paddr=0x00032680 ord=126 fwd=NONE sz=16 bind=UNKNOWN type=OBJECT name=typeinfoforboost::exception_detail::clone_base
vaddr=0x00027740 paddr=0x00027740 ord=127 fwd=NONE sz=235 bind=GLOBAL type=FUNC name=libabw::AbiDocument::parse
Works with object files too:
也适用于目标文件:
$ g++ test.cpp -c -o a.o
$ rabin2 -s a.o | head -n 5
Warning: Cannot initialize program headers
Warning: Cannot initialize dynamic strings
Warning: Cannot initialize dynamic section
[Symbols]
vaddr=0x08000149 paddr=0x00000149 ord=006 fwd=NONE sz=1 bind=LOCAL type=OBJECT name=std::piecewise_construct
vaddr=0x08000149 paddr=0x00000149 ord=007 fwd=NONE sz=1 bind=LOCAL type=OBJECT name=std::__ioinit
vaddr=0x080000eb paddr=0x000000eb ord=017 fwd=NONE sz=73 bind=LOCAL type=FUNC name=__static_initialization_and_destruction_0
vaddr=0x08000134 paddr=0x00000134 ord=018 fwd=NONE sz=21 bind=LOCAL type=FUNC name=_GLOBAL__sub_I__Z4funcP6Animal