1 { lib, stdenv, fetchFromGitHub, fetchurl, fetchpatch
2 , ocaml, findlib, ocamlbuild, ocaml_oasis
3 , bitstring, camlzip, cmdliner, core_kernel, ezjsonm, fileutils, mmap, lwt, ocamlgraph, ocurl, re, uri, zarith, piqi, piqi-ocaml, uuidm, llvm, frontc, ounit, ppx_jane, parsexp
4 , utop, libxml2, ncurses
9 , which, makeWrapper, writeText
13 if lib.versionOlder ocaml.version "4.08"
14 then throw "BAP is not available for OCaml ${ocaml.version}"
17 stdenv.mkDerivation rec {
18 pname = "ocaml${ocaml.version}-bap";
20 src = fetchFromGitHub {
21 owner = "BinaryAnalysisPlatform";
24 sha256 = "1c30zxn0zyi0wypvjmik3fd6n6a8xjcb102qfnccn1af052bvsrd";
28 url = "https://github.com/BinaryAnalysisPlatform/bap/releases/download/v${version}/sigs.zip";
29 sha256 = "0d69jd28z4g64mglq94kj5imhmk5f6sgcsh9q2nij3b0arpcliwk";
32 createFindlibDestdir = true;
34 setupHook = writeText "setupHook.sh" ''
35 export CAML_LD_LIBRARY_PATH="''${CAML_LD_LIBRARY_PATH-}''${CAML_LD_LIBRARY_PATH:+:}''$1/lib/ocaml/${ocaml.version}/site-lib/ocaml${ocaml.version}-bap-${version}/"
36 export CAML_LD_LIBRARY_PATH="''${CAML_LD_LIBRARY_PATH-}''${CAML_LD_LIBRARY_PATH:+:}''$1/lib/ocaml/${ocaml.version}/site-lib/ocaml${ocaml.version}-bap-${version}-llvm-plugins/"
39 nativeBuildInputs = [ which makeWrapper ocaml findlib ocamlbuild ocaml_oasis ];
41 buildInputs = [ ocamlbuild
46 utop libxml2 ncurses ];
48 propagatedBuildInputs = [ bitstring camlzip cmdliner ppx_bap core_kernel ezjsonm fileutils mmap lwt ocamlgraph ocurl re uri zarith piqi parsexp
49 piqi-ocaml uuidm frontc yojson ];
53 export OCAMLPATH=$OCAMLPATH:$OCAMLFIND_DESTDIR;
54 export PATH=$PATH:$out/bin
55 export CAML_LD_LIBRARY_PATH=''${CAML_LD_LIBRARY_PATH-}''${CAML_LD_LIBRARY_PATH:+:}$OCAMLFIND_DESTDIR/bap-plugin-llvm/:$OCAMLFIND_DESTDIR/bap/
59 makeWrapper ${utop}/bin/utop $out/bin/baptop --prefix OCAMLPATH : $OCAMLPATH --prefix PATH : $PATH --add-flags "-ppx ppx-bap -short-paths -require \"bap.top\""
60 wrapProgram $out/bin/bapbuild --prefix OCAMLPATH : $OCAMLPATH --prefix PATH : $PATH
61 ln -s $sigs $out/share/bap/sigs.zip
65 disableIda = "--disable-ida";
66 disableGhidra = "--disable-ghidra";
69 ./curses_is_ncurses.patch
73 substituteInPlace oasis/elf-loader --replace bitstring.ppx ppx_bitstring
76 configureFlags = [ "--enable-everything ${disableIda} ${disableGhidra}" "--with-llvm-config=${llvm.dev}/bin/llvm-config" ];
79 description = "Platform for binary analysis. It is written in OCaml, but can be used from other languages.";
80 homepage = "https://github.com/BinaryAnalysisPlatform/bap/";
81 license = licenses.mit;
82 maintainers = [ maintainers.maurer ];