1#!/bin/bash -eu
2# Copyright 2018 Google Inc.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16################################################################################
17
18#add next branch
19for branch in v4 next
20do
21    cd capstone$branch
22    # build project
23    mkdir build
24    # does not seem to work in source directory
25    # + make.sh overwrites CFLAGS
26    cd build
27    cmake -DCAPSTONE_BUILD_SHARED=0 ..
28    make
29
30    cd $SRC/capstone$branch/bindings/python
31    #better debug info
32    sed -i -e 's/#print/print/' capstone/__init__.py
33    (
34    export CFLAGS=""
35    export AFL_NOOPT=1
36    python setup.py install
37    )
38    cd $SRC/capstone$branch/suite
39    mkdir fuzz/corpus
40    find MC/ -name *.cs | ./test_corpus.py
41    cd fuzz
42    zip -r fuzz_disasm"$branch"_seed_corpus.zip corpus/
43    cp fuzz_disasm"$branch"_seed_corpus.zip $OUT/
44
45    # export other associated stuff
46    cp fuzz_disasm.options $OUT/fuzz_disasm$branch.options
47
48    cd ../../build
49    # build fuzz target
50    FUZZO=CMakeFiles/fuzz_disasm.dir/suite/fuzz/fuzz_disasm.c.o
51    if [ -f CMakeFiles/fuzz_disasm.dir/suite/fuzz/platform.c.o ]; then
52        FUZZO="$FUZZO CMakeFiles/fuzz_disasm.dir/suite/fuzz/platform.c.o"
53    fi
54    $CXX $CXXFLAGS $FUZZO -o $OUT/fuzz_disasm$branch libcapstone.a $LIB_FUZZING_ENGINE
55
56    cd ../../
57done
58