Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading .so Files From Memory [duplicate]

Possible Duplicate:
dlopen from memory?

I've seen this for Windows' DLL files, being loaded from a memory buffer, but I cant find it anywhere for Linux, and "ld" source code is the most complex code I've ever seen. So:

Is there any example of loading .so files from memory? Even a simple one that I can finish? I just don't know where to start, even though I've read most of the ELF specifications it's still mysterious to me.

like image 890
killercode Avatar asked Jan 26 '12 09:01

killercode


People also ask

Where are .so files stored?

These files are normally stored in /lib/ or /usr/lib/.

How do I open a .so file?

so file is a binary file used as a native library on Android. Normally it's a part of an Android application. If you want to see its content, you need to open it as a binary file in a binary (hex) viewer. In any case you won't see much there, but hex code.

What is difference between .so and .a library?

A . a file is a static library, while a . so file is a shared object dynamic library similar to a DLL on Windows.

Can Windows use .so files?

DLLs and SOs are fundamentally different formats, so in short, no, you can't load a DLL on Linux or an SO on Windows.


1 Answers

You're looking at the source code of a wrong thing: ld doesn't do program and library loading. Instead, you should look at the source code of dlopen and dlsym functions found in libc. Also, you should look at the source of the dynamic linker: ld-linux.so (the true name varies with the platform; execute ldd /bin/ls to find out where the dynamic linker resides).

ELF parsing isn't difficult, but it requires attention to detail and understanding of assembly code for the particular CPU; you need also ABI specification for your platform (and it's different for 32- and 64-bit linux, and is also different between CPUs.)

If you just need to load object files from memory at run-time (i.e., it doesn't have to be a SO), you can look at X11 project: they have implemented a module system which, basically, loads object code at some address and relocates it.

like image 151
zvrba Avatar answered Sep 27 '22 17:09

zvrba