码迷,mamicode.com
首页 > 其他好文 > 详细

Mac hook——DYLD_INSERT_LIBRARIES

时间:2014-05-12 02:15:38      阅读:541      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   c   color   

Mac hook——DYLD_INSERT_LIBRARIES

1、gcc生成dylib。

 

gcc -dynamiclib -o mysharedlib.dylib mysharedlib.c

 

2、gcc生成dylib,指定flatnamespace。

gcc -flat_namespace -dynamiclib -o openhook.dylib openhook.c

3、如何Hook?

dani-2:test leedani$ export DYLD_FORCE_FLAT_NAMESPACE=1
dani-2:test leedani$ export DYLD_INSERT_LIBRARIES=openhook.dylib
dani-2:test leedani$ ./main 
--------zz------hello,dani

4、Mac offers a way to override functions in a shared library with DYLD_INSERT_LIBRARIES environment variable (which is similar to LD_PRELOAD on Linux). When you make a twin brother of a function that is defined in an existing shared library, put it in you a shared library, and you register your shared library name in DYLD_INSERT_LIBRARIES, your function is used instead of the original one. This is my simple test. Here I’ve replaced f() in mysharedlib.dylib with f() in openhook.dylib.

5、关于DYLD_INSERT_LIBRARIES & DYLD_FORCE_FLAT_NAMESPACE

bubuko.com,布布扣

 

参考:

1、http://www.h4ck.org.cn/2013/04/hooking-library-calls-on-mac-using-dyld_insert_libraries/

2、http://blog.sina.com.cn/s/blog_45e2b66c0101cde0.html

 

Mac hook——DYLD_INSERT_LIBRARIES,布布扣,bubuko.com

Mac hook——DYLD_INSERT_LIBRARIES

标签:style   blog   class   code   c   color   

原文地址:http://www.cnblogs.com/tekkaman/p/3721378.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!