Skip to content

Commit 0a812f8

Browse files
committed
CHB: save reglhs and stack offset types in function data
1 parent 767fe1a commit 0a812f8

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

CodeHawk/CHB/bchlib/bCHFunctionData.ml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ object (self)
134134
val mutable functiontype = t_unknown
135135
val mutable callsites = 0
136136
val mutable pathcontexts = [] (* (ctxt_iaddress_t, ctxt_iaddress_t list) list *)
137+
val mutable reglhstypes = [] (* (register_t * iaddr * btype_t option) list *)
138+
val mutable stacklhstypes = [] (* (offset * btype_t option) list *)
137139

138140
method set_function_type (ty: btype_t) = functiontype <- ty
139141

@@ -174,6 +176,30 @@ object (self)
174176

175177
method has_callsites = callsites > 0
176178

179+
method set_reglhs_types (regtypes: (register_t * string * btype_t option) list) =
180+
reglhstypes <- regtypes
181+
182+
method get_reglhs_types = reglhstypes
183+
184+
method get_reglhs_type (reg: register_t) (iaddr: string): btype_t option =
185+
List.fold_left (fun acc (r, i, t) ->
186+
match acc with
187+
| Some _ -> acc
188+
| _ ->
189+
if BCHCPURegisters.register_equal reg r && i = iaddr then t else acc)
190+
None reglhstypes
191+
192+
method set_stack_offset_types (stacktypes: (int * btype_t option) list) =
193+
stacklhstypes <- stacktypes
194+
195+
method get_stack_offset_types = stacklhstypes
196+
197+
method get_stack_offset_type (offset: int): btype_t option =
198+
List.fold_left (fun acc (o, t) ->
199+
match acc with
200+
| Some _ -> acc
201+
| _ -> if offset == o then t else acc) None stacklhstypes
202+
177203
method add_name (s:string) =
178204
let s = sanitize_function_name s in
179205
if List.mem s names then

CodeHawk/CHB/bchlib/bCHLibTypes.mli

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,6 +1564,10 @@ class type function_data_int =
15641564
returns the number of remaining call sites.*)
15651565
method remove_callsite: int
15661566

1567+
method set_reglhs_types: ((register_t * string * btype_t option) list) -> unit
1568+
1569+
method set_stack_offset_types: ((int * btype_t option) list) -> unit
1570+
15671571
(* accessors *)
15681572
method get_names: string list (* raw names *)
15691573
method get_function_name: string (* demangled or combination of all names *)
@@ -1575,6 +1579,10 @@ class type function_data_int =
15751579
method get_inlined_blocks: doubleword_int list
15761580
method get_function_type: btype_t
15771581
method get_path_contexts: (string * string list) list
1582+
method get_reglhs_types: (register_t * string * btype_t option) list
1583+
method get_reglhs_type: register_t -> string -> btype_t option
1584+
method get_stack_offset_types: (int * btype_t option) list
1585+
method get_stack_offset_type: int -> btype_t option
15781586

15791587
(* predicates *)
15801588
method has_function_type: bool

CodeHawk/CHB/bchlibarm32/bCHARMAnalysisResults.ml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,26 +284,28 @@ object (self)
284284
val typeconstraintstore = mk_type_constraint_store ()
285285

286286
method record_results ?(save=true) (fn:arm_assembly_function_int) =
287-
let fndata = new fn_analysis_results_t fn in
287+
let fnadata = new fn_analysis_results_t fn in
288288
let vard = (get_function_info fn#get_address)#env#varmgr#vard in
289289
let typeconstraints =
290290
mk_arm_fn_type_constraints typeconstraintstore fn in
291291
let node = xmlElement "application-results" in
292292
begin
293293
(if save then
294294
let faddr = fn#get_address#to_hex_string in
295+
let fndata = BCHFunctionData.functions_data#get_function fn#get_address in
295296
begin
296-
fndata#write_xml node;
297297
typeconstraints#record_type_constraints;
298-
fndata#write_xml_register_types node
299-
(typeconstraintstore#resolve_reglhs_types faddr);
300-
fndata#write_xml_stack_types node
298+
fndata#set_reglhs_types (typeconstraintstore#resolve_reglhs_types faddr);
299+
fndata#set_stack_offset_types
301300
(typeconstraintstore#resolve_local_stack_lhs_types faddr);
301+
fnadata#write_xml_register_types node fndata#get_reglhs_types;
302+
fnadata#write_xml_stack_types node fndata#get_stack_offset_types;
303+
fnadata#write_xml node;
302304
node#setAttribute "a" faddr;
303305
save_app_function_results_file faddr node;
304306
save_vars faddr vard
305307
end );
306-
(* (if save then fndata#save); *)
308+
(* (if save then fnadata#save); *)
307309
H.add table fn#get_address#to_hex_string fn
308310
end
309311

0 commit comments

Comments
 (0)