Skip to content

Commit

Permalink
provides the assembly string as a promise (removes #undefined) (Binar…
Browse files Browse the repository at this point in the history
…yAnalysisPlatform#1398)

This commit fixes a bug that was a feature for a long time, it removes
`#undefined` from the output of the disassembly so that even if we
don't have full semantics for it. We do this by providing the assembly
string as a promise.

It also adds the rule specification for the recently added `insn-code`
property promise.
  • Loading branch information
ivg authored Jan 11, 2022
1 parent 3eb295d commit 1cfb70a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
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

0 comments on commit 1cfb70a

Please sign in to comment.