Reputation: 11835
is it possible implement nm -D
or readelf -s
using python ctypes?
I want to list all dynamic symbols of a .so
file.
Thanks in advance!
Upvotes: 4
Views: 1925
Reputation: 15550
My answer is: No, it is highly unlikely that ctypes
will give you the enumeration of all available symbols in a library.
Reasons for this are mainly in the scope of ctypes
as a Python module, and the scope of dynamic library API's: POSIX dlopen
+dlsym
or Win32 LoadLibrary
+GetProcAddress
. The primary task of these API's is to, well, load DLL's and obtain callable addresses by symbol names/ordinals. They are not designed for symbol enumeration. You can't list symbols using them; and CPython relies on them, off course, to implement its functions.
It is also needs to be explained that the nm
and readelf
tools you mentioned do their own parsing of executable files to get the symbols list. This is quite tangential to loading the library into memory as an executable module. So you will need a different Python module to do that, something like python-elf
for example.
Upvotes: 4