ghidra: improve desktop support

This commit is contained in:
Emily Trau 2024-05-26 15:59:02 +10:00
parent 03d792fbdf
commit 27f69fa93e
2 changed files with 40 additions and 22 deletions

View File

@ -4,10 +4,12 @@
, callPackage
, gradle_7
, perl
, makeWrapper
, makeBinaryWrapper
, openjdk17
, unzip
, makeDesktopItem
, copyDesktopItems
, desktopToDarwinBundle
, icoutils
, xcbuild
, protobuf
@ -53,15 +55,6 @@ let
./0003-Remove-build-datestamp.patch
];
desktopItem = makeDesktopItem {
name = "ghidra";
exec = "ghidra";
icon = "ghidra";
desktopName = "Ghidra";
genericName = "Ghidra Software Reverse Engineering Suite";
categories = [ "Development" ];
};
postPatch = ''
# Set name of release (eg. PUBLIC, DEV, etc.)
sed -i -e 's/application\.release\.name=.*/application.release.name=${releaseName}/' Ghidra/application.properties
@ -145,9 +138,28 @@ HERE
in stdenv.mkDerivation (finalAttrs: {
inherit pname version src patches postPatch;
desktopItems = [
(makeDesktopItem {
name = "ghidra";
exec = "ghidra";
icon = "ghidra";
desktopName = "Ghidra";
genericName = "Ghidra Software Reverse Engineering Suite";
categories = [ "Development" ];
terminal = false;
})
];
nativeBuildInputs = [
gradle unzip makeWrapper icoutils protobuf
] ++ lib.optional stdenv.isDarwin xcbuild;
gradle
unzip
makeBinaryWrapper
copyDesktopItems
protobuf
] ++ lib.optionals stdenv.isDarwin [
xcbuild
desktopToDarwinBundle
];
dontStrip = true;
@ -169,6 +181,7 @@ in stdenv.mkDerivation (finalAttrs: {
installPhase = ''
runHook preInstall
mkdir -p "${pkg_path}" "$out/share/applications"
ZIP=build/dist/$(ls build/dist)
@ -178,15 +191,13 @@ in stdenv.mkDerivation (finalAttrs: {
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"
for f in Ghidra/Framework/Gui/src/main/resources/images/GhidraIcon*.png; do
res=$(basename "$f" ".png" | cut -d"_" -f3 | cut -c11-)
install -Dm444 "$f" "$out/share/icons/hicolor/''${res}x''${res}/apps/ghidra.png"
done;
# improved macOS icon support
install -Dm444 Ghidra/Framework/Gui/src/main/resources/images/GhidraIcon64.png $out/share/icons/hicolor/32x32@2/apps/ghidra.png
runHook postInstall
'';
@ -206,7 +217,8 @@ in stdenv.mkDerivation (finalAttrs: {
};
meta = with lib; {
description = "A software reverse engineering (SRE) suite of tools developed by NSA's Research Directorate in support of the Cybersecurity mission";
changelog = "https://htmlpreview.github.io/?https://github.com/NationalSecurityAgency/ghidra/blob/Ghidra_${finalAttrs.version}_build/Ghidra/Configurations/Public_Release/src/global/docs/ChangeHistory.html";
description = "Software reverse engineering (SRE) suite of tools";
mainProgram = "ghidra";
homepage = "https://ghidra-sre.org/";
platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];

View File

@ -1,7 +1,9 @@
{ lib
, stdenv
, callPackage
, symlinkJoin
, makeBinaryWrapper
, desktopToDarwinBundle
, ghidra
}:
@ -19,10 +21,14 @@ let
withExtensions = f: (symlinkJoin {
name = "${ghidra.pname}-with-extensions-${lib.getVersion ghidra}";
paths = (f allExtensions);
nativeBuildInputs = [ makeBinaryWrapper ];
nativeBuildInputs = [ makeBinaryWrapper ]
++ lib.optional stdenv.hostPlatform.isDarwin desktopToDarwinBundle;
postBuild = ''
makeWrapper '${ghidra}/bin/ghidra' "$out/bin/ghidra" \
--set NIX_GHIDRAHOME "$out/lib/ghidra/Ghidra"
ln -s ${ghidra}/share $out/share
'' + lib.optionalString stdenv.hostPlatform.isDarwin ''
convertDesktopFiles $prefix
'';
inherit (ghidra) meta;
});