Skip to content

Commit 4b40208

Browse files
authored
improves bap-configurator key handling, publishes more config (#1570)
Normalized Keys --------------- 1) Keys passed to `ocaml tools/configure.ml` can now use dashes or underscores interchangeably 2) The keys are case sensitives 3) During rewritign the keys can use either underscores or dashes, and can use any registry. Basically the comparison function makes the following keys equal: `foo-bar`, `FOO_BAR`, `FOO-bar`, and `foo bar`. New Configuration Parameters ---------------------------- Publishes several configuration parameters via Bap_main.Configuration and makes it available via `bap config`, e.g., ``` $ bap config version: 2.6.0-alpha build_id: f4a6c54 datadir: /home/ivg/.local/share/bap cachedir: /home/ivg/.cache/bap sysdatadir: /home/ivg/factory/bap-dune/_opam/share/bap-common libdir: /home/ivg/factory/bap-dune/_opam/lib confdir: /home/ivg/factory/bap-dune/_opam/etc/bap-common bindir: /home/ivg/factory/bap-dune/_opam/bin plugindir: /home/ivg/factory/bap-dune/_opam/lib/bap-common/plugins ``` Updates bapbundle to Hanle dune Plugins --------------------------------------- ``` bapbundle remove foo ``` Will now correctly delete a plugin `foo` even if it a dune plugin. (Note, that it will only remove the folder from the plugins directory and wont remove any installed libraries, for that use opam or your build system)
1 parent 244a5fb commit 4b40208

File tree

7 files changed

+57
-12
lines changed

7 files changed

+57
-12
lines changed

.github/workflows/nightly.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
- name: Install Extra System Dependencies
2727
run: |
2828
sudo add-apt-repository ppa:ivg/ghidra -y
29+
sudo apt-get update -y
2930
sudo apt-get install libghidra-dev -y
3031
sudo apt-get install libghidra-data -y
3132
sudo apt-get install dejagnu -y

lib/bap_main/bap_main.mli

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,12 @@ module Extension : sig
11361136
(** [version] is the preconfigured application version.*)
11371137
val version : string
11381138

1139+
(** [build_id] if bap is built from dev repository, contains
1140+
the short SHA of the git commit.
1141+
1142+
@since 2.6.0 *)
1143+
val build_id : string
1144+
11391145

11401146
(** [datadir] a directory for user-specific BAP readonly data.
11411147
@@ -1167,9 +1173,7 @@ module Extension : sig
11671173

11681174
(** [sysdatadir] a directory for system-specific BAP readonly data
11691175
1170-
@since 2.3.0 before that version it was named [datadir]
1171-
1172-
*)
1176+
@since 2.3.0 before that version it was named [datadir] *)
11731177
val sysdatadir : string
11741178

