Skip to content

Commit

Permalink
fix ambiguous naming of bap packages (closes #1).
Browse files Browse the repository at this point in the history
- now, bap is provided by bap-aslp and bap-uq-pac has been renamed to bap-primus.
- also fixes bap-mc executables.
  • Loading branch information
katrinafyi committed Sep 26, 2023
1 parent d424e74 commit 89557ef
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
matrix:
# end-user packages to ci build for cache
pkg:
[aslp, bap-aslp, bap-uq-pac, basil,
[aslp, bap-aslp, bap-primus, basil,
alive2, retdec-uq-pac, asl-translator]
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
max-parallel: 1
fail-fast: false
matrix:
pkg: [asli, bap-asli-plugin, bap-uq-pac, basil]
pkg: [asli, bap-asli-plugin, bap-primus, basil]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,22 @@ the usual \<nixpkgs\> extended with those from this repo.

For users of tools, the main packages are:
- **[aslp][]**: the ASLp partial evaluator with ARM's MRA,
- **[bap-aslp][]**: a version of official BAP with a bundled ASLp plugin,
- **[bap-uq-pac][]**: PAC's fork of BAP with the [Primus Lisp PR][] but without ASLp, and
- **[bap-aslp][]**[^1]: a version of official BAP with a bundled ASLp plugin (this is the preferred BAP and provides the `bap` executable),
- **[bap-primus][]**: PAC's fork of BAP with the [Primus Lisp PR][] but without ASLp (provides `bap-primus`), and
- **[basil][]**: the Basil tool for analysis and transpilation to Boogie code.

[aslp]: https://github.com/UQ-PAC/aslp
[bap-aslp]: https://github.com/UQ-PAC/bap-asli-plugin
[bap-uq-pac]: https://github.com/UQ-PAC/bap/tree/aarch64-pull-request-2
[bap-primus]: https://github.com/UQ-PAC/bap/tree/aarch64-pull-request-2
[Primus Lisp PR]: https://github.com/BinaryAnalysisPlatform/bap/pull/1546
[basil]: https://github.com/UQ-PAC/bil-to-boogie-translator

These are each defined in a .nix file of the same name,
then instantiated within overlay.nix and
built into a package set in pkgs.nix.

[^1]: Due to the plugin loading method, `bap-mc -- [bytecode]` will not work to disassemble one opcode. Instead, you should omit the `--` or pipe the bytes via stdin `echo [bytecode] | bap-mc`.

## usage

To use these, you will need the Nix package manager
Expand Down
12 changes: 9 additions & 3 deletions bap-asli-plugin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
lib,
asli,
ocamlPackages,
fetchFromGitHub
fetchFromGitHub,
}:

stdenv.mkDerivation rec {
Expand All @@ -16,14 +16,20 @@ stdenv.mkDerivation rec {
sha256 = "sha256-CsdUjXHHVisfiTP2XGOHfm+Aa23KZep4IdgoYHQsnXg=";
};

buildInputs = [ asli ocamlPackages.bap ocamlPackages.findlib ];
buildInputs = [ asli ocamlPackages.bap ocamlPackages.findlib ];

buildPhase = ''
runHook preBuild
bapbuild -package asli.libASL asli.plugin
mkdir -p $out/lib/bap
cp asli.plugin $out/lib/bap
# needed to maintain runtime dependencies.
# asli.plugin loses these because it is a compressed file.
mkdir $out/lib/bap/asli.plugin-deps/
cp -rv _build/*.cmxs $out/lib/bap/asli.plugin-deps/
cp -v asli.plugin $out/lib/bap
runHook postBuild
'';
Expand Down
54 changes: 31 additions & 23 deletions bap-aslp.nix
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
{ stdenv, makeBinaryWrapper, bap-plugins, asli, bap-asli-plugin, testers, bap-aslp }:
let _bap = (bap-plugins.override { plugins = [ bap-asli-plugin ]; });
in stdenv.mkDerivation {
pname = "bap-aslp";
version = _bap.version;
buildInputs = [ _bap asli ];
nativeBuildInputs = [ makeBinaryWrapper ];
unpackPhase = "true";
installPhase = ''
mkdir -p $out/bin
{ stdenv, makeBinaryWrapper, bap-plugins, asli, bap-asli-plugin, testers, bap-aslp, pcre }:

ASLI_PATH=${asli}/share/asli
cd ${_bap}/bin
for b in *; do
makeBinaryWrapper "$(pwd)/$b" $out/bin/$b-aslp \
--append-flags --primus-lisp-semantics=disable \
let _bap = (bap-plugins.override { suffix = ""; plugins = [ bap-asli-plugin ]; });
in stdenv.mkDerivation {
pname = "bap-aslp";
version = bap-asli-plugin.version;
unpackPhase = ":";
buildInputs = [ makeBinaryWrapper ];
postBuild = ''
ASLI_PATH=${asli}/share/asli
mkdir -p $out/bin
cd ${_bap}/bin
for b in *; do
if ! [[ -f $b ]]; then
continue
fi
if [[ $b != bap ]]; then
makeBinaryWrapper "$(pwd)/$b" $out/bin/$b
else
makeBinaryWrapper "$(pwd)/$b" $out/bin/$b \
--append-flags --no-primus-lisp \
--append-flags --asli-prelude=$ASLI_PATH/prelude.asl \
--append-flags --asli-specs=$ASLI_PATH/mra_tools/arch/regs.asl \
--append-flags --asli-specs=$ASLI_PATH/mra_tools/types.asl \
Expand All @@ -29,12 +35,14 @@
--append-flags --asli-specs=$ASLI_PATH/mra_tools/support/memory.asl \
--append-flags --asli-specs=$ASLI_PATH/mra_tools/support/stubs.asl \
--append-flags --asli-specs=$ASLI_PATH/tests/override.asl
done
'';
fi
done
'';

passthru.tests.asli = testers.testVersion {
package = bap-aslp;
command = "bap --help";
version = "asli-specs";
};
}

passthru.tests.asli = testers.testVersion {
package = bap-aslp;
command = "bap-aslp --help";
version = "asli-specs";
};
}
50 changes: 30 additions & 20 deletions bap-plugins.nix
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
{ symlinkJoin, ocamlPackages, makeWrapper, plugins ? []}:
symlinkJoin {
name = "bap-plugins";
version = ocamlPackages.bap.version;

paths = [ ocamlPackages.bap ];
buildInputs = [ makeWrapper ];
postBuild = ''
for x in ${toString plugins}; do
if ! [[ -d "$x/lib/bap" ]]; then
echo "$x/lib/bap" plugin path does not exist >&2
false
fi
done
for b in $out/bin/*; do
wrapProgram $b \
{ stdenv, ocamlPackages, makeBinaryWrapper, suffix ? "", plugins ? [] }:
let bap = ocamlPackages.bap;
in stdenv.mkDerivation {
pname = "bap-plugins";
version = bap.version;
unpackPhase = ":";
propagatedBuildInputs = plugins;
buildInputs = [ makeBinaryWrapper bap ];
postBuild = ''
for x in ${toString plugins}; do
if ! [[ -d "$x/lib/bap" ]]; then
echo "$x/lib/bap" plugin path does not exist >&2
false
fi
done
mkdir -p $out/bin
cd ${bap}/bin
for b in *; do
if ! [[ -f $b ]]; then
continue
fi
if [[ $b != bap ]]; then
makeBinaryWrapper "$(pwd)/$b" $out/bin/$b${suffix}
else
makeBinaryWrapper "$(pwd)/$b" $out/bin/$b${suffix} \
--append-flags "${toString (map (x: "-L ${x + "/lib/bap"}") plugins)}"
done
'';
}
fi
done
'';
}
34 changes: 34 additions & 0 deletions bap-primus.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{ stdenv, testers, fetchFromGitHub, ocamlPackages, makeBinaryWrapper, bap-primus }:
let
_bap = ocamlPackages.bap.overrideAttrs (final: prev: {
version = "unstable-2022-11-22";
src = fetchFromGitHub {
owner = "UQ-PAC";
repo = "bap";
rev = "acfdc1067afa847fa1eadac9700eae349434dc3b";
sha256 = "sha256-FkfwMTbA9QS3vy4rs5Ua4egZg6/gQy3YzUG8xEyFo4A=";
};
});
in stdenv.mkDerivation {
pname = "bap-primus";
version = _bap.version;
buildInputs = [ _bap ];
nativeBuildInputs = [ makeBinaryWrapper ];
unpackPhase = ":";
installPhase = ''
mkdir -p $out/bin
cd ${_bap}/bin
for b in *; do
makeBinaryWrapper "$(pwd)/$b" $out/bin/$b-primus
done
'';

passthru.tests.no-asli = testers.testBuildFailure (
testers.testVersion {
package = bap-primus;
command = "bap-primus --help | grep asli";
version = "asli-specs";
}
);
}
11 changes: 0 additions & 11 deletions bap-uq-pac.nix

This file was deleted.

2 changes: 1 addition & 1 deletion overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let

bap-aslp = prev.callPackage ./bap-aslp.nix {};

bap-uq-pac = prev.callPackage ./bap-uq-pac.nix {};
bap-primus = prev.callPackage ./bap-primus.nix {};

basil = (prev.callPackage ./basil.nix {})
# .overrideAttrs { src = prev.lib.cleanSource ~/progs/basil; }
Expand Down
2 changes: 1 addition & 1 deletion update.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Args:
Package('asli', 'UQ-PAC/aslp', then=[]), # aslp
Package('bap-asli-plugin', 'UQ-PAC/bap-asli-plugin', then=[]), # bap-aslp
Package('basil', 'UQ-PAC/bil-to-boogie-translator'),
Package('bap-uq-pac', 'UQ-PAC/bap', 'aarch64-pull-request-2'),
Package('bap-primus', 'UQ-PAC/bap', 'aarch64-pull-request-2'),
]


Expand Down

0 comments on commit 89557ef

Please sign in to comment.