1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 fetchurl,
6 ocaml,
7 findlib,
8 ocamlbuild,
9 ocaml_oasis,
10 bitstring,
11 camlzip,
12 cmdliner,
13 core_kernel,
14 ezjsonm,
15 fileutils,
16 jane_rope ? null,
17 mmap,
18 lwt,
19 ocamlgraph,
20 ocurl,
21 re,
22 uri,
23 zarith,
24 piqi,
25 piqi-ocaml,
26 uuidm,
27 llvm,
28 frontc,
29 ounit,
30 ppx_jane,
31 parsexp ? null,
32 utop,
33 libxml2,
34 ncurses,
35 linenoise,
36 ppx_bap,
37 ppx_bitstring,
38 yojson,
39 which,
40 makeWrapper,
41 writeText,
42 z3,
43}:
44
45if lib.versionOlder ocaml.version "4.08" then
46 throw "BAP is not available for OCaml ${ocaml.version}"
47else
48
49 stdenv.mkDerivation rec {
50 pname = "ocaml${ocaml.version}-bap";
51 version = "2.5.0+pr1621";
52 src = fetchFromGitHub {
53 owner = "BinaryAnalysisPlatform";
54 repo = "bap";
55 rev = "65c282d94e8b7028e8a986c637db3a2378a753f6";
56 hash = "sha256-LUZZOgG1T8xa5jLA/fDft8ofYb/Yf6QjTrl6AlLY7H0=";
57 };
58
59 sigs = fetchurl {
60 url = "https://github.com/BinaryAnalysisPlatform/bap/releases/download/v${version}/sigs.zip";
61 sha256 = "0d69jd28z4g64mglq94kj5imhmk5f6sgcsh9q2nij3b0arpcliwk";
62 };
63
64 createFindlibDestdir = true;
65
66 setupHook = writeText "setupHook.sh" ''
67 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}/"
68 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/"
69 '';
70
71 nativeBuildInputs = [
72 which
73 makeWrapper
74 ocaml
75 findlib
76 ocamlbuild
77 ocaml_oasis
78 ];
79
80 buildInputs = [
81 ocamlbuild
82 linenoise
83 ounit
84 ppx_bitstring
85 z3
86 utop
87 libxml2
88 ncurses
89 ];
90
91 propagatedBuildInputs = [
92 bitstring
93 camlzip
94 cmdliner
95 ppx_bap
96 core_kernel
97 ezjsonm
98 fileutils
99 jane_rope
100 mmap
101 lwt
102 ocamlgraph
103 ocurl
104 re
105 uri
106 zarith
107 piqi
108 parsexp
109 piqi-ocaml
110 uuidm
111 frontc
112 yojson
113 ];
114
115 installPhase = ''
116 runHook preInstall
117 export OCAMLPATH=$OCAMLPATH:$OCAMLFIND_DESTDIR;
118 export PATH=$PATH:$out/bin
119 export CAML_LD_LIBRARY_PATH=''${CAML_LD_LIBRARY_PATH-}''${CAML_LD_LIBRARY_PATH:+:}$OCAMLFIND_DESTDIR/bap-plugin-llvm/:$OCAMLFIND_DESTDIR/bap/
120 mkdir -p $out/lib/bap
121 make install
122 rm $out/bin/baptop
123 makeWrapper ${utop}/bin/utop $out/bin/baptop --prefix OCAMLPATH : $OCAMLPATH --prefix PATH : $PATH --add-flags "-ppx ppx-bap -short-paths -require \"bap.top\""
124 wrapProgram $out/bin/bapbuild --prefix OCAMLPATH : $OCAMLPATH --prefix PATH : $PATH
125 ln -s $sigs $out/share/bap/sigs.zip
126 runHook postInstall
127 '';
128
129 disableIda = "--disable-ida";
130 disableGhidra = "--disable-ghidra";
131
132 patches = [
133 ./curses_is_ncurses.patch
134 ];
135
136 preConfigure = ''
137 substituteInPlace oasis/monads --replace-warn core_kernel.rope jane_rope
138 '';
139
140 configureFlags = [
141 "--enable-everything ${disableIda} ${disableGhidra}"
142 "--with-llvm-config=${llvm.dev}/bin/llvm-config"
143 ];
144
145 meta = with lib; {
146 description = "Platform for binary analysis. It is written in OCaml, but can be used from other languages";
147 homepage = "https://github.com/BinaryAnalysisPlatform/bap/";
148 license = licenses.mit;
149 maintainers = [ maintainers.maurer ];
150 mainProgram = "bap";
151 };
152 }