[英]How to get address of a symbol in a shared library when provided address of the library?
I am learning about working with shared libraries in C/C++ on Linux. 我正在学习如何在Linux上使用C / C ++中的共享库。 I encountered a little problem that I don't know how to solve.
我遇到了一个我不知道如何解决的问题。
Let's say I have a shared library and an executable. 假设我有一个共享库和一个可执行文件。 However I don't know the library's name or file location (so I can't
dlopen
it). 但是,我不知道图书馆的名称或文件位置(所以我不能
dlopen
它)。 I can only find the address range where the library is mapped into my executable's memory. 我只能找到库映射到可执行文件内存的地址范围。
Is there a way to programmatically get either the handle of the library (something like handle = dlopen(library_address)
) or offset of a symbol within the library (something like address = dlsym(library_address, symbol_name)
)? 有没有办法以编程方式获取库的句柄(类似
handle = dlopen(library_address)
)或库中符号的偏移量(类似于address = dlsym(library_address, symbol_name)
)?
Thank you for your answers. 谢谢您的回答。
If you knew the library's name, you could just call dlopen
again. 如果你知道图书馆的名字,你可以再次打电话给
dlopen
。
If the same shared object is loaded again with
dlopen()
, the same object handle is returned.如果使用
dlopen()
再次加载相同的共享对象,则返回相同的对象句柄。
To discover the loaded modules, you can use dl_iterate_phdr()
. 要发现已加载的模块,可以使用
dl_iterate_phdr()
。
You can also use dladdr()
to inquire about a specific address. 您还可以使用
dladdr()
来查询特定地址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.