2024-07-26 17:52:35 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
stdenv,
|
|
|
|
unzip,
|
|
|
|
jdk,
|
|
|
|
gradle,
|
|
|
|
ghidra,
|
2022-12-26 08:51:17 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2024-07-26 17:52:35 +00:00
|
|
|
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
|
|
|
|
2024-07-26 17:52:35 +00:00
|
|
|
buildGhidraExtension =
|
|
|
|
{
|
|
|
|
pname,
|
|
|
|
nativeBuildInputs ? [ ],
|
|
|
|
meta ? { },
|
|
|
|
...
|
|
|
|
}@args:
|
|
|
|
stdenv.mkDerivation (
|
|
|
|
args
|
|
|
|
// {
|
|
|
|
nativeBuildInputs = nativeBuildInputs ++ [
|
|
|
|
unzip
|
|
|
|
jdk
|
|
|
|
gradle
|
|
|
|
];
|
2022-12-26 08:51:17 +00:00
|
|
|
|
2024-07-26 17:52:35 +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
|
|
|
|
2024-07-26 17:52:35 +00:00
|
|
|
# Needed to run gradle on darwin
|
|
|
|
__darwinAllowLocalNetworking = true;
|
2024-08-06 06:20:11 +00:00
|
|
|
|
2024-07-26 17:52:35 +00:00
|
|
|
gradleBuildTask = args.gradleBuildTask or "buildExtension";
|
|
|
|
gradleFlags = args.gradleFlags or [ ] ++ [ "-PGHIDRA_INSTALL_DIR=${ghidra}/lib/ghidra" ];
|
2024-06-28 03:49:44 +00:00
|
|
|
|
2024-07-26 17:52:35 +00:00
|
|
|
installPhase =
|
|
|
|
args.installPhase or ''
|
|
|
|
runHook preInstall
|
2022-12-26 08:51:17 +00:00
|
|
|
|
2024-07-26 17:52:35 +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
|
|
|
|
2024-07-26 17:52:35 +00:00
|
|
|
runHook postInstall
|
|
|
|
'';
|
2022-12-26 08:51:17 +00:00
|
|
|
|
2024-07-26 17:52:35 +00:00
|
|
|
meta = metaCommon meta;
|
|
|
|
}
|
|
|
|
);
|
2022-12-26 08:51:17 +00:00
|
|
|
|
2024-07-26 17:52:35 +00:00
|
|
|
buildGhidraScripts =
|
|
|
|
{
|
|
|
|
pname,
|
|
|
|
meta ? { },
|
|
|
|
...
|
|
|
|
}@args:
|
|
|
|
stdenv.mkDerivation (
|
|
|
|
args
|
|
|
|
// {
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
2022-12-26 08:51:17 +00:00
|
|
|
|
2024-07-26 17:52:35 +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
|
|
|
|
2024-07-26 17:52:35 +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
|
|
|
|
2024-07-26 17:52:35 +00:00
|
|
|
EOF
|
2022-12-26 08:51:17 +00:00
|
|
|
|
2024-07-26 17:52:35 +00:00
|
|
|
runHook postInstall
|
|
|
|
'';
|
2022-12-26 08:51:17 +00:00
|
|
|
|
2024-07-26 17:52:35 +00:00
|
|
|
meta = metaCommon meta;
|
|
|
|
}
|
|
|
|
);
|
2022-12-26 08:51:17 +00:00
|
|
|
in
|
2024-07-26 17:52:35 +00:00
|
|
|
{
|
|
|
|
inherit buildGhidraExtension buildGhidraScripts;
|
|
|
|
}
|