source: zzuf/trunk/src/libzzuf.c @ 1718

Last change on this file since 1718 was 1718, checked in by Sam Hocevar, 14 years ago
  • Carry DEBUG_FILENO in the ZZUF_DEBUG environment variable.
  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1/*
2 *  zzuf - general purpose fuzzer
3 *  Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: libzzuf.c 1718 2007-01-25 22:34:28Z sam $
7 *
8 *  This program is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15/*
16 *  libzzuf.c: preloaded wrapper library
17 */
18
19#include "config.h"
20#define _GNU_SOURCE
21
22#if defined HAVE_STDINT_H
23#   include <stdint.h>
24#elif defined HAVE_INTTYPES_H
25#   include <inttypes.h>
26#endif
27#if defined HAVE_WINDOWS_H
28#   include <windows.h>
29#endif
30#include <stdio.h>
31#include <sys/types.h>
32#include <unistd.h>
33#include <stdlib.h>
34#include <string.h>
35#include <fcntl.h>
36
37#include <stdarg.h>
38
39#include "libzzuf.h"
40#include "debug.h"
41#include "fd.h"
42#include "sys.h"
43#include "fuzz.h"
44
45/* Library initialisation shit */
46void _zz_init(void) __attribute__((constructor));
47void _zz_fini(void) __attribute__((destructor));
48#if defined HAVE_WINDOWS_H
49BOOL WINAPI DllMain(HINSTANCE, DWORD, PVOID);
50#endif
51
52/* Global variables */
53int   _zz_ready    = 0;
54int   _zz_debugfd  = -1;
55int   _zz_signal   = 0;
56int   _zz_memory   = 0;
57int   _zz_network  = 0;
58
59/* Library initialisation shit */
60void _zz_init(void)
61{
62    char *tmp, *tmp2;
63
64    /* We need this as soon as possible */
65    _zz_mem_init();
66
67    tmp = getenv("ZZUF_DEBUG");
68    if(tmp)
69        _zz_debugfd = atoi(tmp);
70
71    tmp = getenv("ZZUF_SEED");
72    if(tmp && *tmp)
73        _zz_setseed(atol(tmp));
74
75    tmp = getenv("ZZUF_MINRATIO");
76    tmp2 = getenv("ZZUF_MAXRATIO");
77    if(tmp && *tmp && tmp2 && *tmp2)
78        _zz_setratio(atof(tmp), atof(tmp2));
79
80    tmp = getenv("ZZUF_AUTOINC");
81    if(tmp && *tmp == '1')
82        _zz_setautoinc();
83
84    tmp = getenv("ZZUF_BYTES");
85    if(tmp && *tmp)
86        _zz_bytes(tmp);
87
88    tmp = getenv("ZZUF_PROTECT");
89    if(tmp && *tmp)
90        _zz_protect(tmp);
91
92    tmp = getenv("ZZUF_REFUSE");
93    if(tmp && *tmp)
94        _zz_refuse(tmp);
95
96    tmp = getenv("ZZUF_INCLUDE");
97    if(tmp && *tmp)
98        _zz_include(tmp);
99
100    tmp = getenv("ZZUF_EXCLUDE");
101    if(tmp && *tmp)
102        _zz_exclude(tmp);
103
104    tmp = getenv("ZZUF_SIGNAL");
105    if(tmp && *tmp == '1')
106        _zz_signal = 1;
107
108    tmp = getenv("ZZUF_MEMORY");
109    if(tmp && *tmp == '1')
110        _zz_memory = 1;
111
112    tmp = getenv("ZZUF_NETWORK");
113    if(tmp && *tmp == '1')
114        _zz_network = 1;
115
116    _zz_fd_init();
117    _zz_sys_init();
118
119    tmp = getenv("ZZUF_STDIN");
120    if(tmp && *tmp == '1')
121        _zz_register(0);
122
123    _zz_ready = 1;
124
125    debug("libzzuf initialised for PID %li", (long int)getpid());
126}
127
128/* Deinitialisation */
129void _zz_fini(void)
130{
131    _zz_fd_fini();
132}
133
134#if defined HAVE_WINDOWS_H
135BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, PVOID impLoad)
136{
137    (void)hinst;   /* unused */
138    (void)impLoad; /* unused */
139
140    switch(reason)
141    {
142        case DLL_PROCESS_ATTACH:
143            _zz_init();
144            break;
145        case DLL_PROCESS_DETACH:
146            _zz_fini();
147            break;
148    }
149
150    return TRUE;
151}
152#endif
Note: See TracBrowser for help on using the repository browser.