Skip to content
Open
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
18 changes: 16 additions & 2 deletions lib/bap_sema/bap_sema_flatten.ml
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,28 @@ let flatten_exp
Bil.Var var, insert blk def
| Bil.Extract (n, p, x) ->
aux x blk >>= fun (x, blk) ->
new_var (Var.sort_of_typ (get_direct_typ x)) >>= fun var ->
let res_typ = Type.Imm (n - p + 1) in
new_var (Var.sort_of_typ (res_typ)) >>= fun var ->
let e = Bil.Extract (n, p, x) in
new_def var e >>| fun def ->
Bil.Var var, insert blk def
| Bil.Concat (x, y) ->
aux x blk >>= fun (x, blk) ->
aux y blk >>= fun (y, blk) ->
new_var (Var.sort_of_typ (get_direct_typ y)) >>= fun var ->
let exp_size (e : exp) : int option =
let typ_size (typ : Type.t) : (int option) = match typ with
| Type.Imm i -> Some i
| Type.Unk -> None
| _ -> failwith "concating non-immediates"
in
match e with
| Bil.Var v -> typ_size (Var.typ v)
| Bil.Unknown (_, t) -> typ_size t
| Bil.Int w -> Some (Word.bitwidth w)
| _ -> failwith "the expression is not flattened"
in
let res_typ = Option.both (exp_size x) (exp_size y) |> Option.value_map ~default:Type.Unk ~f:(fun (x_size, y_size) -> Type.Imm (x_size + y_size)) in
new_var (Var.sort_of_typ (res_typ)) >>= fun var ->
let e = Bil.Concat (x, y) in
new_def var e >>| fun def ->
Bil.Var var, insert blk def in
Expand Down