For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > June 2007 > Re: how to interposing dlsym/dlopen









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: how to interposing dlsym/dlopen
William Ahern

2007-06-18, 10:07 pm

Frank Cusack <fcusack@fcusack.com> wrote:
> On Mon, 18 Jun 2007 13:35:38 -0700 zhliang2004@gmail.com wrote:
[color=darkred]
> Pretty much. You might be able to use libelf/libgelf to find the
> function address yourself, but wow is that a lot of work. That also
> won't guarantee you're looking at the same library the runtime loader
> located. Why would you want to avoid dlsym()?


[color=darkred]
> Ha, tricky! How about something like


> void *
> dlsym(void *handle, const char *name)
> {
> void *dlp = dlopen("libdl.so", RTLD_LAZY);
> void (*dlsym_fn)(void *, const char *) = dlsym(dlp, "dlsym");
> /* ... do stuff ... */
> return (*dlsym_fn)(handle, name);
> }


If supported (i.e. "#ifdef RTLD_NEXT"), this might work better:

void *
dlsym(void *handle, const char *name)
{
void *(*dlsym_fn)(void *, const char *) = dlsym(RTLD_NEXT, "dlsym");

/* ... do stuff ... */

return (*dlsym_fn)(handle, name);
}


The magic RTLD_NEXT handle makes emenate sense, and may soon become de facto
standard for systems supporting the Solaris style dl* interface.


Frank Cusack

2007-06-19, 4:16 am

On Mon, 18 Jun 2007 19:26:32 -0700 William Ahern <william@wilbur.25thandClement.com> wrote:
> Frank Cusack <fcusack@fcusack.com> wrote:
>
>
>
>
>
> If supported (i.e. "#ifdef RTLD_NEXT"), this might work better:
>
> void *
> dlsym(void *handle, const char *name)
> {
> void *(*dlsym_fn)(void *, const char *) = dlsym(RTLD_NEXT, "dlsym");
>
> /* ... do stuff ... */
>
> return (*dlsym_fn)(handle, name);
> }
>
>
> The magic RTLD_NEXT handle makes emenate sense, and may soon become de facto
> standard for systems supporting the Solaris style dl* interface.


That is an infinite recursion. The call to dlsym() calls the interposer
itself, regardless of the RTLD_NEXT flag.

-frank
Spoon

2007-06-19, 7:09 pm

William Ahern wrote:

> The magic RTLD_NEXT handle makes emenate sense [...]


eminent?
William Ahern

2007-06-19, 7:09 pm

Frank Cusack <fcusack@fcusack.com> wrote:
> On Mon, 18 Jun 2007 19:26:32 -0700 William Ahern <william@wilbur.25thandClement.com> wrote:

<snip>
[color=darkred]
> That is an infinite recursion. The call to dlsym() calls the interposer
> itself, regardless of the RTLD_NEXT flag.


D'oh. I want more of whatever I was smoking. But I'll refrain from posting.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com