@@ -114,10 +114,10 @@ let run_KB_computation (f : Data.cls KB.obj KB.t) (state : KB.state)
114114
115115(* This is the main CEGIS loop. It constructs a patched exe and verifies it.
116116 If its correct, it returns the filepath. If not, it runs again. *)
117- let rec cegis ?count : (count = 1 ) ?max_tries: (max_tries= None )
118- ~seed: (seed : Seeder.t ) (config : Config.t ) (orig_proj : project )
119- (orig_prog : Program.t ) (state : KB.state )
120- : (string , Toplevel_error. t) result =
117+ let rec cegis ?(count : int = 1 ) ?(max_tries : int option = None )
118+ ~(seed : Seeder.t ) (config : Config.t ) (orig_proj : project )
119+ (orig_prog : Program.t ) (orig_code : Bap_wp.Utils.Code_addrs.t )
120+ ( state : KB.state ) : (string, Toplevel_error.t) result =
121121 Events. (send @@ Header " Starting CEGIS iteration" );
122122 Events. (send @@ Info (Printf. sprintf " Iteration: %d" count));
123123
@@ -132,27 +132,29 @@ let rec cegis ?count:(count=1) ?max_tries:(max_tries=None)
132132
133133 (* Temporarily use the new KB state when loading the patched binary. *)
134134 Toplevel. set new_state;
135- let + _, patch_prog = Utils. load_exe tmp_patched_filepath in
135+ let + patch_proj, patch_prog = Utils. load_exe tmp_patched_filepath in
136+ let patch_code =
137+ let open Bap_wp.Utils.Code_addrs in
138+ if (Config. wp_params config).init_mem
139+ then collect patch_proj
140+ else empty in
136141 Toplevel. set state;
137142
138143 let wp_params = Config. wp_params config in
139144 let target = Project. target orig_proj in
140145 if Config. perform_verification config then
141- let verif_res =
142- Verifier. verify target wp_params
143- ~orig_prog: (orig_prog, Config. exe config)
144- ~patch_prog: (patch_prog, tmp_patched_filepath)
145- in
146+ (* let orig_code, patch_code = Addr.Set.empty, Addr.Set.empty in *)
147+ let verif_res = Verifier. verify target wp_params
148+ ~orig_prog: (orig_prog, Config. exe config, orig_code)
149+ ~patch_prog: (patch_prog, tmp_patched_filepath, patch_code) in
146150 match verif_res with
151+ | Error _ as err -> err
147152 | Ok Verifier. Done -> finalize_patched_exe value
148153 | Ok Verifier. Again ->
149- begin
150- let new_count = count + 1 in
151- let new_seed = Seeder. extract_seed value new_state in
152- cegis config orig_proj orig_prog state
153- ~count: new_count ~max_tries ~seed: new_seed
154- end
155- | Error e -> Error e
154+ let new_count = count + 1 in
155+ let new_seed = Seeder. extract_seed value new_state in
156+ cegis config orig_proj orig_prog orig_code state
157+ ~count: new_count ~max_tries ~seed: new_seed
156158 else
157159 let warning =
158160 " WARNING: No verification performed. Patched binary may be incorrect."
@@ -173,11 +175,16 @@ let run (config : Config.t) : (string, Toplevel_error.t) result =
173175 let filepath = Config. exe config in
174176 Events. (send @@ Info (Format. sprintf " Loading into BAP: %s..." filepath));
175177 let + orig_proj, orig_prog = Utils. load_exe filepath in
178+ let orig_code =
179+ let open Bap_wp.Utils.Code_addrs in
180+ if (Config. wp_params config).init_mem
181+ then collect orig_proj
182+ else empty in
176183
177184 let state = Toplevel. current () in
178185 let computation = init config orig_proj in
179186 let + obj, new_state = run_KB_computation computation state in
180187 let seed = Seeder. extract_seed obj new_state in
181188
182189 let max_tries = Config. max_tries config in
183- cegis config orig_proj orig_prog new_state ~max_tries ~seed
190+ cegis config orig_proj orig_prog orig_code new_state ~max_tries ~seed
0 commit comments