Skip to content

Commit 3c042e6

Browse files
authored
Merge pull request #481 from vobst/felix/nix-flake
flake.nix: add Nix flake
2 parents 59075f6 + 3dc6b34 commit 3c042e6

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ If you installed the *cwe_checker* locally, run
7272
```bash
7373
cwe_checker BINARY
7474
```
75+
If you use nix flakes, run
76+
```bash
77+
nix run github:fkie-cad/cwe_checker -- BINARY
78+
```
7579
You can adjust the behavior of most checks via a configuration file located at `src/config.json`.
7680
If you modify it, add the command line flag `--config=src/config.json` to tell the *cwe_checker* to use the modified file.
7781
For information about other available command line flags you can pass the `--help` flag to the *cwe_checker*.

flake.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

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

0 commit comments

Comments
 (0)