summary refs log tree commit diff
path: root/pkgs/ghidra/default.nix
blob: 9c6f2d63542da5720be2385edd2650a56f8d73e7 (plain)
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
{
  lib,
  ghidra,
  openjdk21,
  nixpkgs,
  makeWrapper,
  runCommand,
  callPackage,
  ...
}:

let
  ghidra-copy = let
    copy = runCommand "ghidra-patched" {
      nativeBuildInputs = [ makeWrapper ];
    } ''
      mkdir -p $out $out/lib/ghidra/support

      # dont let `cp` overwrite this later
      ln -s \
        $out/lib/ghidra/support/.launch.sh-wrapped \
        $out/lib/ghidra/support/launch.sh

      patch \
        ${ghidra}/lib/ghidra/support/launch.properties \
        -i ${./ui-scale.patch} \
        -o $out/lib/ghidra/support/launch.properties

      cp --update=none -r ${ghidra}/bin ${ghidra}/lib ${ghidra}/share $out/

      # the original has references to the old ghidra package
      wrapProgram "$out/lib/ghidra/support/.launch.sh-wrapped" \
        --set-default NIX_GHIDRAHOME "$out/lib/ghidra/Ghidra" \
        --prefix PATH : ${lib.makeBinPath [ openjdk21 ]}
    '';
  in
  copy
  // { inherit (ghidra) pname version meta releaseName distroPrefix; };

  members =
    let
      # a bit spooky, no? :3
      nixGhidraPath = "${nixpkgs}/pkgs/tools/security/ghidra";

      buildExtensionAndScripts = callPackage "${nixGhidraPath}/build-extension.nix" {
        ghidra = ghidra-patched;
      };

      withExtensions = callPackage "${nixGhidraPath}/with-extensions.nix" {
        ghidra = ghidra-patched;
      };

      extensions = callPackage "${nixGhidraPath}/extensions.nix" {
        inherit ghidra;
      };
    in
    {
      inherit withExtensions extensions;
      inherit (buildExtensionAndScripts) buildExtension buildGhidraScripts;
    };

    ghidra-patched = ghidra-copy // members;
in
ghidra-patched.withExtensions (
  # extensions passed by function are not built correctly,
  # use extensions build with "normal" ghidra.
  extensions: with members.extensions; [
    gnudisassembler
    machinelearning
    # swift 5.10.2 currently fails build on nixos 25.11
    # see: https://github.com/nixos/nixpkgs/issues/462451
    #ghidraninja-ghidra-scripts
    wasm
    lightkeeper
    kaiju
    ret-sync
    ghidra-delinker-extension
    ghidra-golanganalyzerextension
  ]
)