Skip to content

Commit 05a4239

Browse files
authored
Workspace: Add Ghidra GDB Python dependencies (#1109)
Give Ghidra a dedicated GDB wrapper whose embedded Python uses its bundled protobuf and psutil packages, avoiding runtime pip installation while leaving the normal GDB environment unchanged.
1 parent b830d74 commit 05a4239

1 file changed

Lines changed: 42 additions & 2 deletions

File tree

workspace/additional/ghidra.nix

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,49 @@
11
{ pkgs }:
22

3-
# ghidra will spam-log stack traces into the home directory when not run in a desktop environment
4-
53
let
64
inherit (pkgs.ghidra) pname version meta;
75

86
description = "Software reverse engineering (SRE) suite of tools developed by NSA's Research Directorate in support of the Cybersecurity mission";
97

8+
ghidraPythonDist = "${pkgs.ghidra}/lib/ghidra/Ghidra/Debug/Debugger-rmi-trace/pypkg/dist";
9+
10+
ghidraProtobuf = pkgs.python3Packages.buildPythonPackage {
11+
pname = "protobuf";
12+
version = "3.20.3";
13+
format = "wheel";
14+
src = "${ghidraPythonDist}/protobuf-3.20.3-py2.py3-none-any.whl";
15+
doCheck = false;
16+
pythonImportsCheck = [ "google.protobuf" ];
17+
};
18+
19+
ghidraPsutil = pkgs.python3Packages.buildPythonPackage {
20+
pname = "psutil";
21+
version = "5.9.8";
22+
pyproject = true;
23+
src = "${ghidraPythonDist}/psutil-5.9.8.tar.gz";
24+
build-system = with pkgs.python3Packages; [
25+
setuptools
26+
wheel
27+
];
28+
doCheck = false;
29+
pythonImportsCheck = [ "psutil" ];
30+
};
31+
32+
pythonEnv = pkgs.python3.withPackages (_: [
33+
ghidraProtobuf
34+
ghidraPsutil
35+
]);
36+
37+
gdb = pkgs.symlinkJoin {
38+
name = "ghidra-gdb";
39+
paths = [ pkgs.gdb ];
40+
nativeBuildInputs = [ pkgs.makeWrapper ];
41+
postBuild = ''
42+
wrapProgram $out/bin/gdb \
43+
--suffix PYTHONPATH : "${pythonEnv}/${pkgs.python3.sitePackages}"
44+
'';
45+
};
46+
1047
in pkgs.stdenv.mkDerivation {
1148
inherit pname version meta description;
1249

@@ -18,8 +55,11 @@ in pkgs.stdenv.mkDerivation {
1855
runHook preInstall
1956
2057
mkdir -p "$out/bin"
58+
59+
# Ghidra will spam-log stack traces into the home directory when not run in a desktop environment.
2160
makeWrapper "$src/bin/ghidra" \
2261
"$out/bin/ghidra" \
62+
--prefix PATH : "${pkgs.lib.makeBinPath [ gdb ]}" \
2363
--run 'if [ -z "$DISPLAY" ]; then echo "Error: DISPLAY is not set. Please run under desktop environment." >&2; exit 1; fi'
2464
2565
cp -r "$src/share" "$out/share"

0 commit comments

Comments
 (0)