Skip to content

provides the assembly string as a promise (removes #undefined) #1398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions lib/bap_disasm/bap_disasm_insn.ml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ end
type t = Theory.Semantics.t
type op = Op.t [@@deriving bin_io, compare, sexp]

let normalize_asm asm =
String.substr_replace_all asm ~pattern:"\t"
~with_:" " |> String.strip


module Slot = struct
type 'a t = (Theory.Effect.cls, 'a) KB.slot
Expand All @@ -107,6 +111,19 @@ module Slot = struct
~public:true
~desc:"an assembly string"

let provide_asm : unit =
KB.Rule.(begin
declare ~package:"bap" "asm-of-basic" |>
require Insn.slot |>
provide asm |>
comment "provides the assembly string";
end);
let open KB.Syntax in
KB.promise Theory.Semantics.slot @@ fun label ->
let+ insn = label-->?Insn.slot in
KB.Value.put asm Theory.Semantics.empty @@
normalize_asm @@ Insn.asm insn

let sexp_of_op = function
| Op.Reg r -> Sexp.Atom (Reg.name r)
| Op.Imm w -> sexp_of_int64 (Imm.to_int64 w)
Expand Down Expand Up @@ -213,9 +230,6 @@ module Slot = struct
domain
end

let normalize_asm asm =
String.substr_replace_all asm ~pattern:"\t"
~with_:" " |> String.strip

type vis = {
jump : bool;
Expand Down Expand Up @@ -399,7 +413,7 @@ include Regular.Make(struct
end)

let pp_asm ppf insn =
Format.fprintf ppf "%s" (normalize_asm (asm insn))
Format.fprintf ppf "%s" (asm insn)


module Seqnum = struct
Expand Down
6 changes: 6 additions & 0 deletions lib/bap_image/bap_memory.ml
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,12 @@ let () =
Some (Addr.to_bitvec (min_addr mem))

let () =
KB.Rule.(begin
declare ~package:"bap" "code-of-mem" |>
require slot |>
provide Theory.Semantics.code |>
comment "extracts the memory contents"
end);
let open KB.Syntax in
KB.promise Theory.Semantics.slot @@ fun label ->
let+ {data; off; size} = label-->?slot in
Expand Down