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

Last change on this file since 1858 was 1858, checked in by Sam Hocevar, 13 years ago
  • Network destination port choosing with -p/--ports.
  • Renamed -p/--pick into -l/--list to avoid conflicts.
  • Property svn:keywords set to Id
File size: 3.3 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 1858 2007-11-02 22:45:54Z 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#if defined HAVE_PROCESS_H
31#   include <process.h>
32#endif
33#include <stdio.h>
34#include <sys/types.h>
35#if defined HAVE_UNISTD_H
36#   include <unistd.h>
37#endif
38#include <stdlib.h>
39#include <string.h>
40#include <fcntl.h>
41
42#include <stdarg.h>
43
44#include "libzzuf.h"
45#include "debug.h"
46#include "fd.h"
47#include "sys.h"
48#include "fuzz.h"
49
50/* Library initialisation shit */
51void _zz_init(void) __attribute__((constructor));
52void _zz_fini(void) __attribute__((destructor));
53#if defined HAVE_WINDOWS_H
54BOOL WINAPI DllMain(HINSTANCE, DWORD, PVOID);
55#endif
56
57/* Global variables */
58int   _zz_ready    = 0;
59int   _zz_debugfd  = -1;
60int   _zz_signal   = 0;
61int   _zz_memory   = 0;
62int   _zz_network  = 0;
63
64/* Library initialisation shit */
65void _zz_init(void)
66{
67    char *tmp, *tmp2;
68
69    /* We need this as soon as possible */
70    _zz_mem_init();
71
72    tmp = getenv("ZZUF_DEBUG");
73    if(tmp)
74        _zz_debugfd = atoi(tmp);
75
76    tmp = getenv("ZZUF_SEED");
77    if(tmp && *tmp)
78        _zz_setseed(atol(tmp));
79
80    tmp = getenv("ZZUF_MINRATIO");
81    tmp2 = getenv("ZZUF_MAXRATIO");
82    if(tmp && *tmp && tmp2 && *tmp2)
83        _zz_setratio(atof(tmp), atof(tmp2));
84
85    tmp = getenv("ZZUF_AUTOINC");
86    if(tmp && *tmp == '1')
87        _zz_setautoinc();
88
89    tmp = getenv("ZZUF_BYTES");
90    if(tmp && *tmp)
91        _zz_bytes(tmp);
92
93    tmp = getenv("ZZUF_LIST");
94    if(tmp && *tmp)
95        _zz_list(tmp);
96
97    tmp = getenv("ZZUF_PORTS");
98    if(tmp && *tmp)
99        _zz_ports(tmp);
100
101    tmp = getenv("ZZUF_PROTECT");
102    if(tmp && *tmp)
103        _zz_protect(tmp);
104
105    tmp = getenv("ZZUF_REFUSE");
106    if(tmp && *tmp)
107        _zz_refuse(tmp);
108
109    tmp = getenv("ZZUF_INCLUDE");
110    if(tmp && *tmp)
111        _zz_include(tmp);
112
113    tmp = getenv("ZZUF_EXCLUDE");
114    if(tmp && *tmp)
115        _zz_exclude(tmp);
116
117    tmp = getenv("ZZUF_SIGNAL");
118    if(tmp && *tmp == '1')
119        _zz_signal = 1;
120
121    tmp = getenv("ZZUF_MEMORY");
122    if(tmp && *tmp == '1')
123        _zz_memory = 1;
124
125    tmp = getenv("ZZUF_NETWORK");
126    if(tmp && *tmp == '1')
127        _zz_network = 1;
128
129    _zz_fd_init();
130    _zz_sys_init();
131
132    tmp = getenv("ZZUF_STDIN");
133    if(tmp && *tmp == '1')
134        _zz_register(0);
135
136    _zz_ready = 1;
137
138    debug("libzzuf initialised for PID %li", (long int)getpid());
139}
140
141/* Deinitialisation */
142void _zz_fini(void)
143{
144    _zz_fd_fini();
145}
146
147#if defined HAVE_WINDOWS_H
148BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, PVOID impLoad)
149{
150    (void)hinst;   /* unused */
151    (void)impLoad; /* unused */
152
153    switch(reason)
154    {
155        case DLL_PROCESS_ATTACH:
156            _zz_init();
157            break;
158        case DLL_PROCESS_DETACH:
159            _zz_fini();
160            break;
161    }
162
163    return TRUE;
164}
165#endif
Note: See TracBrowser for help on using the repository browser.