-
Notifications
You must be signed in to change notification settings - Fork 122
/
flake.nix
86 lines (83 loc) · 2.79 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
{
description = "Nix flake for the cwe_checker with patched Ghidra as a dependency.";
inputs = {
# Depend on NixOS-unstable for the latest Rust version.
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }:
let
pkgs = nixpkgs.legacyPackages."x86_64-linux";
# Building Ghidra.
ghidra-cwe-checker-plugin = pkgs.ghidra.buildGhidraScripts {
pname = "cwe_checker";
name = "cwe_checker";
src = ./ghidra_plugin;
};
cwe-ghidra = pkgs.ghidra.withExtensions (p: with p; [ ghidra-cwe-checker-plugin ]);
# Path to Java Ghidra plugin.
cwe-checker-ghidra-plugins = pkgs.runCommand
"cwe-checker-ghidra-plugins" { src = ./src/ghidra/p_code_extractor; }
''
mkdir -p $out/p_code_extractor
cp -rf $src/* $out/p_code_extractor
'';
# Build Ghidra package with analyzeHeadless in support/ instead of bin/.
# This is where the cwe_checker expects it to be.
cwe-ghidra-path-fix = pkgs.stdenv.mkDerivation {
name = "analyzeHeadless";
pname = "analyzeHeadless";
buildInputs = [ cwe-ghidra ];
src = cwe-ghidra;
buildPhase = ''
mkdir -p $out
cp -rf ${cwe-ghidra} $out
# cwe checker expects
mkdir -p $out/support
cp ${cwe-ghidra}/bin/ghidra-analyzeHeadless $out/support/analyzeHeadless
'';
};
# Building cwe_checker.
cwe-checker-bins = pkgs.rustPlatform.buildRustPackage {
pname = "cwe_checker";
name = "cwe_checker";
src = ./.;
cargoLock = {
lockFile = ./Cargo.lock;
};
};
# Build ghidra.json
cwe-ghidra-json = pkgs.writeTextFile {
name = "GhidraConfigFile";
text = builtins.toJSON { ghidra_path = ''${cwe-ghidra-path-fix}''; };
};
# Creates config dir for cwe_checker.
cwe-checker-configs = pkgs.runCommand "cwe-checker-configs" { src = ./src; }
''
mkdir -p $out
cp $src/config.json $out
cp $src/lkm_config.json $out
ln -s ${cwe-ghidra-json} $out/ghidra.json
'';
# Target bin for 'nix run'.
cwe-checker = pkgs.writeScriptBin "cwe-checker" ''
#!/bin/sh
CWE_CHECKER_CONFIGS_PATH=${cwe-checker-configs} \
CWE_CHECKER_GHIDRA_PLUGINS_PATH=${cwe-checker-ghidra-plugins} \
${cwe-checker-bins}/bin/cwe_checker $@;
'';
in
{
devShell.x86_64-linux = pkgs.mkShell {
buildInputs = with pkgs; [
rustc
cargo
cwe-ghidra-path-fix
];
shellHook = ''
export CWE_CHECKER_CONFIGS_PATH=${cwe-checker-configs} \
export CWE_CHECKER_GHIDRA_PLUGINS_PATH=${cwe-checker-ghidra-plugins} \
'';
};
packages.x86_64-linux.default = cwe-checker;
};
}