Guruji
Guruji

Reputation: 279

Is there a way to read the contents of .so file without loading it?

Is there any way to read the content of a .SO(shared objects) file without loading it?

My use-case scenario is:

  1. I have a .so file on windows. I need to query for some methods whether they are present in .so or not.
  2. To know all the classes in a .so file.
  3. Given a class name need to find all the methods on this class.

Note: I can easily do these things on DLL. Also I am working on windows so I can't load a .SO file.

Thanks

Upvotes: 21

Views: 66701

Answers (3)

Guruji
Guruji

Reputation: 279

yes needed solution for windows OS. I used the nm.exe tool present in ndk tools in android sdk/ndk.

i dumped the outputof nm.exe in some file and then using regular expression extracted out all the classes and methods from it.

Upvotes: 2

TCAllen07
TCAllen07

Reputation: 1404

To screen: readelf -a <file>

To save the output, dump it into a file. For example, I'm learning about the Python RPi.GPIO module on Raspberry Pi, which is stored in /usr/lib/python2.7/dist-packages/RPi, so I run: readelf -a GPIO.so > ~/gpio.so.out

Upvotes: 28

ypnos
ypnos

Reputation: 52357

You can read these files with tools included in the GNU binutils. While GNU binutils is typically installed on Linux systems, this is not the case for Windows. However, they run within Cygwin or minGW under Windows.

Resources:

  1. Binutils: http://www.gnu.org/software/binutils/
  2. Cygwin: http://www.cygwin.com/
  3. MinGW: http://www.mingw.org/
  4. MinGW Binutils: http://sourceforge.net/projects/mingw/files/MinGW/Base/binutils/

Note that with MinGW (3.), you do not need Cygwin (2.) and compile Binutils (1.) yourself. Binutils is included in MinGW (3.), but you can also try to download just the Binutils part of MinGW (4.).

How to use nm and readelf to obtain the information is explained here: How do I list the symbols in a .so file

If you want to include this functionality into a C++ program, you could either incorporate the source code of these tools (beware of the license!) or call them from within your program. Probably you will need a Cygwin environment to get the source code compile under Windows.

Upvotes: 5

Related Questions