LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-28-2011, 04:28 PM   #1
KillerCode
Member
 
Registered: Nov 2010
Posts: 57

Rep: Reputation: 0
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.
 
Old 02-28-2011, 05:43 PM   #2
DJ Shaji
Member
 
Registered: Dec 2004
Location: Yo Momma's house
Distribution: Fedora Rawhide, ArchLinux
Posts: 518
Blog Entries: 15

Rep: Reputation: 106Reputation: 106
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.
 
Old 02-28-2011, 06:59 PM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
 
Old 03-01-2011, 01:21 AM   #4
KillerCode
Member
 
Registered: Nov 2010
Posts: 57

Original Poster
Rep: Reputation: 0
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
 
Old 03-01-2011, 04:50 AM   #5
DJ Shaji
Member
 
Registered: Dec 2004
Location: Yo Momma's house
Distribution: Fedora Rawhide, ArchLinux
Posts: 518
Blog Entries: 15

Rep: Reputation: 106Reputation: 106
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.
 
Old 03-01-2011, 11:20 AM   #6
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Quote:
Originally Posted by KillerCode View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to access physical memory directly? atif_shabir Linux - Embedded & Single-board computer 3 10-20-2009 01:31 AM
how to run a .sh file directly kamesh156 Linux - Software 4 05-21-2009 04:51 PM
can we run the binary file directly kamesh156 Linux - General 1 10-17-2005 07:57 AM
how to run a .sh file directly kamesh156 Linux - General 3 10-13-2005 08:26 AM
how to run a .sh file directly kamesh156 Linux - Software 7 10-10-2005 05:27 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration