Why DYLD_INSERT_LIBRARIES works differently on 10.4 and 10.5
Why DYLD_INSERT_LIBRARIES works differently on 10.4 and 10.5
- Subject: Why DYLD_INSERT_LIBRARIES works differently on 10.4 and 10.5
- From: Alexander Samoylovich <email@hidden>
- Date: Wed, 1 Apr 2009 15:07:11 -0700
Hello.
I am trying to interpose getaddrinfo and freeaddrinfo functions. For
this purpose I use DYLD_INSERT_LIBRARIES environment variable.
The library source and the shell script to run an application to be
hooked are below.
This trick works for Mac OS X 10.4 for Safari, Firefox and curl. But
under Mac OS X 10.5 it works with Firefox and curl but not with Safari.
For Safari the library hooks freeaddrinfo but not getarrdinfo. The
real application also interposes connect and connect$UNIX2003 and
works for all application and all OSes.
So the question:
Why DYLD_INSERT_LIBRARIES works differently on 10.4 and 10.5? Is there
any way to force it to work the same way and to interpose getaddrinfo
too?
Thank you,
Alex
I use the following shell script to start a process, Safari in this
case:
DYLD_INSERT_LIBRARIES=hook.dylib /Applications/Safari.app/Contents/
MacOS/Safari
hook.dylib is the library to be inserted:
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <netdb.h>
#include <unistd.h>
#include <stdarg.h>
typedef struct interpose_s {
void* new_func;
void* old_func;
} interpose_t;
void report(char *str) {
FILE *f = fopen("hook.log", "a");
fprintf(f, "%s", str);
fclose(f);
}
extern int my_getaddrinfo(const char * __restrict, const char *
__restrict, const struct addrinfo * __restrict, struct addrinfo **
__restrict);
extern void my_freeaddrinfo (struct addrinfo *ai);
int my_getaddrinfo(const char * __restrict a, const char * __restrict
b, const struct addrinfo * __restrict c, struct addrinfo ** __restrict
d) {
report("--getaddrinfo--\n");
return getaddrinfo (a, b, c, d);
}
void my_freeaddrinfo(struct addrinfo *ai) {
report("--freeaddrinfo--\n");
freeaddrinfo(ai);
}
const interpose_t interposes[] __attribute__ ((section ("__DATA,
__interpose"))) = {
{(void*) my_getaddrinfo, (void*) getaddrinfo},
{(void*) my_freeaddrinfo, (void*) freeaddrinfo}};
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden