Skip to content

Commit

Permalink
adds the call destination names in the assembly output
Browse files Browse the repository at this point in the history
This is a simple quality of life update that should be done many years
ago. This change adds printing the call destination name in the
assembly output, much like objdump does, e.g.,
```
c23e: e8 35 7c ff ff            callq -0x83cb # <malloc>
```

The commit also publishes the `Symtab.callee` function that gives this
information.
  • Loading branch information
ivg committed Apr 15, 2022
1 parent a360700 commit 0715b0a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
7 changes: 7 additions & 0 deletions lib/bap/bap.mli
Original file line number Diff line number Diff line change
Expand Up @@ -7845,6 +7845,13 @@ module Std : sig
(** [span fn] returns a memory map of a region occupied by a
function [fn] *)
val span : fn -> unit memmap

(** [explicit_callee symtab address] returns a callee which is
called from a block with the given [address].
@since 2.5.0
*)
val callee : t -> addr -> string option
end

type lifter = mem -> Disasm_expert.Basic.full_insn -> bil Or_error.t
Expand Down
4 changes: 4 additions & 0 deletions lib/bap_disasm/bap_disasm_symtab.ml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ let insert_call ?(implicit=false) symtab block data =

let explicit_callee {ecalls} = Map.find ecalls
let implicit_callee {icalls} = Map.find icalls
let callee tab src = match explicit_callee tab src with
| Some dst -> Some dst
| None -> implicit_callee tab src



let (<--) = fun g f -> match g with
Expand Down
2 changes: 2 additions & 0 deletions lib/bap_disasm/bap_disasm_symtab.mli
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ val explicit_callee : t -> addr -> string option
(** [implicit_callee symtab address] returns a callee which is
implicitly called from a block with the given [address]. *)
val implicit_callee : t -> addr -> string option

val callee : t -> addr -> string option
10 changes: 7 additions & 3 deletions plugins/print/print_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ let section_name memory start =
function Some name -> name
| None -> Format.asprintf ".section@%a" Addr.pp start

let same_name x y = String.(Insn.name x = Insn.name y)

let print_disasm pp_insn patterns ppf proj =
let memory = Project.memory proj in
Expand All @@ -389,19 +390,22 @@ let print_disasm pp_insn patterns ppf proj =
sorted_blocks (Graphs.Cfg.nodes cfg) |> Seq.iter ~f:(fun blk ->
let mem = Block.memory blk in
fprintf ppf "%a:@\n" pp_addr (Memory.min_addr mem);
Block.insns blk |> List.iter ~f:(pp_insn ppf))));
Block.insns blk |> List.iter ~f:(pp_insn syms blk ppf))));
pp_close_tbox ppf ()

let pp_bil fmt ppf (mem,insn) =
let pp_bil fmt _ _ ppf (mem,insn) =
let pp_bil ppf = Bil.Io.print ~fmt ppf in
let addr = Memory.min_addr mem in
fprintf ppf "%a: %s@\n%a@\n" pp_addr addr (Insn.asm insn)
pp_bil (Insn.bil insn)

let pp_insn fmt ppf (mem,insn) =
let pp_insn fmt tab blk ppf (mem,insn) =
Memory.pp ppf mem;
pp_print_tab ppf () [@ocaml.warning "-3"];
Insn.Io.print ~fmt ppf insn;
if same_name insn (Block.terminator blk)
then Option.iter (Symtab.callee tab (Block.addr blk))
~f:(fprintf ppf " # <%s>");
fprintf ppf "@\n"

let pp_knowledge ppf _ =
Expand Down

0 comments on commit 0715b0a

Please sign in to comment.