Unix Programming - Re: Possible to do the equivalent of dlopen with an executable

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > July 2006 > Re: Possible to do the equivalent of dlopen with an executable





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: Possible to do the equivalent of dlopen with an executable
Paul Pluzhnikov

2006-07-20, 1:47 am

gazelle@xmission.xmission.com (Kenny McCormack) writes:

> Is it possible to do the equivalent of dlopen with an executable (i.e.,
> not shared lib) ?


On Linux, "dlopen(NULL, ...)" returns you the handle to the main
executable. This handle works fine for subsequent dlsym()s,
provided the exe exports the function you need in its dynamic symbol
table ("nm -D a.out").

> ISTR, that it was
> somehow possible to do the same thing (i.e., execute routines stored
> within) a regular executable as well.


Calling routines in the main executable from a DSO is easy, provided
that you know routine name at DSO compile time, and that the routine
is dynamically exported from the exe.

If the exe loads foo.so (as a plugin) and defines bar() as
dynamically exported symbol, then put this into foo.so:

int foo() {
return bar();
}

and foo.so`foo() will happily call a.out`bar()

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com