package bap-symbol-reader

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file read_symbols_main.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
open Bap_knowledge

open Core_kernel
open Regular.Std
open Bap_future.Std
open Bap.Std

include Self()

let extract name arch =
  let blk_of_sexp x = [%of_sexp:string*int64*int64] x in
  let width = Arch.addr_size arch |> Size.in_bits in
  let addr = Addr.of_int64 ~width in
  In_channel.with_file name ~f:(fun ch ->
      Sexp.input_sexps ch |> List.map ~f:blk_of_sexp |>
      List.map ~f:(fun (n,s,e) -> n,addr s,addr e))


module type Target = sig
  type t
  val of_blocks : (string * addr * addr) seq -> t
  val set_path : t -> string -> t
  val provide : Knowledge.agent -> t -> unit
end

let agent =
  let reliability = Knowledge.Agent.authorative in
  Knowledge.Agent.register ~package:"bap"
    ~reliability "user-symbolizer"
    ~desc:"reads symbols from the user provided file"

let register syms =
  let provide (module T : Target) =
    let providers = Stream.merge
        Project.Info.arch
        Project.Info.file
        ~f:(fun arch path ->
            extract syms arch |>
            Seq.of_list |> T.of_blocks |>
            fun t -> T.set_path t path) in
    Stream.observe providers (T.provide agent) in
  provide (module struct
    include Rooter
    let provide _ s = provide s
  end);
  provide (module Symbolizer)

let () =
  let () = Config.manpage [
      `S "DESCRIPTION";
      `P "Read symbol information from a file and provide rooter,
    symbolizer and a reconstructor, based on this information. Once
  symbols are read, use $(b,--)$(i,SERVICE)=$(b,file) to use them.
  where $(i,SERVICE) is one of $(b,rooter), $(b,symbolizer) or $(b,reconstructor).
";
      `S "SEE ALSO";
      `P "$(b,bap-plugin-objdump)(1), $(b,bap-plugin-byteweight)(1), $(b,bap-plugin-ida)(1)";
    ] in
  let symsfile = Config.(param (some non_dir_file) "from" ~docv:"SYMS"
                           ~doc:"Use this file as symbols source") in
  Config.when_ready (fun {Config.get=(!)} ->
      match !symsfile with
      | Some file -> register file
      | None -> () )
OCaml

Innovation. Community. Security.