From 220a9f714cc8e9ae48caeaef1f2a0d812e6ef499 Mon Sep 17 00:00:00 2001 From: rina Date: Tue, 26 Sep 2023 13:39:28 +1000 Subject: [PATCH] fix ambiguous naming of bap packages (closes #1). - now, bap is provided by bap-aslp and bap-uq-pac has been renamed to bap-primus. - also fixes bap-mc executables. --- .github/workflows/main.yml | 2 +- .github/workflows/update.yml | 2 +- README.md | 8 ++++-- bap-asli-plugin.nix | 12 ++++++-- bap-aslp.nix | 54 +++++++++++++++++++++--------------- bap-plugins.nix | 50 ++++++++++++++++++++------------- bap-primus.nix | 39 ++++++++++++++++++++++++++ bap-uq-pac.nix | 11 -------- overlay.nix | 2 +- update.py | 2 +- 10 files changed, 118 insertions(+), 64 deletions(-) create mode 100644 bap-primus.nix delete mode 100644 bap-uq-pac.nix diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0c2de63..a5ed59f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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: diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index a9b7362..82fc993 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -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 diff --git a/README.md b/README.md index a4c1754..3c0e8dc 100644 --- a/README.md +++ b/README.md @@ -24,13 +24,13 @@ the usual \ 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 @@ -38,6 +38,8 @@ 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 diff --git a/bap-asli-plugin.nix b/bap-asli-plugin.nix index a681019..d7ba144 100644 --- a/bap-asli-plugin.nix +++ b/bap-asli-plugin.nix @@ -2,7 +2,7 @@ lib, asli, ocamlPackages, - fetchFromGitHub + fetchFromGitHub, }: stdenv.mkDerivation rec { @@ -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 ''; diff --git a/bap-aslp.nix b/bap-aslp.nix index 302bbe2..2c732fa 100644 --- a/bap-aslp.nix +++ b/bap-aslp.nix @@ -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 \ @@ -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"; - }; - } diff --git a/bap-plugins.nix b/bap-plugins.nix index 002beba..4f43ccb 100644 --- a/bap-plugins.nix +++ b/bap-plugins.nix @@ -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 + ''; +} diff --git a/bap-primus.nix b/bap-primus.nix new file mode 100644 index 0000000..c143892 --- /dev/null +++ b/bap-primus.nix @@ -0,0 +1,39 @@ +{ 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; + + # hack: pass through bap source for updating. + src = _bap.src; + + 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"; + } + ); + } diff --git a/bap-uq-pac.nix b/bap-uq-pac.nix deleted file mode 100644 index 455f545..0000000 --- a/bap-uq-pac.nix +++ /dev/null @@ -1,11 +0,0 @@ -{ fetchFromGitHub, ocamlPackages }: - ocamlPackages.bap.overrideAttrs (final: prev: { - version = "unstable-2022-11-22"; - # buildInputs = (prev.buildInputs or []) ++ [ asli ]; - src = fetchFromGitHub { - owner = "UQ-PAC"; - repo = "bap"; - rev = "acfdc1067afa847fa1eadac9700eae349434dc3b"; - sha256 = "sha256-FkfwMTbA9QS3vy4rs5Ua4egZg6/gQy3YzUG8xEyFo4A="; - }; - }) diff --git a/overlay.nix b/overlay.nix index 037ebfe..8af09cd 100644 --- a/overlay.nix +++ b/overlay.nix @@ -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; } diff --git a/update.py b/update.py index bc728a9..0d21333 100755 --- a/update.py +++ b/update.py @@ -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'), ]