Skip to content

Commit b637902

Browse files
committed
makes bap-extra packages optional to facilitate local development
Eases local dune-base developement, so that you can easily start local development without too much external dependencies hassle. Allows you to disable bap-extra packages and just do `dune build` and everything should work. For the context, Dune doesn't provide nice options for multi-project monorepos. The dune files represent the static information about the project and it is presumed that there is an external tool that generates them. Cf., tezos manifest that generates dune files from the OCaml EDSL or whatever they use in Janestreet (jenga?). Originally, the plan was to implement the same mechanism, e.g., generate the dune-project file during the configuration phase. But right now I don't have enough time for that, so I am pushing a simple workaround. All packages in bap-extra are now marked as allow_empty, indicating that they can produce now artifacts. Their corresponding libraries are now optional (if a dependency is not met, then the library is silently not built). The only special case is ghidra that doesn't have dependencies trackable by Dune (i.e., OCaml libraries, besides base and bap), so to prevent it from building I added a small check that ghidra library is installed.
1 parent 0ff8147 commit b637902

File tree

6 files changed

+22
-2
lines changed

6 files changed

+22
-2
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,15 @@ git clone git@github.com:BinaryAnalysisPlatform/bap.git && cd bap
7171
opam install . --deps-only
7272
dune build && dune install
7373
```
74-
7574
to install bap and its dependencies into the currently selected switch.
7675

76+
The above command will build all packages available in bap, including experimental packages like Ghidra or Radare (included in the bap-extra) meta-package. To prepare development envionment that excludes these packages (or any other packages) just remove corresponding .opam files (don't worry, opam will regenerate them later), before creating a switch e.g.,
77+
```
78+
rm bap-{extra,radare2,ghidra,primus-symbolic-executor,ida}.opam
79+
opam switch create . --deps-only
80+
dune build && dune install
81+
```
82+
7783
## Using
7884
7985
BAP, like Docker or Git, is driven by a single command-line utility called [bap][man-bap]. Just type `bap` in your shell and it will print a message which shows BAP capabilities. The `disassemble` command will take a binary program, disassemble it, lift it into the intermediate architecture agnostic representation, build a control flow graph, and finally apply staged user-defined analysis in a form of disassembling passes. Finally, the `--dump` option (`-d` in short) will output the resulting program in the specified format. This is the default command, so you don't even need to specify it, e.g., the following will disassembled and dump the `/bin/echo` binary on your machine:

dune-project

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ be seen as a common denominator between Lwt and Async libraries.")
565565
(name bap-ghidra)
566566
(synopsis "The BAP NSA Ghidra backend")
567567
(tags (bap ghidra disassembler))
568+
(allow_empty)
568569
(depends
569570
(core_kernel (and (>= v0.14) (< v0.16)))
570571
(ppx_bap (= :version))
@@ -996,6 +997,7 @@ be seen as a common denominator between Lwt and Async libraries.")
996997
(name bap-primus-symbolic-executor)
997998
(synopsis "A BAP Primus symbolic executor")
998999
(tags (bap bap-primus))
1000+
(allow_empty)
9991001
(depends
10001002
(bap-common (= :version))
10011003
(bap-primus (= :version))
@@ -1096,6 +1098,7 @@ be seen as a common denominator between Lwt and Async libraries.")
10961098
(name bap-radare2)
10971099
(synopsis "BAP Radare2 integration")
10981100
(tags (bap bap-plugin radare2))
1101+
(allow_empty)
10991102
(depends
11001103
(bap-abi (= :version))
11011104
(bap-arm (= :version))

lib/bap_ghidra/dune

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
(* -*- tuareg -*- *)
2+
3+
let () = Format.kasprintf Jbuild_plugin.V1.send {|
14
(library
25
(name bap_ghidra)
36
(public_name bap-ghidra)
@@ -12,4 +15,6 @@
1215
(foreign_stubs
1316
(language c)
1417
(names ghidra_stubs))
15-
(c_library_flags :standard -L/usr/lib/ghidra -ldecomp))
18+
(c_library_flags :standard -L/usr/lib/ghidra -ldecomp)
19+
(enabled_if %b))
20+
|} (Sys.file_exists "/usr/lib/ghidra")

plugins/ghidra/dune

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
(library
2+
(optional)
23
(name bap_ghidra_plugin)
34
(public_name bap-ghidra.plugin)
45
(libraries bap bap-ghidra bap-main core_kernel))
56

67
(plugin
8+
(optional)
79
(name ghidra)
810
(package bap-ghidra)
911
(libraries bap-ghidra.plugin)

plugins/primus_symbolic_executor/dune

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
(library
2+
(optional)
23
(name bap_primus_symbolic_executor_plugin)
34
(public_name bap-primus-symbolic-executor.plugin)
45
(preprocess (pps ppx_bap))
@@ -16,6 +17,7 @@
1617
bap-core-theory))
1718

1819
(plugin
20+
(optional)
1921
(name primus-symbolic-executor)
2022
(package bap-primus-symbolic-executor)
2123
(libraries bap-primus-symbolic-executor.plugin)

plugins/radare2/dune

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
(library
2+
(optional)
23
(name bap_radare2_plugin)
34
(public_name bap-radare2.plugin)
45
(libraries
@@ -17,6 +18,7 @@
1718
zarith))
1819

1920
(plugin
21+
(optional)
2022
(name radare2)
2123
(package bap-radare2)
2224
(libraries bap-radare2.plugin)

0 commit comments

Comments
 (0)