11751179
(** [libdir] a directory for BAP object files,
@@ -1182,6 +1186,18 @@ module Extension : sig
11821186
val confdir : string
11831187

11841188

1189+
(** [bindir] the preconfigured directory for binaries.
1190+
1191+
@since 2.6.0 *)
1192+
val bindir : string
1193+
1194+
1195+
(** [plugindir] the preconfigured path where to store BAP plugins.
1196+
1197+
@since 2.6.0 *)
1198+
val plugindir : string
1199+
1200+
11851201
(** [refine ~provides ~exclude ctxt] refines the context.
11861202
11871203
Refine the context by excluding from it all parameters of the

lib/bap_main/bap_main_config.ml.ab

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ let suffix_program = "$suffix_program"
2828
let debug = "$debug"
2929
let profile = "$profile"
3030
let standard_library = "$standard_library"
31-
let build_id = "$build_id"
31+
let build_id = "$build_id"
32+
let plugindir = "$plugindir"

src/bap_frontend.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,15 @@ let _list_command_declaration : unit =
318318

319319
let _config_command_declaration : unit =
320320
let entities = Configuration.[
321+
"version", version;
322+
"build_id", build_id;
321323
"datadir", datadir;
322324
"cachedir", cachedir;
323325
"sysdatadir", sysdatadir;
324326
"libdir", libdir;
325327
"confdir", confdir;
328+
"bindir", bindir;
329+
"plugindir", plugindir;
326330
] in
327331
let entity = Command.argument @@ Type.(some (enum entities)) in
328332
let doc = "prints BAP configuration" in
@@ -336,9 +340,6 @@ let _config_command_declaration : unit =
336340
Format.printf "%s: %s@." name value);
337341
Ok ()
338342

339-
340-
341-
342343
let () =
343344
let _unused : (module unit) = (module Bap.Std) in
344345
let () =

tools/bapbundle.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ open Core_kernel[@@warning "-D"]
22
open Bap_bundle.Std
33
open Format
44

5+
56
module Sys = Caml.Sys
67

78
open Manifest.Fields
@@ -11,6 +12,7 @@ exception Target_unspecified
1112
exception Target_is_directory
1213
exception Target_doesn't_exist
1314
exception Destdir_is_not_a_dir
15+
exception Target_not_installed
1416

1517
let target = ref ""
1618
let manifest = ref (Manifest.create "")
@@ -221,7 +223,8 @@ module Remove = struct
221223
if String.is_empty target.contents then raise Target_unspecified;
222224
let file = normalized @@ Filename.concat !destdir !target in
223225
if Sys.file_exists file
224-
then Sys.remove file
226+
then FileUtil.rm ~recurse:true [file]
227+
else raise Target_not_installed
225228
end
226229

227230

@@ -301,6 +304,8 @@ let () =
301304
error "The provided bundle file is either malformed or is not a bundle"
302305
| Destdir_is_not_a_dir ->
303306
error "The destination should be a directory, not a file"
307+
| Target_not_installed ->
308+
error "The specified plugin is not installed"
304309
| Sys_error err ->
305310
error "%s" err
306311
| exn ->

tools/rewrite.ml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,27 @@ type cls =
1414
| With
1515
| Comp of bool
1616

17-
type cfg = string Hashtbl.M(String).t [@@deriving sexp]
17+
module Key = struct
18+
type t = string [@@deriving sexp]
19+
let normalize =
20+
String.map ~f:(function
21+
| '_' | ' ' -> '-'
22+
| c -> c)
23+
24+
let sexp_of_t x =
25+
sexp_of_string @@ String.lowercase @@ normalize x
26+
27+
let hash x = String.Caseless.hash @@ normalize x
28+
include Comparable.Make(struct
29+
type t = string
30+
let sexp_of_t = sexp_of_t
31+
let compare x y = String.Caseless.compare
32+
(normalize x)
33+
(normalize y)
34+
end)
35+
end
36+
37+
type cfg = string Hashtbl.M(Key).t [@@deriving sexp]
1838

1939
let filename = ref ""
2040
let init = ref false
@@ -39,7 +59,7 @@ let () = Cfg.main ~args ~name:"bap-configurator" @@ fun self ->
3959
"--quiet";
4060
"--short=7";
4161
"HEAD"
42-
]
62+
] |> String.strip
4363
with _ -> "" in
4464

4565
let name = "bap-common" in
@@ -52,7 +72,7 @@ let () = Cfg.main ~args ~name:"bap-configurator" @@ fun self ->
5272
String.concat ~sep:"; " in
5373

5474
if init.contents then begin
55-
let vars = Hashtbl.of_alist_exn (module String) [
75+
let vars = Hashtbl.of_alist_exn (module Key) [
5676
"pkg_name", name;
5777
"pkg_version", "2.6.0-alpha";
5878
"prefix", prefix;
@@ -74,7 +94,7 @@ let () = Cfg.main ~args ~name:"bap-configurator" @@ fun self ->
7494
"dvidir", "$docdir";
7595
"pdfdir", "$docdir";
7696
"psdir", "$docdir";
77-
"plugindir", "$libdir/bap";
97+
"plugindir", "$libdir/$pkg_name/plugins";
7898
"debug", "true";
7999
"profile", "false";
80100
"build_id", build_id;

tools/rewrite.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(* rewrites configuration variables *)

0 commit comments

Comments
 (0)