简体   繁体   English

如何在提供库的地址时获取共享库中符号的地址?

[英]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

From the man page : 手册页

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.

相关问题 glibc-获取具有包含指定地址的符号的共享库的句柄 - glibc - get handle to shared library having symbol containing specified address 如何从库中获取地址信息以在所有进程之间共享? - How to get address information from library to be shared among all processes? 如何在运行时确定共享库中全局变量的地址范围? - How to determine the address range of global variables in a shared library at runtime? 如何判断进程地址空间中加载共享库的位置? - How to tell where a shared library is loaded in process address space? 共享库如何链接到符号? - shared library how to link to a symbol? PIC共享库中的不同功能地址 - different function address in PIC shared library 如何找到共享库的符号的绝对地址? - How find absolute address of symbol of shared libraries? 创建共享库时,如何告诉链接器可执行文件中包含符号? - When creating a shared library, how to tell the linker that a symbol is in the executable? 如何使用库从文件访问共享库中提到的指令的地址? - How can i access address of an instruction mentioned in shared library from a file using the library? 加载共享库时未定义的符号 - Undefined symbol when loading a shared library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM