Skip to content

Commit dfb4f23

Browse files
authored
stops proposing aliases as potential subroutine names (#1356)
Partially reverts #1355 by removing the gossiper, which was promising, under low certainity, aliases as subroutine names. It turned to produce name conflicts on many real binaries and, in general, was wrong idea, as we from the start was using aliases as dump for conflicting names.
1 parent e91bd87 commit dfb4f23

File tree

1 file changed

+15
-32
lines changed

1 file changed

+15
-32
lines changed

lib/bap/bap_project.ml

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@ module Symbols = struct
8585
fun x ->
8686
let x = Int64.(x land mask) in
8787
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
8990
| None -> Set.singleton (module String) alias
90-
| Some names -> Set.add names alias) in
91+
| Some names -> Set.add names alias)
92+
} in
9193
let pp_comma ppf () = Format.pp_print_string ppf ", " in
9294
let pp_addrs =
9395
Format.pp_print_list ~pp_sep:pp_comma Bitvec.pp
@@ -105,29 +107,26 @@ module Symbols = struct
105107
Seq.fold roots ~init:(Set.empty (module Bitvec_order))
106108
~f:(fun xs x -> Set.add xs (to_addr x)) in
107109
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) ->
110113
let addr = to_addr data in
111114
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
115118
~saturated:(fun k v t -> {
116119
t with names = Map.add_exn t.names k v
117120
})
118-
~unmatched:(fun reason t -> {
119-
t with aliases = match reason with
121+
~unmatched:(fun reason t -> match reason with
120122
| Non_injective_fwd (addrs,name) ->
121123
info "the symbol %s has ambiguous addresses: %a@\n"
122124
name pp_addrs addrs;
123-
List.fold addrs ~init:t.aliases ~f:(fun aliases addr ->
124-
add_alias aliases addr name)
125+
t
125126
| Non_injective_bwd (names,addr) ->
126127
info "the symbol at %a has ambiguous names: %a@\n"
127128
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)
131130

132131
let build_table t spec = match Ogre.eval (from_spec t) spec with
133132
| Ok x -> x
@@ -192,24 +191,6 @@ module Symbols = struct
192191
match Map.find aliases addr with
193192
| None -> Set.empty (module String)
194193
| 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
213194
end
214195

215196

@@ -233,6 +214,8 @@ let with_filename spec target _code memory path f =
233214
!!(Some unit)) f
234215

235216

217+
218+
236219
module State = struct
237220
open KB.Syntax
238221
module Dis = Bap_disasm_driver

0 commit comments

Comments
 (0)