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

3

20

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

Harp answered 16/10, 2013 at 5:43 Comment(4)
There are a few solutions here, don't know about any windows-tools though. #35232Tildi
On unix, you can do this from the command line (try man nm). Do you need it in C++?Tabby
Maybe you'll find the right tools in 'Cygwin' ?Anomalistic
I need to do it on windows only..? yes in C++ ...@TabbyHarp
M
28

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

Motoring answered 13/3, 2015 at 19:41 Comment(2)
He asked for help on Windows OS, this answer i irreleventSlype
yes needed solution for windows OS. I used the nm.exe tool present in ndk tools in android sdk/ndkHarp
S
5

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.

Sequestered answered 16/10, 2013 at 6:8 Comment(0)
H
2

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.

Harp answered 27/2, 2017 at 6:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.