@@ -78,6 +78,7 @@ let stackvar_intro_to_string (svi: stackvar_intro_t) =
7878
7979let function_annotation_to_string (a : function_annotation_t ) =
8080 (String. concat " \n " (List. map regvar_intro_to_string a.regvarintros))
81+ ^ " \n "
8182 ^ (String. concat " \n " (List. map stackvar_intro_to_string a.stackvarintros))
8283
8384
@@ -174,6 +175,16 @@ object (self)
174175 None a.regvarintros
175176 | _ -> None
176177
178+ method get_stackvar_intro (offset : int ): stackvar_intro_t option =
179+ match self#get_function_annotation with
180+ | Some a ->
181+ List. fold_left (fun acc svi ->
182+ match acc with
183+ | Some _ -> acc
184+ | _ -> if svi.svi_offset = offset then Some svi else None )
185+ None a.stackvarintros
186+ | _ -> None
187+
177188 method has_regvar_type_annotation (iaddr : doubleword_int ): bool =
178189 match self#get_function_annotation with
179190 | Some a ->
@@ -182,13 +193,28 @@ object (self)
182193 a.regvarintros
183194 | _ -> false
184195
196+ method has_stackvar_type_annotation (offset : int ): bool =
197+ match self#get_function_annotation with
198+ | Some a ->
199+ List. exists
200+ (fun svi -> svi.svi_offset = offset && Option. is_some svi.svi_vartype)
201+ a.stackvarintros
202+ | _ -> false
203+
185204 method has_regvar_type_cast (iaddr : doubleword_int ): bool =
186205 match self#get_function_annotation with
187206 | Some a ->
188207 List. exists
189208 (fun rvi -> rvi.rvi_iaddr#equal iaddr && rvi.rvi_cast) a.regvarintros
190209 | _ -> false
191210
211+ method has_stackvar_type_cast (offset : int ): bool =
212+ match self#get_function_annotation with
213+ | Some a ->
214+ List. exists
215+ (fun svi -> svi.svi_offset = offset && svi.svi_cast) a.stackvarintros
216+ | _ -> false
217+
192218 method get_regvar_type_annotation (iaddr : doubleword_int ): btype_t traceresult =
193219 let opttype =
194220 match self#get_function_annotation with
@@ -221,6 +247,39 @@ object (self)
221247 __FILE__ ^ " :" ^ (string_of_int __LINE__) ^ " : "
222248 ^ " No register var annotation found at " ^ iaddr#to_hex_string]
223249
250+ method get_stackvar_type_annotation (offset : int ): btype_t traceresult =
251+ let opttype =
252+ match self#get_function_annotation with
253+ | None ->
254+ Some
255+ (Error [
256+ __FILE__ ^ " :" ^ (string_of_int __LINE__) ^ " : "
257+ ^ " Function " ^ faddr#to_hex_string ^ " does not have annotations" ])
258+ | Some a ->
259+ List. fold_left
260+ (fun acc svi ->
261+ match acc with
262+ | Some _ -> acc
263+ | _ ->
264+ if svi.svi_offset = offset then
265+ match svi.svi_vartype with
266+ | Some t -> Some (Ok t)
267+ | _ ->
268+ Some
269+ (Error [
270+ __FILE__ ^ " :" ^ (string_of_int __LINE__) ^ " : "
271+ ^ " Stack var annotation at offset "
272+ ^ (string_of_int offset)
273+ ^ " does not have a type" ])
274+ else
275+ acc) None a.stackvarintros in
276+ match opttype with
277+ | Some r -> r
278+ | None ->
279+ Error [
280+ __FILE__ ^ " :" ^ (string_of_int __LINE__) ^ " : "
281+ ^ " No stackvar annotation found at offset " ^ (string_of_int offset)]
282+
224283 method add_inlined_block (baddr :doubleword_int ) =
225284 inlined_blocks < - baddr :: inlined_blocks
226285
@@ -504,31 +563,33 @@ let read_xml_stackvar_intro (node: xml_element_int): stackvar_intro_t traceresul
504563 else if not (has " name" ) then
505564 Error [" stackvar intro without name" ]
506565 else
507- let svi_offset = geti " offset" in
566+ let svi_offset = ( - ( geti " offset" )) in
508567 let svi_name = get " name" in
509- let svi_vartype =
568+ let ( svi_vartype, svi_cast) =
510569 if has " typename" then
511570 let typename = get " typename" in
571+ let iscast = (has " cast" ) && ((get " cast" ) = " yes" ) in
512572 TR. tfold
513573 ~ok: (fun btype ->
514574 if has " ptrto" && (get " ptrto" ) = " yes" then
515- Some (t_ptrto btype)
575+ ( Some (t_ptrto btype), iscast )
516576 else if has " arraysize" then
517577 let arraysize = geti " arraysize" in
518- Some (t_array btype arraysize)
578+ ( Some (t_array btype arraysize), iscast )
519579 else
520- Some btype)
580+ ( Some btype, iscast) )
521581 ~error: (fun e ->
522582 begin
523583 log_error_result __FILE__ __LINE__ e;
524- None
584+ ( None , false )
525585 end )
526586 (convert_string_to_type typename)
527587 else
528- None in
588+ ( None , false ) in
529589 Ok {svi_offset = svi_offset;
530590 svi_name = svi_name;
531- svi_vartype = svi_vartype}
591+ svi_vartype = svi_vartype;
592+ svi_cast = svi_cast}
532593
533594
534595let read_xml_function_annotation (node : xml_element_int ) =
0 commit comments