2021-01-11 07:54:33 +00:00
|
|
|
{ lib, stdenv, fetchFromGitHub, fetchurl
|
2021-01-08 22:18:14 +00:00
|
|
|
, ocaml, findlib, ocamlbuild, ocaml_oasis
|
|
|
|
, 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, ncurses
|
2021-02-22 07:57:51 +00:00
|
|
|
, linenoise
|
|
|
|
, ppx_bap
|
2021-01-08 22:18:14 +00:00
|
|
|
, ppx_bitstring
|
2021-02-22 07:57:51 +00:00
|
|
|
, yojson
|
2021-01-08 22:18:14 +00:00
|
|
|
, which, makeWrapper, writeText
|
2020-10-02 05:44:56 +00:00
|
|
|
, z3
|
2018-06-24 12:59:48 +00:00
|
|
|
}:
|
2017-01-25 07:08:03 +00:00
|
|
|
|
2022-04-25 20:35:24 +00:00
|
|
|
if lib.versionOlder ocaml.version "4.08"
|
2020-10-02 05:44:56 +00:00
|
|
|
then throw "BAP is not available for OCaml ${ocaml.version}"
|
|
|
|
else
|
|
|
|
|
2018-06-24 12:59:48 +00:00
|
|
|
stdenv.mkDerivation rec {
|
2022-02-10 00:28:00 +00:00
|
|
|
pname = "ocaml${ocaml.version}-bap";
|
2022-04-06 23:46:57 +00:00
|
|
|
version = "2.4.0";
|
2017-01-25 07:08:03 +00:00
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "BinaryAnalysisPlatform";
|
|
|
|
repo = "bap";
|
|
|
|
rev = "v${version}";
|
2022-04-06 23:46:57 +00:00
|
|
|
sha256 = "1xc8zfcwm40zihs3ajcrh2x32xd08qnygay03qy3qxhybr5hqngr";
|
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 06:35:25 +00:00
|
|
|
sha256 = "0d69jd28z4g64mglq94kj5imhmk5f6sgcsh9q2nij3b0arpcliwk";
|
2017-01-25 07:08:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
createFindlibDestdir = true;
|
|
|
|
|
|
|
|
setupHook = writeText "setupHook.sh" ''
|
2022-02-10 00:28:00 +00:00
|
|
|
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}/"
|
|
|
|
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/"
|
2017-01-25 07:08:03 +00:00
|
|
|
'';
|
|
|
|
|
2022-02-22 09:59:04 +00:00
|
|
|
nativeBuildInputs = [ which makeWrapper ocaml findlib ocamlbuild ocaml_oasis ];
|
2017-01-25 07:08:03 +00:00
|
|
|
|
2022-02-22 09:59:04 +00:00
|
|
|
buildInputs = [ linenoise
|
2021-02-22 07:57:51 +00:00
|
|
|
ounit
|
|
|
|
ppx_bitstring
|
2020-10-02 05:44:56 +00:00
|
|
|
z3
|
2021-01-08 22:18:14 +00:00
|
|
|
utop libxml2 ncurses ];
|
2017-01-25 07:08:03 +00:00
|
|
|
|
2021-02-22 07:57:51 +00:00
|
|
|
propagatedBuildInputs = [ bitstring camlzip cmdliner ppx_bap core_kernel ezjsonm fileutils ocaml_lwt ocamlgraph ocurl re uri zarith piqi parsexp
|
|
|
|
piqi-ocaml uuidm frontc yojson ];
|
2017-01-25 07:08:03 +00:00
|
|
|
|
|
|
|
installPhase = ''
|
2022-02-11 08:58:23 +00:00
|
|
|
runHook preInstall
|
2017-01-25 07:08:03 +00:00
|
|
|
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
|
2022-02-11 08:58:23 +00:00
|
|
|
runHook postInstall
|
2017-01-25 07:08:03 +00:00
|
|
|
'';
|
|
|
|
|
2020-04-19 23:56:09 +00:00
|
|
|
disableIda = "--disable-ida";
|
2022-04-06 23:46:57 +00:00
|
|
|
disableGhidra = "--disable-ghidra";
|
2020-04-19 23:56:09 +00:00
|
|
|
|
2021-01-08 22:18:14 +00:00
|
|
|
patches = [ ./curses_is_ncurses.patch ];
|
2017-01-25 07:08:03 +00:00
|
|
|
|
2021-01-03 09:14:22 +00:00
|
|
|
preConfigure = ''
|
2021-02-22 07:57:51 +00:00
|
|
|
substituteInPlace oasis/elf-loader --replace bitstring.ppx ppx_bitstring
|
2021-01-03 09:14:22 +00:00
|
|
|
'';
|
|
|
|
|
2022-04-06 23:46:57 +00:00
|
|
|
configureFlags = [ "--enable-everything ${disableIda} ${disableGhidra}" "--with-llvm-config=${llvm.dev}/bin/llvm-config" ];
|
2017-01-25 07:08:03 +00:00
|
|
|
|
2021-01-11 07:54:33 +00:00
|
|
|
meta = with lib; {
|
2017-01-25 07:08:03 +00:00
|
|
|
description = "Platform for binary analysis. It is written in OCaml, but can be used from other languages.";
|
2020-04-01 01:11:51 +00:00
|
|
|
homepage = "https://github.com/BinaryAnalysisPlatform/bap/";
|
2017-01-25 07:08:03 +00:00
|
|
|
maintainers = [ maintainers.maurer ];
|
|
|
|
license = licenses.mit;
|
|
|
|
};
|
|
|
|
}
|