Why DYLD_INSERT_LIBRARIES works differently on 10.4 and 10.5
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Dkim-signature: v=1; a=rsa-sha256; q=dns/txt; l=2071; t=1238623657; x=1239487657; c=relaxed/simple; s=sjdkim2002; h=Content-Type:From:Subject:Content-Transfer-Encoding:MIME-Version; d=cisco.com; i=asamoylo@cisco.com; z=From:=20Alexander=20Samoylovich=20<asamoylo@cisco.com> |Subject:=20Why=20DYLD_INSERT_LIBRARIES=20works=20different ly=20on=2010.4=20and=2010.5 |Sender:=20; bh=PDvBpT1JRg41OsANSUuplPljhab+3jYAR/eqpDJomak=; b=YBY+B42ZY9jDQwRMgWSINl/5dQ5nm4CdC7a7tSCnXZdVaR/7fog5X8q6dA etoXw6efeCbcIk1NZ/Iz+Lt1tcLKg9IC+wOweqD1+uxwQMzF+LXDRt3sjNw7 BYOvI8H+xF; Hello. So the question: Thank you, Alex 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); } void my_freeaddrinfo(struct addrinfo *ai) { report("--freeaddrinfo--\n"); freeaddrinfo(ai); } 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. 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? 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 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); } 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 (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com
participants (1)
-
Alexander Samoylovich