-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·60 lines (50 loc) · 2.06 KB
/
setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/sh
die() { echo "Error: $1"; exit 100; }
build_afl() {
echo 'Building AFL'
which $CC | grep -q clang || which clang >/dev/null || die "requires clang";
which $CXX | grep -q clang || which clang++ >/dev/null || die "requires clang++";
which wget >/dev/null || die "requires wget";
which tar >/dev/null || die "requires tar";
llvm-config --version >/dev/null || die "requires llvm development version";
cd afl;
[ -f afl-latest.tgz ] || wget http://lcamtuf.coredump.cx/afl/releases/afl-latest.tgz || die "wget failed";
[ -f ./afl-*/afl-fuzz.c ] || tar -zxvf afl-latest.tgz || die "tar -zxvf afl-latest.tgz failed";
cd afl-* || die "cd afl-*";
if ! test -f ./PATCHED ; then
echo 'Applying patch to afl'
ls ../*.patch | while read x; do
echo "Applying $x"
patch -p2 < $x || die "failed patch";
done || die "could not patch";
echo '' > ./PATCHED
fi
export AFL_DIR=`pwd`;
[ -f ./afl-fuzz ] || AFL_NO_X86=1 make || die "failed to compile afl";
cd llvm_mode || die "cd llvm_mode";
[ -f ../afl-clang-fast ] && echo 'afl clang fast found';
if ! test -f ../afl-clang-fast -a -f ./test-insn; then
rm ../afl-clang-fast 2>/dev/null
make SHELL='sh -x' || die "failed to compile afl-clang-fast"
fi
cd ../../../ || die "cd ../../../";
export AFL_CLANG_FAST=$AFL_DIR/afl-clang-fast;
return 0;
}
use_system_afl() {
export AFL_CLANG_FAST=`which afl-clang-fast`;
return 0;
}
which git >/dev/null || die "requires git";
which make >/dev/null || die "requires make";
if which afl-clang-fast >/dev/null 2>/dev/null && which afl-fuzz >/dev/null 2>/dev/null; then
use_system_afl;
else
build_afl;
fi
[ -d cjdns ] || git clone git://github.com/cjdelisle/cjdns.git || die "failed to clone cjdns";
cd cjdns || die "cd cjdns";
git checkout crashey || die "checkout crashey";
./do || die "Failed to compile cjdns without afl";
CC=$AFL_CLANG_FAST ./do || die "Failed to compile cjdns with afl";
echo "Cjdns compiled for AFL, run fuzz.sh to begin fuzzing";