{ stdenv, stdenvNoCC, fetchFromGitHub, callPackage, makeWrapper , clang, llvm, gcc, which, libcgroup, python, perl, gmp , file, wine ? null, fetchpatch }: # wine fuzzing is only known to work for win32 binaries, and using a mixture of # 32 and 64-bit libraries ... complicates things, so it's recommended to build # a full 32bit version of this package if you want to do wine fuzzing assert (wine != null) -> (stdenv.targetPlatform.system == "i686-linux"); let aflplusplus-qemu = callPackage ./qemu.nix { inherit aflplusplus; }; qemu-exe-name = if stdenv.targetPlatform.system == "x86_64-linux" then "qemu-x86_64" else if stdenv.targetPlatform.system == "i686-linux" then "qemu-i386" else throw "aflplusplus: no support for ${stdenv.targetPlatform.system}!"; libdislocator = callPackage ./libdislocator.nix { inherit aflplusplus; }; libtokencap = callPackage ./libtokencap.nix { inherit aflplusplus; }; aflplusplus = stdenvNoCC.mkDerivation rec { pname = "aflplusplus"; version = "2.65c"; src = fetchFromGitHub { owner = "AFLplusplus"; repo = "AFLplusplus"; rev = version; sha256 = "1np2a3kypb2m8nyv6qnij18yzn41pl8619jzydci40br4vxial9l"; }; enableParallelBuilding = true; # Note: libcgroup isn't needed for building, just for the afl-cgroup # script. nativeBuildInputs = [ makeWrapper which clang gcc ]; buildInputs = [ llvm python gmp ] ++ stdenv.lib.optional (wine != null) python.pkgs.wrapPython; postPatch = '' # Replace the CLANG_BIN variables with the correct path substituteInPlace llvm_mode/afl-clang-fast.c \ --replace "CLANGPP_BIN" '"${clang}/bin/clang++"' \ --replace "CLANG_BIN" '"${clang}/bin/clang"' \ --replace 'getenv("AFL_PATH")' "(getenv(\"AFL_PATH\") ? getenv(\"AFL_PATH\") : \"$out/lib/afl\")" # Replace "gcc" and friends with full paths in afl-gcc # Prevents afl-gcc picking up any (possibly incorrect) gcc from the path substituteInPlace src/afl-gcc.c \ --replace '"gcc"' '"${gcc}/bin/gcc"' \ --replace '"g++"' '"${gcc}/bin/g++"' \ --replace '"gcj"' '"gcj-UNSUPPORTED"' \ --replace '"clang"' '"clang-UNSUPPORTED"' \ --replace '"clang++"' '"clang++-UNSUPPORTED"' ''; makeFlags = [ "PREFIX=$(out)" ]; buildPhase = '' common="$makeFlags -j$NIX_BUILD_CORES" make all $common make radamsa $common make -C gcc_plugin CC=${gcc}/bin/gcc CXX=${gcc}/bin/g++ $common make -C llvm_mode $common make -C qemu_mode/libcompcov $common make -C qemu_mode/unsigaction $common ''; postInstall = '' # remove afl-clang(++) which are just symlinks to afl-clang-fast rm $out/bin/afl-clang $out/bin/afl-clang++ # the makefile neglects to install unsigaction cp qemu_mode/unsigaction/unsigaction*.so $out/lib/afl/ # Install the custom QEMU emulator for binary blob fuzzing. cp ${aflplusplus-qemu}/bin/${qemu-exe-name} $out/bin/afl-qemu-trace # give user a convenient way of accessing libcompconv.so, libdislocator.so, libtokencap.so cat > $out/bin/get-afl-qemu-libcompcov-so <