Skip to content
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

prints the jump destination address and name in the assembly output #1469

Merged
merged 1 commit into from
Apr 15, 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
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
28 changes: 24 additions & 4 deletions plugins/print/print_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ let section_name memory start =
function Some name -> name
| None -> Format.asprintf ".section@%a" Addr.pp start


let print_disasm pp_insn patterns ppf proj =
let memory = Project.memory proj in
let syms = Project.symbols proj in
Expand All @@ -389,19 +388,40 @@ 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 jmp_dst insn =
let rec find = List.find_map ~f:(function
| Bil.Jmp (Int dst) -> Some dst
| Bil.If (_,yay,nay) ->
Option.first_some (find yay) (find nay)
| _ -> None) in
find (Insn.bil insn)

let print_jmp_dst tab blk ppf insn =
match jmp_dst insn, Symtab.callee tab (Block.addr blk) with
| Some dst, Some name ->
Format.fprintf ppf " # %s <%s>" (Addr.string_of_value dst) name
| Some dst, None ->
Format.fprintf ppf " # %s" (Addr.string_of_value dst)
| None, Some name ->
Format.fprintf ppf " # <%s>" name
| None, None -> ()

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 phys_equal insn (Block.terminator blk)
then print_jmp_dst tab blk ppf insn;
fprintf ppf "@\n"

let pp_knowledge ppf _ =
Expand Down