Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>On mach, you have to use <code>DYLD_INSERT_LIBRARIES</code> macro instead of <code>LD_PRELOAD</code> to specify a list of shared libraries to pre-load (1...*).</p> <p>By default, standard functions are not getting replaced with functions from the shared objects just because they have the same names. You have to explicitly state what function overrides what using <a href="http://www.opensource.apple.com/source/dyld/dyld-132.13/include/mach-o/dyld-interposing.h" rel="nofollow">DYLD_INTERPOSE</a> macro. It allows you to declare a replacement function with any name (for example, override <code>open</code> with <code>my_open</code>) and be able to call original function you are overriding. In addition to that, you don't have to resolve addresses of real functions manually.</p> <p>Alternatively, to achieve Linux-like behavior you have to define <code>DYLD_FORCE_FLAT_NAMESPACE</code> macro.</p> <p>There is a lot more going on, see <a href="http://www.manpagez.com/man/1/dyld/" rel="nofollow">dyld</a> manual for details.</p> <p>So your code should look something like this:</p> <pre><code>#define _GNU_SOURCE #include &lt;stdint.h&gt; #include &lt;stdio.h&gt; #include &lt;string.h&gt; #include &lt;stdarg.h&gt; #include &lt;dlfcn.h&gt; #include &lt;mach-o/dyld-interposing.h&gt; /** * Interponemos nuestra funcion open * * @param char* filename * @param int flags **/ int my_open(char * filename, int flags) { // Entero int p = open(filename, flags); fprintf(stderr, "Abrimos %s) = %i\n", filename, flags); // Devolvemos return p; } DYLD_INTERPOSE(my_open, open) //-------------------------------------------------------- /** * Interponemos nuestra funcion malloc * * @param size_t size */ void* my_malloc(size_t size) { void *p = malloc(size); // Memoria reservada fprintf(stderr, "Reserva de memoria (%d) = %p\n", size, p); // Devolvemos return p; } DYLD_INTERPOSE(my_malloc, malloc) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload