返回共享库符号表 [英] Returning a shared library symbol table
问题描述
例如:
void * sdl_library = dlopen(libSDL.so,RTLD_LAZY);
void * initializer = dlsym(sdl_library,SDL_Init);
假设没有错误,初始化程序将指向共享库libSDK.so中的SD_Init函数。 p>
但是,这需要知道符号SDL_Init存在。
是否可能查询库的所有符号?例如,在这种情况下,它将返回SDL_Init,函数指针和由libSDL.so导出的任何其他符号。
是没有libc的功能来做到这一点。但是,您可以自己编写一个代码(尽管代码有些涉及)。
在Linux上, dlopen()
实际上返回一个 link_map
结构的地址,其中有一个名为 l_addr
的成员指向加载共享对象(假设您的系统不会随机分配共享库位置,并且您的库未被预先链接)。
在Linux上,一个确定的方法来找到基础地址( 拥有ELF标题后,您应该能够遍历导出符号列表(动态符号表) ,首先找到 此外,您可以使用 libelf ,但由于我以前没有经验,我无法指导您。 p> 最后注意到,这个练习有点徒劳:你会得到一个定义的函数的列表,但是你不知道如何调用它们(他们期待什么参数)那么有什么意义? For instance: Assuming no errors, initializer will point to the function SD_Init in the shared library libSDK.so. However this requires knowing the symbol "SDL_Init" exists. Is it possibly to query a library for all its symbols? Eg, in this case it would return SDL_Init, the function pointer, and any other symbols exported by libSDL.so. There is no libc function to do that. However, you can write one yourself (though the code is somewhat involved). On Linux, On Linux, a sure way to find the base address (the address of Having the ELF header, you should be able to iterate over a list of exported symbols (the dynamic symbol table), by first locating the Additionally, you could use libelf, but I'm unable to guide you since I don't have previous experience with it. Finally note that the exercise is somewhat futile: you'll get a list of defined functions, but you'll have no idea how to call them (what parameters they expect), so what's the point? 这篇关于返回共享库符号表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! Elf * _Ehdr
的地址)将使用 dl_iterate_phdr()
在 dlopen( )$>
PT_DYNAMIC
类型的 Elf * _Phdr
,然后找到 DT_SYMTAB
, DT_STRTAB
条目,并迭代动态符号表中的所有符号。使用 /usr/include/elf.h
来指导您。
void* sdl_library = dlopen("libSDL.so", RTLD_LAZY);
void* initializer = dlsym(sdl_library,"SDL_Init");
dlopen()
in fact returns the address of a link_map
structure, which has a member named l_addr
that points to the base address of the loaded shared object (assuming your system doesn't randomize shared library placement, and that your library has not been prelinked).Elf*_Ehdr
) is to use dl_iterate_phdr()
after dlopen()
ing the library.Elf*_Phdr
of type PT_DYNAMIC
, and then locating DT_SYMTAB
, DT_STRTAB
entries, and iterating over all symbols in the dynamic symbol table. Use /usr/include/elf.h
to guide you.