How to pull out a function from an ELF shared library?

How to pull out a function from an ELF shared library?

Post by Sudhakar Govindavajha » Fri, 30 Aug 2002 23:46:48



I am trying to study a particular function in a shared library,
without source. (I am trying to crack a random number generator.) I tried
using a decompiler(REC). But the decompiler segfaults even before it
reaches my function. So I want to pullout the function from the ELF .so
file and put it into a new file and try my luck.  Any ideas what I can do?
already wasted a lot of time on this.  this is on a x86 machine. rhl 7.3
2.4 kernel.

Sudhakar
http://www.cs.princeton.edu/~sudhakar/

 
 
 

How to pull out a function from an ELF shared library?

Post by Paul Pluzhniko » Sat, 31 Aug 2002 09:05:04



> I am trying to study a particular function in a shared library,
> without source. (I am trying to crack a random number generator.) I tried
> using a decompiler(REC). But the decompiler segfaults even before it
> reaches my function.

You can often do this:

  gdb /path/to/elf.so
  (gdb) disas function_name

Quote:> So I want to pullout the function from the ELF .so
> file and put it into a new file and try my luck.

I don't think there is an easy way to do that.

Cheers,
--
In order to understand recursion you must first understand recursion.

 
 
 

How to pull out a function from an ELF shared library?

Post by John Reise » Sat, 31 Aug 2002 13:10:02


   > So I want to pullout the function from the ELF .so
   > file and put it into a new file and try my luck.

It should be possible to make a new .so with only that function visible,
which might isolate the function enough to be useful.  It depends on whether
the names of the other functions in the same .so conflict with the rest
of your runtime symbol table.

Do "nm -D foo.so" to see the dynamic runtime global symbols.  Use 'objcopy'
to make a new .so, changing all defined global symbols (other than the
function you want) into 'weak' symbols:

        objcopy -W sym1 -W sym2 -W sym3 ... foo.so bar.so

You might also try "-N sym1" to remove 'sym1' entirely.

Then link with bar.so and let the fun begin.

 
 
 

How to pull out a function from an ELF shared library?

Post by Neil Horma » Sun, 01 Sep 2002 03:18:10



> I am trying to study a particular function in a shared library,
> without source. (I am trying to crack a random number generator.) I tried
> using a decompiler(REC). But the decompiler segfaults even before it
> reaches my function. So I want to pullout the function from the ELF .so
> file and put it into a new file and try my luck.  Any ideas what I can do?
> already wasted a lot of time on this.  this is on a x86 machine. rhl 7.3
> 2.4 kernel.

> Sudhakar
> http://www.cs.princeton.edu/~sudhakar/

use objectdump.  with this tool you can determine the start and end address of
your function, and then you can use it to convert the binary code into assembly.
  Of course, if your goal is to simply recompile it into your own library you
will need to do a good bit of work to incorporate it, but using objectdump will
  give you enough insight into the functions mechanics that you can probably
reproduce the c code function by hand.
Hope that helps
Neil
 
 
 

How to pull out a function from an ELF shared library?

Post by David Tralle » Sun, 01 Sep 2002 03:55:19


Quote:> I am trying to study a particular function in a shared library,
> without source. (I am trying to crack a random number generator.) I tried
> using a decompiler(REC). But the decompiler segfaults even before it
> reaches my function. So I want to pullout the function from the ELF .so
> file and put it into a new file and try my luck.  Any ideas what I can do?
> already wasted a lot of time on this.  this is on a x86 machine. rhl 7.3
> 2.4 kernel.

> Sudhakar
> http://www.cs.princeton.edu/~sudhakar/

have you tried to use dlopen family functions? I think you can open
the .so library with dlopen, and then find symbol of your function
with dlsym and you will receive a pointer to your function. Now is a
black box ... hard job but ...

Another solution: using objdump (dissasembly option) you can optain
asm code.

I hope this is usefull for you.
DTM

 
 
 

1. Will strip(debug shared library) == nodebug shared library ?

compiling the C++ code without debug option to produce object
files(.o) and then producing the shared library with them. Say, the
size of this library is SIZE_SO_NoD.

compiling the C++ code with debug option to produce object files(.o)
and then producing the shared library with them. Then, do 'strip
library_name'. Say, the size of this library is SIZE_SO_D.

Will SIZE_SO_NoD & SIZE_SO_D be exactly/almost equal ? If yes/no, why?
Also, what exactly 'mcs -d library_name' do? Does it reduce symbols
from the shared library which was produced without debug option also?

2. Solaris 2.5 Desktop x86 edition: missing ntpdate?

3. Help with building shared libraries with dependencies on other shared libraries

4. /var/mail polluted with .USER_dt_index files

5. Question: Inclusion of shared libraries during linking of shared libraries

6. kswap and swapctl

7. Shared library loading shared library.

8. Resetting user password automatically

9. Need a Shared Library Guru: beyond simple shared library question

10. When is a shared library not a shared library?

11. Adding to an ELF shared library

12. non-PIC ELF shared libraries (fwd)

13. Elf major-minor shared library