Reorganise source code to better separate zzuf and libzzuf. Note: the Win32

build is now broken.
This commit is contained in:
Sam Hocevar
2009-12-12 22:19:47 +00:00
committed by sam
parent e0768d009b
commit 606d50b39f
25 changed files with 76 additions and 33 deletions
+24 -10
View File
@@ -1,22 +1,36 @@
# $Id$
COMMON = random.c random.h ranges.c ranges.h fd.c fd.h fuzz.c fuzz.h
bin_PROGRAMS = zzuf
pkglib_LTLIBRARIES = libzzuf.la
ZZUF = \
zzuf.c opts.c opts.h md5.c md5.h timer.c timer.h
LIBZZUF = \
libzzuf/libzzuf.c libzzuf/libzzuf.h \
libzzuf/debug.c libzzuf/debug.h \
libzzuf/sys.c libzzuf/sys.h \
libzzuf/network.c libzzuf/network.h \
libzzuf/lib-fd.c libzzuf/lib-mem.c libzzuf/lib-signal.c \
libzzuf/lib-stream.c libzzuf/lib-load.h
COMMON = \
common/random.c common/random.h \
common/ranges.c common/ranges.h \
common/fd.c common/fd.h \
common/fuzz.c common/fuzz.h
if NEED_GETOPT_LONG
GETOPT = mygetopt.c mygetopt.h
endif
bin_PROGRAMS = zzuf
zzuf_SOURCES = zzuf.c $(COMMON) $(GETOPT) \
opts.c opts.h md5.c md5.h timer.c timer.h
zzuf_CFLAGS = -DLIBDIR=\"$(libdir)/zzuf\"
zzuf_SOURCES = $(ZZUF) $(COMMON) $(GETOPT)
zzuf_CFLAGS = -DLIBDIR=\"$(libdir)/zzuf\" -Icommon/
zzuf_LDFLAGS = $(MATH_LIBS) $(WINSOCK2_LIBS)
zzuf_DEPENDENCIES = libzzuf.la
pkglib_LTLIBRARIES = libzzuf.la
libzzuf_la_SOURCES = libzzuf.c libzzuf.h $(COMMON) debug.c debug.h \
sys.c sys.h network.c network.h \
lib-fd.c lib-mem.c lib-signal.c lib-stream.c lib-load.h
libzzuf_la_CFLAGS = -DLIBZZUF
libzzuf_la_SOURCES = $(LIBZZUF) $(COMMON)
libzzuf_la_CFLAGS = -DLIBZZUF -Ilibzzuf/ -Icommon/
libzzuf_la_LDFLAGS = -avoid-version -no-undefined $(DLL_LDFLAGS)
libzzuf_la_LIBADD = $(GETOPT_LIBS) $(DL_LIBS) $(MATH_LIBS) $(WINSOCK2_LIBS)
+1 -14
View File
@@ -13,7 +13,7 @@
*/
/*
* libzzuf.h: preloaded wrapper library
* common.h: default fuzzing settings
*/
/* We arbitrarily split files into 1024-byte chunks. Each chunk has an
@@ -47,16 +47,3 @@ struct fuzz
uint8_t data[CHUNKBYTES];
};
/* Internal variables */
extern int _zz_ready;
extern int _zz_disabled;
extern int _zz_debuglevel;
extern int _zz_debugfd;
extern int _zz_signal;
extern int _zz_memory;
extern int _zz_network;
extern int _zz_autoinc;
/* This function is needed to initialise memory functions */
extern void _zz_mem_init(void);
+9 -3
View File
@@ -31,12 +31,14 @@
#include <string.h>
#include <math.h>
#include "debug.h"
#include "libzzuf.h"
#include "common.h"
#include "fd.h"
#include "fuzz.h"
#include "network.h"
#include "ranges.h"
#if defined LIBZZUF
# include "debug.h"
# include "network.h"
#endif
/* Regex stuff */
#if defined HAVE_REGEX_H
@@ -223,8 +225,10 @@ void _zz_register(int fd)
if(fd < 0 || fd > 65535 || (fd < maxfd && fds[fd] != -1))
return;
#if defined LIBZZUF
if(autoinc)
debug2("using seed %li", (long int)seed);
#endif
/* If filedescriptor is outside our bounds */
while(fd >= maxfd)
@@ -375,7 +379,9 @@ void _zz_setfuzzed(int fd, int count)
&& count <= files[fds[fd]].already_fuzzed)
return;
#if defined LIBZZUF
debug2("setfuzzed(%i, %i)", fd, count);
#endif
files[fds[fd]].already_pos = files[fds[fd]].pos;
files[fds[fd]].already_fuzzed = count;
View File
+6 -2
View File
@@ -27,12 +27,14 @@
#include <stdlib.h>
#include <string.h>
#include "libzzuf.h"
#include "debug.h"
#include "common.h"
#include "random.h"
#include "fuzz.h"
#include "fd.h"
#include "ranges.h"
#if defined LIBZZUF
# include "debug.h"
#endif
#define MAGIC1 0x33ea84f7
#define MAGIC2 0x783bc31f
@@ -91,7 +93,9 @@ void _zz_fuzz(int fd, volatile uint8_t *buf, int64_t len)
int64_t i, j;
int todo;
#if defined LIBZZUF
debug2("fuzz(%i, @%lli, %lli)", fd, (long long int)pos, (long long int)len);
#endif
aligned_buf = buf - pos;
fuzz = _zz_getfuzz(fd);
View File
+1 -1
View File
@@ -26,7 +26,7 @@
#include <stdlib.h>
#include <string.h>
#include "libzzuf.h"
#include "common.h"
#include "ranges.h"
/* This function converts a string containing a list of ranges in the format
View File
View File
@@ -54,6 +54,7 @@
# include <unistd.h> /* Needed for __srefills lseek() call */
#endif
#include "common.h"
#include "libzzuf.h"
#include "lib-load.h"
#include "debug.h"
+31
View File
@@ -0,0 +1,31 @@
/*
* zzuf - general purpose fuzzer
* Copyright (c) 2006-2009 Sam Hocevar <sam@hocevar.net>
* All Rights Reserved
*
* $Id$
*
* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/
/*
* libzzuf.h: preloaded wrapper library
*/
/* Internal variables */
extern int _zz_ready;
extern int _zz_disabled;
extern int _zz_debuglevel;
extern int _zz_debugfd;
extern int _zz_signal;
extern int _zz_memory;
extern int _zz_network;
extern int _zz_autoinc;
/* This function is needed to initialise memory functions */
extern void _zz_mem_init(void);
View File
View File
+1 -1
View File
@@ -28,7 +28,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "libzzuf.h"
#include "common.h"
#include "opts.h"
void _zz_opts_init(struct opts *opts)
+2 -2
View File
@@ -64,7 +64,7 @@
# include <sys/resource.h>
#endif
#include "libzzuf.h"
#include "common.h"
#include "opts.h"
#include "random.h"
#include "fd.h"
@@ -1256,7 +1256,7 @@ static intptr_t get_entry_point_offset(char const *name)
nt = (PIMAGE_NT_HEADERS)((char *)base + dos->e_lfanew);
if(dos->e_magic == IMAGE_DOS_SIGNATURE /* 0x5A4D */
&& nt->Signature == IMAGE_NT_SIGNATURE /* 0x00004550 */
&& nt->FileHeader.Machine == IMAGE_FILE_MACHINE_I386
&& nt->FileHeader.Machine == IMAGE_FILE_MACHINE_I386
&& nt->OptionalHeader.Magic == 0x10b /* IMAGE_NT_OPTIONAL_HDR32_MAGIC */)
{
ret = (intptr_t)nt->OptionalHeader.AddressOfEntryPoint;