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