@@ -85,9 +85,11 @@ module Symbols = struct
85
85
fun x ->
86
86
let x = Int64. (x land mask) in
87
87
Bitvec. (int64 x mod m) in
88
- let add_alias aliases addr alias = Map. update aliases addr ~f: (function
88
+ let add_alias tab addr alias = {
89
+ tab with aliases = Map. update tab.aliases addr ~f: (function
89
90
| None -> Set. singleton (module String ) alias
90
- | Some names -> Set. add names alias) in
91
+ | Some names -> Set. add names alias)
92
+ } in
91
93
let pp_comma ppf () = Format. pp_print_string ppf " , " in
92
94
let pp_addrs =
93
95
Format. pp_print_list ~pp_sep: pp_comma Bitvec. pp
@@ -105,29 +107,26 @@ module Symbols = struct
105
107
Seq. fold roots ~init: (Set. empty (module Bitvec_order ))
106
108
~f: (fun xs x -> Set. add xs (to_addr x)) in
107
109
let + named_symbols = collect Image.Scheme. named_symbol in
108
- let init = Bap_relation. empty Bitvec. compare String. compare in
109
- Seq. fold named_symbols ~init ~f: (fun rel (data ,name ) ->
110
+ let init = {empty with roots},
111
+ Bap_relation. empty Bitvec. compare String. compare in
112
+ Seq. fold named_symbols ~init ~f: (fun (tab ,rel ) (data ,name ) ->
110
113
let addr = to_addr data in
111
114
if Set. mem roots addr && is_ident name
112
- then Bap_relation. add rel (to_addr data) name
113
- else rel) |> fun rel ->
114
- Bap_relation. matching rel {empty with roots}
115
+ then tab, Bap_relation. add rel (to_addr data) name
116
+ else add_alias tab addr name, rel) |> fun ( table , rel ) ->
117
+ Bap_relation. matching rel table
115
118
~saturated: (fun k v t -> {
116
119
t with names = Map. add_exn t.names k v
117
120
})
118
- ~unmatched: (fun reason t -> {
119
- t with aliases = match reason with
121
+ ~unmatched: (fun reason t -> match reason with
120
122
| Non_injective_fwd (addrs ,name ) ->
121
123
info " the symbol %s has ambiguous addresses: %a@\n "
122
124
name pp_addrs addrs;
123
- List. fold addrs ~init: t.aliases ~f: (fun aliases addr ->
124
- add_alias aliases addr name)
125
+ t
125
126
| Non_injective_bwd (names ,addr ) ->
126
127
info " the symbol at %a has ambiguous names: %a@\n "
127
128
Bitvec. pp addr pp_names names;
128
- List. fold names ~init: t.aliases ~f: (fun aliases name ->
129
- add_alias aliases addr name)
130
- })
129
+ t)
131
130
132
131
let build_table t spec = match Ogre. eval (from_spec t) spec with
133
132
| Ok x -> x
@@ -192,24 +191,6 @@ module Symbols = struct
192
191
match Map. find aliases addr with
193
192
| None -> Set. empty (module String )
194
193
| Some aliases -> aliases
195
-
196
- let gossiper = KB.Agent. register
197
- ~package: " bap" " symbols-gossiper"
198
- ~desc: " propses an alias as a possible name"
199
- ~reliability: KB.Agent. unreliable
200
-
201
- let gossiped_aliases : unit =
202
- KB.Rule. (begin
203
- declare " provides aliases as names" |>
204
- require Image.Spec. slot |>
205
- provide Theory.Label. possible_name |>
206
- comment " uses aliases as an unreliable source of symbol names" ;
207
- end );
208
- KB. propose gossiper Theory.Label. possible_name @@ fun obj ->
209
- let + aliases = KB. collect Theory.Label. aliases obj in
210
- match Set. find aliases ~f: is_ident with
211
- | None -> Set. max_elt aliases
212
- | ident -> ident
213
194
end
214
195
215
196
@@ -233,6 +214,8 @@ let with_filename spec target _code memory path f =
233
214
!! (Some unit )) f
234
215
235
216
217
+
218
+
236
219
module State = struct
237
220
open KB.Syntax
238
221
module Dis = Bap_disasm_driver
0 commit comments