nixpkgs/pkgs/tools/security/ghidra/build.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

181 lines
5.2 KiB
Nix
Raw Normal View History

2021-12-24 16:24:29 +00:00
{ stdenv
, fetchFromGitHub
, lib
2023-02-14 12:43:19 +00:00
, gradle_7
2021-12-24 16:24:29 +00:00
, perl
, makeWrapper
2022-11-06 23:31:27 +00:00
, openjdk17
2021-12-24 16:24:29 +00:00
, unzip
, makeDesktopItem
, icoutils
2021-12-27 19:43:56 +00:00
, xcbuild
2023-05-19 19:40:13 +00:00
, protobuf
2021-12-24 16:24:29 +00:00
}:
let
pkg_path = "$out/lib/ghidra";
pname = "ghidra";
2023-07-22 03:52:53 +00:00
version = "10.3.2";
2021-12-24 16:24:29 +00:00
src = fetchFromGitHub {
owner = "NationalSecurityAgency";
repo = "Ghidra";
rev = "Ghidra_${version}_build";
2023-07-22 03:52:53 +00:00
hash = "sha256-CVnEHtSF3DVTH+8qwUsABJq/lRkg6xulEWU+Q5C9ajo=";
2021-12-24 16:24:29 +00:00
};
2023-02-14 12:43:19 +00:00
gradle = gradle_7;
2021-12-24 16:24:29 +00:00
desktopItem = makeDesktopItem {
name = "ghidra";
exec = "ghidra";
icon = "ghidra";
desktopName = "Ghidra";
genericName = "Ghidra Software Reverse Engineering Suite";
categories = [ "Development" ];
2021-12-24 16:24:29 +00:00
};
# postPatch scripts.
# Tells ghidra to use our own protoc binary instead of the prebuilt one.
fixProtoc = ''
cat >>Ghidra/Debug/Debugger-gadp/build.gradle <<HERE
protobuf {
protoc {
2023-05-19 19:40:13 +00:00
path = '${protobuf}/bin/protoc'
}
}
HERE
cat >>Ghidra/Debug/Debugger-isf/build.gradle <<HERE
protobuf {
protoc {
path = '${protobuf}/bin/protoc'
}
}
HERE
'';
2021-12-24 16:24:29 +00:00
# Adds a gradle step that downloads all the dependencies to the gradle cache.
addResolveStep = ''
2021-12-24 16:24:29 +00:00
cat >>build.gradle <<HERE
task resolveDependencies {
doLast {
project.rootProject.allprojects.each { subProject ->
subProject.buildscript.configurations.each { configuration ->
resolveConfiguration(subProject, configuration, "buildscript config \''${configuration.name}")
}
subProject.configurations.each { configuration ->
resolveConfiguration(subProject, configuration, "config \''${configuration.name}")
}
}
}
}
void resolveConfiguration(subProject, configuration, name) {
if (configuration.canBeResolved) {
logger.info("Resolving project {} {}", subProject.name, name)
configuration.resolve()
}
}
HERE
'';
# fake build to pre-download deps into fixed-output derivation
# Taken from mindustry derivation.
deps = stdenv.mkDerivation {
pname = "${pname}-deps";
inherit version src;
patches = [ ./0001-Use-protobuf-gradle-plugin.patch ];
postPatch = fixProtoc + addResolveStep;
nativeBuildInputs = [ gradle perl ] ++ lib.optional stdenv.isDarwin xcbuild;
buildPhase = ''
export HOME="$NIX_BUILD_TOP/home"
mkdir -p "$HOME"
export JAVA_TOOL_OPTIONS="-Duser.home='$HOME'"
export GRADLE_USER_HOME="$HOME/.gradle"
2021-12-24 16:24:29 +00:00
# First, fetch the static dependencies.
2022-11-06 23:31:27 +00:00
gradle --no-daemon --info -Dorg.gradle.java.home=${openjdk17} -I gradle/support/fetchDependencies.gradle init
2021-12-24 16:24:29 +00:00
# Then, fetch the maven dependencies.
2022-11-06 23:31:27 +00:00
gradle --no-daemon --info -Dorg.gradle.java.home=${openjdk17} resolveDependencies
2021-12-24 16:24:29 +00:00
'';
# perl code mavenizes pathes (com.squareup.okio/okio/1.13.0/a9283170b7305c8d92d25aff02a6ab7e45d06cbe/okio-1.13.0.jar -> com/squareup/okio/okio/1.13.0/okio-1.13.0.jar)
installPhase = ''
find $GRADLE_USER_HOME/caches/modules-2 -type f -regex '.*\.\(jar\|pom\)' \
| perl -pe 's#(.*/([^/]+)/([^/]+)/([^/]+)/[0-9a-f]{30,40}/([^/\s]+))$# ($x = $2) =~ tr|\.|/|; "install -Dm444 $1 \$out/maven/$x/$3/$4/$5" #e' \
| sh
cp -r dependencies $out/dependencies
'';
outputHashAlgo = "sha256";
outputHashMode = "recursive";
2023-05-19 19:40:13 +00:00
outputHash = "sha256-HveS3f8XHpJqefc4djYmnYfd01H2OBFK5PLNOsHAqlc=";
2021-12-24 16:24:29 +00:00
};
in stdenv.mkDerivation {
2021-12-24 16:24:29 +00:00
inherit pname version src;
nativeBuildInputs = [
gradle unzip makeWrapper icoutils
2021-12-27 19:43:56 +00:00
] ++ lib.optional stdenv.isDarwin xcbuild;
2021-12-24 16:24:29 +00:00
dontStrip = true;
patches = [ ./0001-Use-protobuf-gradle-plugin.patch ];
postPatch = fixProtoc;
buildPhase = ''
export HOME="$NIX_BUILD_TOP/home"
mkdir -p "$HOME"
export JAVA_TOOL_OPTIONS="-Duser.home='$HOME'"
2021-12-27 19:43:56 +00:00
ln -s ${deps}/dependencies dependencies
sed -i "s#mavenLocal()#mavenLocal(); maven { url '${deps}/maven' }#g" build.gradle
2021-12-24 16:24:29 +00:00
2022-11-06 23:31:27 +00:00
gradle --offline --no-daemon --info -Dorg.gradle.java.home=${openjdk17} buildGhidra
2021-12-24 16:24:29 +00:00
'';
installPhase = ''
mkdir -p "${pkg_path}" "$out/share/applications"
ZIP=build/dist/$(ls build/dist)
echo $ZIP
unzip $ZIP -d ${pkg_path}
f=("${pkg_path}"/*)
mv "${pkg_path}"/*/* "${pkg_path}"
rmdir "''${f[@]}"
ln -s ${desktopItem}/share/applications/* $out/share/applications
icotool -x "Ghidra/RuntimeScripts/Windows/support/ghidra.ico"
rm ghidra_4_40x40x32.png
for f in ghidra_*.png; do
res=$(basename "$f" ".png" | cut -d"_" -f3 | cut -d"x" -f1-2)
mkdir -pv "$out/share/icons/hicolor/$res/apps"
mv "$f" "$out/share/icons/hicolor/$res/apps/ghidra.png"
done;
'';
postFixup = ''
mkdir -p "$out/bin"
ln -s "${pkg_path}/ghidraRun" "$out/bin/ghidra"
wrapProgram "${pkg_path}/support/launch.sh" \
2022-11-06 23:31:27 +00:00
--prefix PATH : ${lib.makeBinPath [ openjdk17 ]}
2021-12-24 16:24:29 +00:00
'';
meta = with lib; {
description = "A software reverse engineering (SRE) suite of tools developed by NSA's Research Directorate in support of the Cybersecurity mission";
homepage = "https://ghidra-sre.org/";
2023-06-27 16:47:11 +00:00
platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
sourceProvenance = with sourceTypes; [
fromSource
binaryBytecode # deps
];
2021-12-24 16:24:29 +00:00
license = licenses.asl20;
2022-06-23 00:57:01 +00:00
maintainers = with maintainers; [ roblabla ];
broken = stdenv.isDarwin && stdenv.isx86_64;
2021-12-24 16:24:29 +00:00
};
}