about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/tools/analysis/rizin/default.nix
blob: 9f8524e68995f461957f9bc9d56e7f57d8be2073 (plain) (blame)
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
{ lib
, pkgs # for passthru.plugins
, stdenv
, fetchpatch
, fetchurl
, pkg-config
, libusb-compat-0_1
, readline
, libewf
, perl
, zlib
, openssl
, file
, libmspack
, libzip
, lz4
, xxHash
, xz
, meson
, python3
, cmake
, ninja
, capstone
, tree-sitter
}:

let rizin = stdenv.mkDerivation rec {
  pname = "rizin";
  version = "0.6.3";

  src = fetchurl {
    url = "https://github.com/rizinorg/rizin/releases/download/v${version}/rizin-src-v${version}.tar.xz";
    hash = "sha256-lfZMarnm2qnp+lY0OY649s206/LoFNouTLlp0x9FCcI=";
  };

  mesonFlags = [
    "-Duse_sys_capstone=enabled"
    "-Duse_sys_magic=enabled"
    "-Duse_sys_libzip=enabled"
    "-Duse_sys_zlib=enabled"
    "-Duse_sys_lz4=enabled"
    "-Duse_sys_lzma=enabled"
    "-Duse_sys_xxhash=enabled"
    "-Duse_sys_openssl=enabled"
    "-Duse_sys_libmspack=enabled"
    "-Duse_sys_tree_sitter=enabled"
    # this is needed for wrapping (adding plugins) to work
    "-Dportable=true"
  ];

  patches = [
    # Normally, Rizin only looks for files in the install prefix. With
    # portable=true, it instead looks for files in relation to the parent
    # of the directory of the binary file specified in /proc/self/exe,
    # caching it. This patch replaces the entire logic to only look at
    # the env var NIX_RZ_PREFIX
    ./librz-wrapper-support.patch
    # Fix tree-sitter 0.20.9 build failure: https://github.com/rizinorg/rizin/pull/4165
    (fetchpatch {
      name = "tree-sitter-0.20.9.patch";
      url = "https://github.com/rizinorg/rizin/commit/1bb08712dbc9e062bb439a65dcebeb4221ded699.patch";
      hash = "sha256-mE0eQAFhyxX5bwrz+S1IVl6HNV9ITQ+tRRvGLLif5VI=";
    })
  ];


  nativeBuildInputs = [
    pkg-config
    meson
    (python3.withPackages (pp: with pp; [
      pyyaml
    ]))
    ninja
    cmake
  ];

  # meson's find_library seems to not use our compiler wrapper if static parameter
  # is either true/false... We work around by also providing LIBRARY_PATH
  preConfigure = ''
    LIBRARY_PATH=""
    for b in ${toString (map lib.getLib buildInputs)}; do
      if [[ -d "$b/lib" ]]; then
        LIBRARY_PATH="$b/lib''${LIBRARY_PATH:+:}$LIBRARY_PATH"
      fi
    done
    export LIBRARY_PATH
  '' + lib.optionalString stdenv.isDarwin ''
    substituteInPlace binrz/rizin/macos_sign.sh \
      --replace 'codesign' '# codesign'
  '';

  buildInputs = [
    file
    libzip
    capstone
    readline
    libusb-compat-0_1
    libewf
    perl
    zlib
    lz4
    openssl
    libmspack
    tree-sitter
    xxHash
    xz
  ];

  postPatch = ''
    # find_installation without arguments uses Meson’s Python interpreter,
    # which does not have any extra modules.
    # https://github.com/mesonbuild/meson/pull/9904
    substituteInPlace meson.build \
      --replace "import('python').find_installation()" "find_program('python3')"
  '';

  passthru = rec {
    plugins = {
      jsdec = pkgs.callPackage ./jsdec.nix {
        inherit rizin openssl;
      };
      rz-ghidra = pkgs.qt6.callPackage ./rz-ghidra.nix {
        inherit rizin openssl;
        enableCutterPlugin = false;
      };
      # sigdb isn't a real plugin, but it's separated from the main rizin
      # derivation so that only those who need it will download it
      sigdb = pkgs.callPackage ./sigdb.nix { };
    };
    withPlugins = filter: pkgs.callPackage ./wrapper.nix {
      inherit rizin;
      plugins = filter plugins;
    };
  };

  meta = {
    description = "UNIX-like reverse engineering framework and command-line toolset.";
    homepage = "https://rizin.re/";
    license = lib.licenses.gpl3Plus;
    mainProgram = "rizin";
    maintainers = with lib.maintainers; [ raskin makefu mic92 ];
    platforms = with lib.platforms; unix;
  };
}; in rizin