Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can do wrapper and "overwrite" function with LD_PRELOAD - similarly to example shown earlier.</p> <pre><code>LD_PRELOAD=/path.../lib_fake_malloc.so ./app </code></pre> <p>But I recommend to do this "slightly" smarter, I mean <strong>calling dlsym once</strong>.</p> <pre><code>#define _GNU_SOURCE #include &lt;stdio.h&gt; #include &lt;stdint.h&gt; #include &lt;dlfcn.h&gt; void* malloc(size_t size) { static void* (*real_malloc)(size_t) = NULL; if (!real_malloc) real_malloc = dlsym(RTLD_NEXT, "malloc"); void *p = real_malloc(size); fprintf(stderr, "malloc(%d) = %p\n", size, p); return p; } </code></pre> <p>example I've found here: <a href="http://www.jayconrod.com/cgi/view_post.py?23" rel="noreferrer">http://www.jayconrod.com/cgi/view_post.py?23</a> post by Jay Conrod.</p> <p>But what I've found really cool at this page is that: <strong>GNU linker provides</strong> a useful option, <strong>--wrap</strong> . When I check "man ld" there is following example:</p> <pre><code>void * __wrap_malloc (size_t c) { printf ("malloc called with %zu\n", c); return __real_malloc (c); } </code></pre> <p>I agree with them that's "trivial example" :). Even dlsym is not needed. </p> <p>Let, me cite one more part of my "man ld" page:</p> <pre><code>--wrap=symbol Use a wrapper function for symbol. Any undefined reference to symbol will be resolved to "__wrap_symbol". Any undefined reference to "__real_symbol" will be resolved to symbol. </code></pre> <p>I hope, description is complete and shows how to use those things.</p>
    singulars
    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