Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>see ld's option <code>--wrap symbol</code>. From the man page:</p> <blockquote> <p>--wrap symbol Use a wrapper function for symbol. Any undefined reference to symbol will be resolved to "<code>__wrap_symbol</code>". Any undefined reference to "<code>__real_symbol</code>" will be resolved to symbol.</p> <p>This can be used to provide a wrapper for a system function. The wrapper function should be called "<code>__wrap_symbol</code>". If it wishes to call the system function, it should call "<code>__real_symbol</code>".</p> <p>Here is a trivial example:</p> </blockquote> <pre><code>void * __wrap_malloc (size_t c) { printf ("malloc called with %zu\n", c); return __real_malloc (c); } </code></pre> <blockquote> <p>If you link other code with this file using --wrap malloc, then all calls to "<code>malloc</code>" will call the function "<code>__wrap_malloc</code>" instead. The call to "__real_malloc" in<br> "<code>__wrap_malloc</code>" will call the real "<code>malloc</code>" function.</p> <p>You may wish to provide a "<code>__real_malloc</code>" function as well, so that links without the --wrap option will succeed. If you do this, you should not put the definition of "<code>__real_malloc</code>" in the same file as "<code>__wrap_malloc</code>"; if you do, the assembler may resolve the call before the linker has a chance to wrap it to "malloc".</p> </blockquote> <p>The other option is to possibly look at the source for ltrace, it is more or less does the same thing :-P.</p> <p>Here's an idea though. You could have your <code>LD_PRELOAD</code>'ed library change the PLT entries to point to your code. This you technically the <code>sbrk()</code> function is still callable from your code nativly.</p>
 

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