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

Last change on this file since 1701 was 1701, checked in by Sam Hocevar, 14 years ago
  • Added DLL initialisation code for Win32.
  • Property svn:keywords set to Id
File size: 3.0 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 1701 2007-01-23 15:38:18Z 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_hasdebug = 0;
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    tmp = getenv("ZZUF_DEBUG");
65    if(tmp && *tmp == '1')
66        _zz_hasdebug = 1;
67
68    tmp = getenv("ZZUF_SEED");
69    if(tmp && *tmp)
70        _zz_setseed(atol(tmp));
71
72    tmp = getenv("ZZUF_MINRATIO");
73    tmp2 = getenv("ZZUF_MAXRATIO");
74    if(tmp && *tmp && tmp2 && *tmp2)
75        _zz_setratio(atof(tmp), atof(tmp2));
76
77    tmp = getenv("ZZUF_AUTOINC");
78    if(tmp && *tmp == '1')
79        _zz_setautoinc();
80
81    tmp = getenv("ZZUF_PROTECT");
82    if(tmp && *tmp)
83        _zz_protect(tmp);
84
85    tmp = getenv("ZZUF_REFUSE");
86    if(tmp && *tmp)
87        _zz_refuse(tmp);
88
89    tmp = getenv("ZZUF_INCLUDE");
90    if(tmp && *tmp)
91        _zz_include(tmp);
92
93    tmp = getenv("ZZUF_EXCLUDE");
94    if(tmp && *tmp)
95        _zz_exclude(tmp);
96
97    tmp = getenv("ZZUF_SIGNAL");
98    if(tmp && *tmp == '1')
99        _zz_signal = 1;
100
101    tmp = getenv("ZZUF_MEMORY");
102    if(tmp && *tmp == '1')
103        _zz_memory = 1;
104
105    tmp = getenv("ZZUF_NETWORK");
106    if(tmp && *tmp == '1')
107        _zz_network = 1;
108
109    _zz_fd_init();
110    _zz_sys_init();
111
112    tmp = getenv("ZZUF_STDIN");
113    if(tmp && *tmp == '1')
114        _zz_register(0);
115
116    _zz_ready = 1;
117
118    debug("libzzuf initialised for PID %li", (long int)getpid());
119}
120
121/* Deinitialisation */
122void _zz_fini(void)
123{
124    _zz_fd_fini();
125}
126
127#if defined HAVE_WINDOWS_H
128BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, PVOID impLoad)
129{
130    (void)hinst;   /* unused */
131    (void)impLoad; /* unused */
132
133    switch(reason)
134    {
135        case DLL_PROCESS_ATTACH:
136            _zz_init();
137            break;
138        case DLL_PROCESS_DETACH:
139            _zz_fini();
140            break;
141    }
142
143    return TRUE;
144}
145#endif
Note: See TracBrowser for help on using the repository browser.