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

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

99 lines
2.1 KiB
Nix
Raw Normal View History

{
lib,
stdenv,
unzip,
jdk,
gradle,
ghidra,
2022-12-26 08:51:17 +00:00
}:
let
metaCommon =
oldMeta:
oldMeta
2024-08-16 21:18:33 +00:00
// {
maintainers = (oldMeta.maintainers or [ ]) ++ (with lib.maintainers; [ vringar ]);
2022-12-26 08:51:17 +00:00
platforms = oldMeta.platforms or ghidra.meta.platforms;
2024-08-16 21:18:33 +00:00
};
2022-12-26 08:51:17 +00:00
buildGhidraExtension =
{
pname,
nativeBuildInputs ? [ ],
meta ? { },
...
}@args:
stdenv.mkDerivation (
args
// {
nativeBuildInputs = nativeBuildInputs ++ [
unzip
jdk
gradle
];
2022-12-26 08:51:17 +00:00
preBuild = ''
# Set project name, otherwise defaults to directory name
echo -e '\nrootProject.name = "${pname}"' >> settings.gradle
# A config directory needs to exist when ghidra's GHelpBuilder is run
export XDG_CONFIG_HOME="''${XDG_CONFIG_HOME:-$(mktemp -d)}"
${args.preBuild or ""}
'';
2022-12-26 08:51:17 +00:00
# Needed to run gradle on darwin
__darwinAllowLocalNetworking = true;
gradleBuildTask = args.gradleBuildTask or "buildExtension";
gradleFlags = args.gradleFlags or [ ] ++ [ "-PGHIDRA_INSTALL_DIR=${ghidra}/lib/ghidra" ];
2024-06-28 03:49:44 +00:00
installPhase =
args.installPhase or ''
runHook preInstall
2022-12-26 08:51:17 +00:00
mkdir -p $out/lib/ghidra/Ghidra/Extensions
unzip -d $out/lib/ghidra/Ghidra/Extensions dist/*.zip
2022-12-26 08:51:17 +00:00
runHook postInstall
'';
2022-12-26 08:51:17 +00:00
meta = metaCommon meta;
}
);
2022-12-26 08:51:17 +00:00
buildGhidraScripts =
{
pname,
meta ? { },
...
}@args:
stdenv.mkDerivation (
args
// {
installPhase = ''
runHook preInstall
2022-12-26 08:51:17 +00:00
GHIDRA_HOME=$out/lib/ghidra/Ghidra/Extensions/${pname}
mkdir -p $GHIDRA_HOME
cp -r . $GHIDRA_HOME/ghidra_scripts
2022-12-26 08:51:17 +00:00
touch $GHIDRA_HOME/Module.manifest
cat <<'EOF' > extension.properties
name=${pname}
description=${meta.description or ""}
author=
createdOn=
version=${lib.getVersion ghidra}
2022-12-26 08:51:17 +00:00
EOF
2022-12-26 08:51:17 +00:00
runHook postInstall
'';
2022-12-26 08:51:17 +00:00
meta = metaCommon meta;
}
);
2022-12-26 08:51:17 +00:00
in
{
inherit buildGhidraExtension buildGhidraScripts;
}