Skip to content

Commit

Permalink
ghidra: chore run nixfmt-rfc-style on ghidra dir
Browse files Browse the repository at this point in the history
  • Loading branch information
vringar authored and emilytrau committed Aug 6, 2024
1 parent acc5bfc commit 57a7c13
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 133 deletions.
135 changes: 78 additions & 57 deletions pkgs/tools/security/ghidra/build-extension.nix
Original file line number Diff line number Diff line change
@@ -1,77 +1,98 @@
{ lib
, stdenv
, unzip
, jdk
, gradle
, ghidra
{
lib,
stdenv,
unzip,
jdk,
gradle,
ghidra,
}:

let
metaCommon = oldMeta:
oldMeta // (with lib; {
maintainers = (oldMeta.maintainers or []) ++ (with maintainers; [ vringar ]);
metaCommon =
oldMeta:
oldMeta
// (with lib; {
maintainers = (oldMeta.maintainers or [ ]) ++ (with maintainers; [ vringar ]);
platforms = oldMeta.platforms or ghidra.meta.platforms;
});

buildGhidraExtension = {
pname, nativeBuildInputs ? [], meta ? { }, ...
}@args:
stdenv.mkDerivation (args // {
nativeBuildInputs = nativeBuildInputs ++ [
unzip
jdk
gradle
];
buildGhidraExtension =
{
pname,
nativeBuildInputs ? [ ],
meta ? { },
...
}@args:
stdenv.mkDerivation (
args
// {
nativeBuildInputs = nativeBuildInputs ++ [
unzip
jdk
gradle
];

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 ""}
'';
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 ""}
'';

# Needed to run gradle on darwin
__darwinAllowLocalNetworking = true;
# Needed to run gradle on darwin
__darwinAllowLocalNetworking = true;

gradleBuildTask = args.gradleBuildTask or "buildExtension";
gradleFlags = args.gradleFlags or [ ] ++ [ "-PGHIDRA_INSTALL_DIR=${ghidra}/lib/ghidra" ];
gradleBuildTask = args.gradleBuildTask or "buildExtension";
gradleFlags = args.gradleFlags or [ ] ++ [ "-PGHIDRA_INSTALL_DIR=${ghidra}/lib/ghidra" ];

