• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Why DYLD_INSERT_LIBRARIES works differently on 10.4 and 10.5
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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: Thu, 2 Apr 2009 09:37:28 -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.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: Why DYLD_INSERT_LIBRARIES works differently on 10.4 and 10.5
      • From: Peter O'Gorman <email@hidden>
  • Prev by Date: Re: How to get rid of local C++ symbols in a dylib?
  • Next by Date: Xcode hangs adding Rails project to Organizer
  • Previous by thread: Re: How to debug Xcode dependency-tracking?
  • Next by thread: Re: Why DYLD_INSERT_LIBRARIES works differently on 10.4 and 10.5
  • Index(es):
    • Date
    • Thread