LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   can a .so file be used directly from memory? (https://www.linuxquestions.org/questions/programming-9/can-a-so-file-be-used-directly-from-memory-865576/)

KillerCode 02-28-2011 04:28 PM

can a .so file be used directly from memory?
 
ive a .so file stored in a (char *) is there any way i could load functions from it directly? without writing it to disk?
it can be done in windows (dll files) by using some c implementation to use LoadLibrary and GetProcAddress on a dll stored in memory (char *), so i was wondering if such thing exists or possible on linux with dlopen and dlsym?

thanks.

DJ Shaji 02-28-2011 05:43 PM

Well, the simplest thing would be to open a tmp file, and write the .so file to it, do what you gotta do, and then remove it.

If that particular piece of code has to be so confidential, make it a part of the binary itself.

theNbomr 02-28-2011 06:59 PM

The trick is that there is executable code in the library. The char array is in a data-only space, and code in a data segment is not executable. An interesting question is how a userspace application coerces the appropriate pieces of the shared object library to load into an appropriate code space.

--- rod.

KillerCode 03-01-2011 01:21 AM

i dont think its related to the executable sections (.text in this case) the whole problem lies on mapping it to memory as .so file (like dlopen does) and obtain its file descriptot, the rest i guess is easy

DJ Shaji 03-01-2011 04:50 AM

basically its the ld-linux that hooks up static libraries to running programs. my guess would be that you'd have to take its source and modify it to do what you want.

theNbomr 03-01-2011 11:20 AM

Quote:

Originally Posted by KillerCode (Post 4274831)
i dont think its related to the executable sections (.text in this case) the whole problem lies on mapping it to memory as .so file (like dlopen does) and obtain its file descriptot, the rest i guess is easy

Then what do you mean by 'load functions from it'?
It sounds like you are simply trying to replicate the work of a linking loader. Why not have the the existing loader do this? It works on files, though, not on in-memory images. If you export the in-memory image as a virtual file (fuse), then it could be operated on by a conventional loader.

--- rod.


All times are GMT -5. The time now is 09:11 PM.