2019-06-16 20:59:06 +01:00
|
|
|
{ stdenv, fetchFromGitHub, fetchurl
|
2018-06-24 13:59:48 +01:00
|
|
|
, ocaml, findlib, ocamlbuild, ocaml_oasis,
|
2019-09-03 20:26:27 +01:00
|
|
|
bitstring, camlzip, cmdliner, core_kernel, ezjsonm, fileutils, ocaml_lwt, ocamlgraph, ocurl, re, uri, zarith, piqi, piqi-ocaml, uuidm, llvm, frontc, ounit, ppx_jane, parsexp,
|
|
|
|
utop, libxml2,
|
2019-04-28 07:35:25 +01:00
|
|
|
ppx_tools_versioned,
|
2018-06-24 13:59:48 +01:00
|
|
|
which, makeWrapper, writeText
|
|
|
|
}:
|
2017-01-25 07:08:03 +00:00
|
|
|
|
2019-09-03 20:35:45 +01:00
|
|
|
if stdenv.lib.versionAtLeast core_kernel.version "0.12"
|
|
|
|
then throw "BAP needs core_kernel-0.11 (hence OCaml ≤ 4.06)"
|
|
|
|
else
|
|
|
|
|
2018-06-24 13:59:48 +01:00
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
name = "ocaml${ocaml.version}-bap-${version}";
|
2019-04-28 07:35:25 +01:00
|
|
|
version = "1.6.0";
|
2017-01-25 07:08:03 +00:00
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "BinaryAnalysisPlatform";
|
|
|
|
repo = "bap";
|
|
|
|
rev = "v${version}";
|
2019-04-28 07:35:25 +01:00
|
|
|
sha256 = "0ryf2xb37pj2f9mc3p5prqgqrylph9qgq7q9jnbx8b03nzzpa6h6";
|
2017-01-25 07:08:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
sigs = fetchurl {
|
|
|
|
url = "https://github.com/BinaryAnalysisPlatform/bap/releases/download/v${version}/sigs.zip";
|
2019-04-28 07:35:25 +01:00
|
|
|
sha256 = "0d69jd28z4g64mglq94kj5imhmk5f6sgcsh9q2nij3b0arpcliwk";
|
2017-01-25 07:08:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
createFindlibDestdir = true;
|
|
|
|
|
|
|
|
setupHook = writeText "setupHook.sh" ''
|
2019-11-14 18:44:07 +00:00
|
|
|
export CAML_LD_LIBRARY_PATH="''${CAML_LD_LIBRARY_PATH-}''${CAML_LD_LIBRARY_PATH:+:}''$1/lib/ocaml/${ocaml.version}/site-lib/${name}/"
|
|
|
|
export CAML_LD_LIBRARY_PATH="''${CAML_LD_LIBRARY_PATH-}''${CAML_LD_LIBRARY_PATH:+:}''$1/lib/ocaml/${ocaml.version}/site-lib/${name}-llvm-plugins/"
|
2017-01-25 07:08:03 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
nativeBuildInputs = [ which makeWrapper ];
|
|
|
|
|
2018-06-24 13:59:48 +01:00
|
|
|
buildInputs = [ ocaml findlib ocamlbuild ocaml_oasis
|
2019-09-03 20:26:27 +01:00
|
|
|
llvm ppx_tools_versioned
|
|
|
|
utop libxml2 ];
|
2017-01-25 07:08:03 +00:00
|
|
|
|
2019-04-28 07:35:25 +01:00
|
|
|
propagatedBuildInputs = [ bitstring camlzip cmdliner ppx_jane core_kernel ezjsonm fileutils ocaml_lwt ocamlgraph ocurl re uri zarith piqi parsexp
|
2017-01-25 07:08:03 +00:00
|
|
|
piqi-ocaml uuidm frontc ounit ];
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
export OCAMLPATH=$OCAMLPATH:$OCAMLFIND_DESTDIR;
|
|
|
|
export PATH=$PATH:$out/bin
|
2019-11-14 18:44:07 +00:00
|
|
|
export CAML_LD_LIBRARY_PATH=''${CAML_LD_LIBRARY_PATH-}''${CAML_LD_LIBRARY_PATH:+:}$OCAMLFIND_DESTDIR/bap-plugin-llvm/:$OCAMLFIND_DESTDIR/bap/
|
2017-01-25 07:08:03 +00:00
|
|
|
mkdir -p $out/lib/bap
|
|
|
|
make install
|
|
|
|
rm $out/bin/baptop
|
|
|
|
makeWrapper ${utop}/bin/utop $out/bin/baptop --prefix OCAMLPATH : $OCAMLPATH --prefix PATH : $PATH --add-flags "-ppx ppx-bap -short-paths -require \"bap.top\""
|
|
|
|
wrapProgram $out/bin/bapbuild --prefix OCAMLPATH : $OCAMLPATH --prefix PATH : $PATH
|
|
|
|
ln -s $sigs $out/share/bap/sigs.zip
|
|
|
|
'';
|
|
|
|
|
|
|
|
disableIda = "--disable-ida --disable-fsi-benchmark";
|
|
|
|
|
2019-09-03 20:26:27 +01:00
|
|
|
configureFlags = [ "--enable-everything ${disableIda}" "--with-llvm-config=${llvm}/bin/llvm-config" ];
|
2017-01-25 07:08:03 +00:00
|
|
|
|
|
|
|
BAPBUILDFLAGS = "-j $(NIX_BUILD_CORES)";
|
|
|
|
|
|
|
|
meta = with stdenv.lib; {
|
|
|
|
description = "Platform for binary analysis. It is written in OCaml, but can be used from other languages.";
|
|
|
|
homepage = https://github.com/BinaryAnalysisPlatform/bap/;
|
|
|
|
maintainers = [ maintainers.maurer ];
|
|
|
|
license = licenses.mit;
|
|
|
|
};
|
|
|
|
}
|