1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 buildPackages,
6 capstone,
7 file,
8 gtk2,
9 gtkdialog,
10 libewf,
11 libusb-compat-0_1,
12 libuv,
13 libzip,
14 lua,
15 lz4,
16 meson,
17 ninja,
18 openssl,
19 perl,
20 pkg-config,
21 python3,
22 readline,
23 ruby,
24 vte,
25 xxHash,
26 zlib,
27 useX11 ? false,
28 rubyBindings ? false,
29 luaBindings ? false,
30}:
31let
32 binaryninja = fetchFromGitHub {
33 owner = "Vector35";
34 repo = "binaryninja-api";
35 rev = "c40a5f04deec68d388b2072dc42b29141089f9ce"; # https://github.com/radareorg/radare2/blob/master/subprojects/binaryninja.wrap
36 hash = "sha256-IfuGgwVI51urQxhaYkYsE45NkScgxKmmEBV6Pllhwmo=";
37 };
38
39 sdb = fetchFromGitHub {
40 owner = "radare";
41 repo = "sdb";
42 tag = "2.2.0"; # https://github.com/radareorg/radare2/blob/master/subprojects/sdb.wrap
43 hash = "sha256-S/aL3F6+Z/rqelfIJaZaBF1IxSmhA1qE9ahFvKARoaE=";
44 };
45
46 qjs = fetchFromGitHub {
47 owner = "quickjs-ng";
48 repo = "quickjs";
49 rev = "7238ee64dbc2fbdea044555cda8cda78785a93ed"; # https://github.com/radareorg/radare2/blob/master/subprojects/qjs.wrap
50 hash = "sha256-1ZeLCTmbrlRrZB9El3L497gt3QUA5GIScrFVIBkxA88=";
51 };
52in
53stdenv.mkDerivation (finalAttrs: {
54 pname = "radare2";
55 version = "6.0.2";
56
57 src = fetchFromGitHub {
58 owner = "radare";
59 repo = "radare2";
60 tag = finalAttrs.version;
61 hash = "sha256-uCMf+pNqyjRLeNJlE8Kk6PQCIRBjidO/XGHeNV/F1lA=";
62 };
63
64 mesonFlags = [
65 (lib.mesonOption "use_sys_capstone" "true")
66 (lib.mesonOption "use_sys_lz4" "true")
67 (lib.mesonOption "use_sys_magic" "true")
68 (lib.mesonOption "use_sys_openssl" "true")
69 (lib.mesonOption "use_sys_xxhash" "true")
70 (lib.mesonOption "use_sys_zip" "true")
71 (lib.mesonOption "use_sys_zlib" "true")
72 (lib.mesonOption "r2_gittap" finalAttrs.version)
73 ];
74
75 enableParallelBuilding = true;
76
77 depsBuildBuild = [ buildPackages.stdenv.cc ];
78
79 strictDeps = true;
80
81 nativeBuildInputs = [
82 pkg-config
83 meson
84 ninja
85 python3
86 ];
87
88 buildInputs = [
89 capstone
90 file
91 libewf
92 libusb-compat-0_1
93 libuv
94 lz4
95 openssl
96 perl
97 readline
98 zlib
99 ]
100 ++ lib.optionals useX11 [
101 gtkdialog
102 vte
103 gtk2
104 ]
105 ++ lib.optionals rubyBindings [ ruby ]
106 ++ lib.optionals luaBindings [ lua ];
107
108 propagatedBuildInputs = [
109 # radare2 exposes r_lib which depends on these libraries
110 file # for its list of magic numbers (`libmagic`)
111 libzip
112 xxHash
113 ];
114
115 postUnpack = ''
116 pushd $sourceRoot/subprojects
117
118 cp -r ${binaryninja} binaryninja
119 chmod -R +w binaryninja
120 cp packagefiles/binaryninja/meson.build binaryninja
121
122 cp -r ${sdb} sdb
123 chmod -R +w sdb
124
125 cp -r ${qjs} qjs
126 chmod -R +w qjs
127 cp packagefiles/qjs/meson.build qjs
128
129 popd
130 '';
131
132 postFixup = lib.optionalString stdenv.hostPlatform.isDarwin ''
133 install_name_tool -add_rpath $out/lib $out/lib/libr_io.${finalAttrs.version}.dylib
134 '';
135
136 meta = {
137 description = "UNIX-like reverse engineering framework and command-line toolset";
138 longDescription = ''
139 r2 is a complete rewrite of radare. It provides a set of libraries, tools
140 and plugins to ease reverse engineering tasks. Distributed mostly under
141 LGPLv3, each plugin can have different licenses.
142
143 The radare project started as a simple command-line hexadecimal editor
144 focused on forensics. Today, r2 is a featureful low-level command-line
145 tool with support for scripting with the embedded JavaScript interpreter
146 or via r2pipe.
147
148 r2 can edit files on local hard drives, view kernel memory, and debug
149 programs locally or via a remote gdb/windbg servers. r2's wide
150 architecture support allows you to analyze, emulate, debug, modify, and
151 disassemble any binary.
152 '';
153 homepage = "https://radare.org";
154 changelog = "https://github.com/radareorg/radare2/releases/tag/${finalAttrs.version}";
155 license = with lib.licenses; [
156 gpl3Only
157 lgpl3Only
158 ];
159 maintainers = with lib.maintainers; [
160 arkivm
161 azahi
162 makefu
163 mic92
164 raskin
165 ];
166 mainProgram = "radare2";
167 platforms = lib.platforms.unix;
168 };
169})