Changes between Initial Version and Version 1 of zzuf/internals


Ignore:
Timestamp:
11/22/2009 03:12:54 PM (15 years ago)
Author:
Sam Hocevar
Comment:

start writing internal documentation

Legend:

Unmodified
Added
Removed
Modified
  • zzuf/internals

    v1 v1  
     1= zzuf internals =
     2
     3This document is an attempt at explaining how zzuf works and how it can be extended to support more functions.
     4
     5== Architecture overview ==
     6
     7The zzuf software consists in two parts:
     8 * The `zzuf` executable
     9 * The `libzzuf` shared library
     10
     11Here is the global workflow when zzuf fuzzes a process:
     12 * `zzuf` reads options from the command line.
     13 * `zzuf` writes fuzzing information to the environment
     14 * `zuff` preloads `libzzuf` into the called process and executes it
     15 * `libzzuf` reads fuzzing information from the envronment
     16 * `libzzuf` diverts standard function calls with its own ones
     17 * the called process runs normally, but any diverted call goes through `libzzuf` first
     18
     19== Writing function diversions ==
     20
     21Diverted functions are declared using the '''`NEW`''' macro. The address of the original function is stored into a global function pointer using the '''`ORIG`''' macro. The '''`LOADSYM`''' macro takes care of retrieving its address and storing it into the pointer.
     22
     23For instance, this is how the '''`memalign`''' function is declared in its libc header, `malloc.h`:
     24
     25{{{
     26#!c
     27void *memalign(size_t boundary, size_t size);
     28}}}
     29
     30And here is how '''`memalign`''' is diverted:
     31
     32{{{
     33#!c
     34#include <malloc.h>
     35#include "libzzuf.h"
     36#include "lib-load.h"
     37
     38/* ... */
     39
     40#if defined HAVE_MEMALIGN
     41static void * (*ORIG(memalign)) (size_t boundary, size_t size);
     42#endif
     43
     44/* ... */
     45
     46#if defined HAVE_MEMALIGN
     47void *NEW(memalign)(size_t boundary, size_t size)
     48{
     49    void *ret;
     50    LOADSYM(memalign);
     51    ret = ORIG(memalign)(boundary, size);
     52    /* ... */
     53    return ret;
     54}
     55#endif
     56}}}
     57
     58=== Standard file descriptor functions ===
     59
     60=== `FILE *` functions ===
     61