package binsec

  1. Overview
  2. Docs

doc/src/binsec/kernel_options.ml.html

Source file kernel_options.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
(**************************************************************************)
(*  This file is part of BINSEC.                                          *)
(*                                                                        *)
(*  Copyright (C) 2016-2026                                               *)
(*    CEA (Commissariat à l'énergie atomique et aux énergies              *)
(*         alternatives)                                                  *)
(*                                                                        *)
(*  you can redistribute it and/or modify it under the terms of the GNU   *)
(*  Lesser General Public License as published by the Free Software       *)
(*  Foundation, version 2.1.                                              *)
(*                                                                        *)
(*  It is distributed in the hope that it will be useful,                 *)
(*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *)
(*  GNU Lesser General Public License for more details.                   *)
(*                                                                        *)
(*  See the GNU Lesser General Public License version 2.1                 *)
(*  for more details (enclosed in the file licenses/LGPLv2.1).            *)
(*                                                                        *)
(**************************************************************************)

(** Kernel general command-line options. *)

include Cli.Options (struct
  let shortname = "" (* This is the only one :-) *)
  let name = "Kernel"
end)

module Config_file = Builder.String_option (struct
  let name = "config"
  let doc = "Use this configuration file"
end)

module Dba_config = Builder.String_option (struct
  let name = "dba-config"
  let doc = "Set dba configuration file name"
end)

module Dba_file = Builder.String_option (struct
  let name = "dba-file"
  let doc = "Set DBA file "
end)

module Describe_binary = Builder.False (struct
  let name = "describe"
  let doc = "Display a description of the binary and exits"
end)

module ExecFile = Builder.String_option (struct
  let name = "file"
  let doc = "Set binary file. *Optional*"
end)

module Entry_point = Builder.String_option (struct
  let name = "entrypoint"
  let doc = "Set entry point"
end)

module Decoder = Builder.String (struct
  let name = "decoder"
  let default = "unisim-armsec"
  let doc = "External decoder command"
end)

module Version = Builder.False (struct
  let name = "version"
  let doc = "Print the version identifier and exit"
end)

module Color = Builder.No (struct
  let name = "color"
  let doc = "Disable colored output"
end)

module Color_profile =
  Builder.Wrap
    (struct
      let name = "color-profile"
      let doc = "Set your profile for the actual execution"

      type t = string

      let default = Binsec_base.Logger.Profile.default.name
      let default_str = Some default
      let of_string = Fun.id

      let choices =
        Some
          (List.map
             (fun ({ name; _ } : Binsec_base.Logger.Profile.t) -> name)
             Binsec_base.Logger.Profile.all_profiles)
    end)
    (struct
      type t = string

      let get () = (Binsec_base.Logger.get_profile ()).name

      let set new_profile =
        Binsec_base.Logger.set_profile
          (Binsec_base.Logger.Profile.of_string new_profile)
    end)

module Color_help = Builder.False (struct
  let name = "color-help"
  let doc = "Print the color documentation"
end)

module Machine = struct
  (** Abstract representation of hardware architecture *)
  include Builder.Variant_choice_assoc (struct
    type t = Machine.isa

    let name = "isa"
    let doc = Format.asprintf " Set isa [set by loader]"

    let assoc_map =
      [
        ("x86", Machine.x86);
        ("x86-32", Machine.x86);
        ("amd64", Machine.amd64);
        ("x86-64", Machine.amd64);
        ("arm32", Machine.armv7 LittleEndian ~thumb:False);
        ("armv7", Machine.armv7 LittleEndian ~thumb:False);
        ("armv7:arm", Machine.armv7 LittleEndian ~thumb:False);
        ("armv7:thumb", Machine.armv7 LittleEndian ~thumb:True);
        ("armv7:both", Machine.armv7 LittleEndian ~thumb:Unknown);
        ("aarch64", Machine.armv8 LittleEndian);
        ("armv8", Machine.armv8 LittleEndian);
        ("ppc64", Machine.ppc64 BigEndian);
        ("riscv", Machine.riscv `x32);
        ("riscv32", Machine.riscv `x32);
        ("riscv64", Machine.riscv `x64);
        ("sparcv8", Machine.sparcv8);
        ("z80", Machine.z80);
        ("unknown", Machine.unknown);
      ]

    let default = Machine.unknown
  end)

  let pp ppf () = Machine.ISA.pp ppf (get ())
  let isa = get
  let endianness () = Machine.ISA.endianness (get ())

  let word_size () =
    Size.Bit.to_int Machine.(Bitwidth.bitsize (ISA.bits (get ())))

  let bits () = Machine.ISA.bits (get ())
  let stack_register () = Machine.ISA.stack_register (get ())
end