Settings

Theme

Hooking C Functions at Runtime

thomasfinch.me

18 points by tomf64 10 years ago · 4 comments

Reader

glandium 10 years ago

That's a lot of work for something that the dynamic linker on OS X supports out of the box. See, for example, http://toves.freeshell.org/interpose/ or search for "OS X interpose" on your favorite search engine.

erobbins 10 years ago

Interesting.. in the linux/unix world I've always intercepted functions with LD_PRELOAD. I'm guessing that's not an option on OS X?

  • jamessu 10 years ago

    DYLD_INSERT_LIBRARIES is more or less the OS X equivalent of LD_PRELOAD.

    • glandium 10 years ago

      With a big bias towards "less". Dynamic linking on OS X uses strong binding (unless you specifically link your binaries with the option that disables strong binding). That is, symbols are associated with libraries. So for example, when your program wants the symbol for e.g. malloc, the symbol table will also have the information that the symbol is in libSystem.dylib (or whatever the lib for that is), and the dynamic linker will pick malloc from there, even when DYLD_INSERT_LIBRARIES contains a library exporting the malloc symbol. On GNU/Linux at least, even with symbol versioning, which adds some binding information linking symbol version names to library names, ld.so still resolves symbols with versions to the symbol exported by a library in LD_PRELOAD.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection