1{ lib
2, stdenv
3, fetchFromGitHub
4, buildPackages
5, pkg-config
6, libusb-compat-0_1
7, readline
8, libewf
9, perl
10, zlib
11, openssl
12, libuv
13, file
14, libzip
15, xxHash
16, gtk2
17, vte
18, gtkdialog
19, python3
20, ruby
21, lua
22, capstone
23, useX11 ? false
24, rubyBindings ? false
25, pythonBindings ? false
26, luaBindings ? false
27}:
28
29let
30 # FIXME: Compare revision with https://github.com/radareorg/radare2/blob/master/libr/asm/arch/arm/v35arm64/Makefile#L20
31 arm64 = fetchFromGitHub {
32 owner = "radareorg";
33 repo = "vector35-arch-arm64";
34 rev = "3c5eaba46dab72ecb7d5f5b865a13fdeee95b464";
35 sha256 = "sha256-alcGEi+D8CptXzfznnuxQKCvU2mbzn2sQge5jSqLVpg=";
36 };
37in
38stdenv.mkDerivation rec {
39 pname = "radare2";
40 version = "5.4.2";
41
42 src = fetchFromGitHub {
43 owner = "radare";
44 repo = "radare2";
45 rev = version;
46 sha256 = "sha256-5GvJ7J+pAL8GIZ4Tv09wdGyihfMm1bUABhmf7ozQoxc=";
47 };
48
49 preBuild = ''
50 cp -r ${arm64} libr/asm/arch/arm/v35arm64/arch-arm64
51 chmod -R +w libr/asm/arch/arm/v35arm64/arch-arm64
52 '';
53
54 postFixup = lib.optionalString stdenv.isDarwin ''
55 for file in $out/bin/rasm2 $out/bin/ragg2 $out/bin/rabin2 $out/lib/libr_asm.${version}.dylib; do
56 install_name_tool -change libcapstone.4.dylib ${capstone}/lib/libcapstone.4.dylib $file
57 done
58 '';
59
60 postInstall = ''
61 install -D -m755 $src/binr/r2pm/r2pm $out/bin/r2pm
62 '';
63
64 WITHOUT_PULL = "1";
65 makeFlags = [
66 "GITTAP=${version}"
67 "RANLIB=${stdenv.cc.bintools.bintools}/bin/${stdenv.cc.bintools.targetPrefix}ranlib"
68 "CC=${stdenv.cc.targetPrefix}cc"
69 "HOST_CC=${stdenv.cc.targetPrefix}cc"
70 ];
71
72 configureFlags = [
73 "--with-sysmagic"
74 "--with-syszip"
75 "--with-sysxxhash"
76 "--with-syscapstone"
77 "--with-openssl"
78 ];
79
80 enableParallelBuilding = true;
81 depsBuildBuild = [ buildPackages.stdenv.cc ];
82
83 nativeBuildInputs = [ pkg-config ];
84 buildInputs = [
85 capstone
86 file
87 readline
88 libusb-compat-0_1
89 libewf
90 perl
91 zlib
92 openssl
93 libuv
94 ] ++ lib.optional useX11 [ gtkdialog vte gtk2 ]
95 ++ lib.optional rubyBindings [ ruby ]
96 ++ lib.optional pythonBindings [ python3 ]
97 ++ lib.optional luaBindings [ lua ];
98
99 propagatedBuildInputs = [
100 # radare2 exposes r_lib which depends on these libraries
101 file # for its list of magic numbers (`libmagic`)
102 libzip
103 xxHash
104 ];
105
106 meta = with lib; {
107 description = "unix-like reverse engineering framework and commandline tools";
108 homepage = "https://radare.org/";
109 license = licenses.gpl2Plus;
110 maintainers = with maintainers; [ raskin makefu mic92 arkivm ];
111 platforms = platforms.unix;
112 };
113}