Skip to content

Commit e2787ca

Browse files
committed
CHB:add cmdline option to include callees with fns_included
1 parent 23146bd commit e2787ca

4 files changed

Lines changed: 63 additions & 5 deletions

File tree

CodeHawk/CHB/bchanalyze/bCHAnalyzeApp.ml

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,45 @@ let no_lineq = ref []
9999
let add_no_lineq s = no_lineq := s :: !no_lineq
100100

101101

102+
(** Expands a list of function address hex strings with the direct application
103+
callees of each function, as recorded in saved function info. Silently
104+
skips functions whose info is not yet available (e.g. first analysis pass).
105+
Emits a diagnostics log entry for every callee added. *)
106+
let expand_fns_with_callees (fns: string list) : string list =
107+
List.fold_left
108+
(fun acc faddr_str ->
109+
match string_to_doubleword faddr_str with
110+
| Error _ -> acc
111+
| Ok faddr ->
112+
let callees =
113+
try
114+
let finfo = load_function_info faddr in
115+
List.filter_map
116+
(fun ct ->
117+
if ct#is_app_call then Some ct#get_app_address
118+
else None)
119+
finfo#get_callees
120+
with _ -> []
121+
in
122+
List.fold_left
123+
(fun acc2 callee ->
124+
let s = callee#to_hex_string in
125+
if List.mem s acc2 then
126+
acc2
127+
else
128+
begin
129+
log_diagnostics_result
130+
~tag:"expand_fns_with_callees"
131+
__FILE__ __LINE__
132+
["add callee: " ^ s ^ " of: " ^ faddr_str];
133+
s :: acc2
134+
end)
135+
acc
136+
callees)
137+
fns
138+
fns
139+
140+
102141
let analyze_x86_function faddr f count =
103142
let _ =
104143
if system_settings#show_function_timing then
@@ -173,7 +212,9 @@ let analyze_x86_function faddr f count =
173212

174213

175214
let analyze starttime =
176-
let fns_included = included_functions () in
215+
let fns_included =
216+
let fns = included_functions () in
217+
if fn_include_callees () then expand_fns_with_callees fns else fns in
177218
let fns_excluded = excluded_functions () in
178219
let count = ref 0 in
179220
let failedfunctions = ref [] in
@@ -409,7 +450,9 @@ let analyze_mips_function faddr f count =
409450

410451

411452
let analyze_mips starttime =
412-
let fns_included = included_functions () in
453+
let fns_included =
454+
let fns = included_functions () in
455+
if fn_include_callees () then expand_fns_with_callees fns else fns in
413456
let fns_excluded = excluded_functions () in
414457
let count = ref 0 in
415458
let failedfunctions = ref [] in
@@ -565,7 +608,9 @@ let analyze_arm_function faddr f count =
565608

566609

567610
let analyze_arm starttime =
568-
let fns_included = included_functions () in
611+
let fns_included =
612+
let fns = included_functions () in
613+
if fn_include_callees () then expand_fns_with_callees fns else fns in
569614
let fns_excluded = excluded_functions () in
570615
let count = ref 0 in
571616
let failedfunctions = ref [] in
@@ -678,7 +723,9 @@ let analyze_pwr_function
678723

679724

680725
let analyze_pwr (starttime: float) =
681-
let fns_included = included_functions () in
726+
let fns_included =
727+
let fns = included_functions () in
728+
if fn_include_callees () then expand_fns_with_callees fns else fns in
682729
let fns_excluded = excluded_functions () in
683730
let count = ref 0 in
684731
begin

CodeHawk/CHB/bchcmdline/bCHXBinaryAnalyzer.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
Copyright (c) 2005-2020 Kestrel Technology LLC
88
Copyright (c) 2020 Henny Sipma
9-
Copyright (c) 2021-2025 Aarno Labs LLC
9+
Copyright (c) 2021-2026 Aarno Labs LLC
1010
1111
Permission is hereby granted, free of charge, to any person obtaining a copy
1212
of this software and associated documentation files (the "Software"), to deal
@@ -189,6 +189,9 @@ let speclist =
189189
"exclude the function with the given address from the analysis");
190190
("-fn_include", Arg.String (fun s -> include_function s),
191191
"include the function with the given address in the analysis");
192+
("-fn_include_callees",
193+
Arg.Unit (fun () -> set_fn_include_callees ()),
194+
"expand the set of functions to be analyzed with the callees of the included functions");
192195
("-fn_no_lineq", Arg.String (fun s -> add_no_lineq s),
193196
"do not apply linear equality analysis to the function with the given address");
194197
("-lineq_instr_cutoff",

CodeHawk/CHB/bchlib/bCHSystemSettings.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ let exclude_function (s: string) = fns_excluded := s :: !fns_excluded
5050
let excluded_functions () = !fns_excluded
5151

5252

53+
let fn_include_callees = ref false
54+
let set_fn_include_callees () = fn_include_callees := true
55+
let fn_include_callees () = !fn_include_callees
56+
57+
5358
let arm_typingrules_settings = H.create 23
5459

5560
let _ =

CodeHawk/CHB/bchlib/bCHSystemSettings.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ val included_functions: unit -> string list
4242

4343
val exclude_function: string -> unit
4444
val excluded_functions: unit -> string list
45+
46+
val set_fn_include_callees: unit -> unit
47+
val fn_include_callees: unit -> bool

0 commit comments

Comments
 (0)