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