installPhase = args.installPhase or ''
runHook preInstall
installPhase =
args.installPhase or ''
runHook preInstall
mkdir -p $out/lib/ghidra/Ghidra/Extensions
unzip -d $out/lib/ghidra/Ghidra/Extensions dist/*.zip
mkdir -p $out/lib/ghidra/Ghidra/Extensions
unzip -d $out/lib/ghidra/Ghidra/Extensions dist/*.zip
runHook postInstall
'';
runHook postInstall
'';

meta = metaCommon meta;
});
meta = metaCommon meta;
}
);

buildGhidraScripts = { pname, meta ? { }, ... }@args:
stdenv.mkDerivation (args // {
installPhase = ''
runHook preInstall
buildGhidraScripts =
{
pname,
meta ? { },
...
}@args:
stdenv.mkDerivation (
args
// {
installPhase = ''
runHook preInstall
GHIDRA_HOME=$out/lib/ghidra/Ghidra/Extensions/${pname}
mkdir -p $GHIDRA_HOME
cp -r . $GHIDRA_HOME/ghidra_scripts
GHIDRA_HOME=$out/lib/ghidra/Ghidra/Extensions/${pname}
mkdir -p $GHIDRA_HOME
cp -r . $GHIDRA_HOME/ghidra_scripts
touch $GHIDRA_HOME/Module.manifest
cat <<'EOF' > extension.properties
name=${pname}
description=${meta.description or ""}
author=
createdOn=
version=${lib.getVersion ghidra}
touch $GHIDRA_HOME/Module.manifest
cat <<'EOF' > extension.properties
name=${pname}
description=${meta.description or ""}
author=
createdOn=
version=${lib.getVersion ghidra}
EOF
EOF
runHook postInstall
'';
runHook postInstall
'';

meta = metaCommon meta;
});
meta = metaCommon meta;
}
);
in
{ inherit buildGhidraExtension buildGhidraScripts; }
{
inherit buildGhidraExtension buildGhidraScripts;
}
36 changes: 22 additions & 14 deletions pkgs/tools/security/ghidra/default.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{ stdenv
, fetchzip
, lib
, makeWrapper
, autoPatchelfHook
, openjdk17
, pam
, makeDesktopItem
, icoutils
{
stdenv,
fetchzip,
lib,
makeWrapper,
autoPatchelfHook,
openjdk17,
pam,
makeDesktopItem,
icoutils,
}:

let
Expand All @@ -24,7 +25,8 @@ let
startupWMClass = "ghidra-Ghidra";
};

in stdenv.mkDerivation rec {
in
stdenv.mkDerivation rec {
pname = "ghidra";
version = "10.4";
versiondate = "20230928";
Expand All @@ -37,8 +39,7 @@ in stdenv.mkDerivation rec {
nativeBuildInputs = [
makeWrapper
icoutils
]
++ lib.optionals stdenv.isLinux [ autoPatchelfHook ];
] ++ lib.optionals stdenv.isLinux [ autoPatchelfHook ];

buildInputs = [
stdenv.cc.cc.lib
Expand Down Expand Up @@ -74,10 +75,17 @@ in stdenv.mkDerivation rec {
description = "Software reverse engineering (SRE) suite of tools developed by NSA's Research Directorate in support of the Cybersecurity mission";
mainProgram = "ghidra";
homepage = "https://github.com/NationalSecurityAgency/ghidra";
platforms = [ "x86_64-linux" "x86_64-darwin" ];
platforms = [
"x86_64-linux"
"x86_64-darwin"
];
sourceProvenance = with sourceTypes; [ binaryBytecode ];
license = licenses.asl20;
maintainers = with maintainers; [ ck3d govanify mic92 ];
maintainers = with maintainers; [
ck3d
govanify
mic92
];
};

}
12 changes: 10 additions & 2 deletions pkgs/tools/security/ghidra/extensions.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{ lib, newScope, callPackage, ghidra }:
{
lib,
newScope,
callPackage,
ghidra,
}:

lib.makeScope newScope (self: {
inherit (callPackage ./build-extension.nix { inherit ghidra; }) buildGhidraExtension buildGhidraScripts;
inherit (callPackage ./build-extension.nix { inherit ghidra; })
buildGhidraExtension
buildGhidraScripts
;

ghidraninja-ghidra-scripts = self.callPackage ./extensions/ghidraninja-ghidra-scripts { };

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{ lib
, fetchFromGitHub
, buildGhidraScripts
, binwalk
, swift
, yara
{
lib,
fetchFromGitHub,
buildGhidraScripts,
binwalk,
swift,
yara,
}:

buildGhidraScripts {
Expand Down
31 changes: 14 additions & 17 deletions pkgs/tools/security/ghidra/extensions/gnudisassembler/default.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{ lib
, stdenv
, fetchurl
, buildGhidraExtension
, ghidra
, flex
, bison
, texinfo
, perl
, zlib
, xcbuild
{
lib,
stdenv,
fetchurl,
buildGhidraExtension,
ghidra,
flex,
bison,
texinfo,
perl,
zlib,
xcbuild,
}:

let
Expand Down Expand Up @@ -41,13 +42,9 @@ buildGhidraExtension {
bison
texinfo
perl
] ++ lib.optionals stdenv.hostPlatform.isDarwin [
xcbuild
];
] ++ lib.optionals stdenv.hostPlatform.isDarwin [ xcbuild ];

buildInputs = [
zlib
];
buildInputs = [ zlib ];
gradleBuildTask = "assemble";

installPhase = ''
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ lib
, buildGhidraExtension
, ghidra
{
lib,
buildGhidraExtension,
ghidra,
}:

buildGhidraExtension {
Expand Down Expand Up @@ -28,7 +29,7 @@ buildGhidraExtension {
downloadPage = "https://github.com/NationalSecurityAgency/ghidra/tree/master/Ghidra/Extensions/MachineLearning";
sourceProvenance = with sourceTypes; [
fromSource
binaryBytecode # deps
binaryBytecode # deps
];
};
}
11 changes: 6 additions & 5 deletions pkgs/tools/security/ghidra/extensions/sleighdevtools/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{ lib
, buildGhidraExtension
, ghidra
, python3
{
lib,
buildGhidraExtension,
ghidra,
python3,
}:

buildGhidraExtension {
Expand Down Expand Up @@ -34,7 +35,7 @@ buildGhidraExtension {
downloadPage = "https://github.com/NationalSecurityAgency/ghidra/tree/master/Ghidra/Extensions/SleighDevTools";
sourceProvenance = with sourceTypes; [
fromSource
binaryBytecode # deps
binaryBytecode # deps
];
};
}
Loading

0 comments on commit 57a7c13

Please sign in to comment.