use super::*;

pub struct ExploitFuzz<'a> {
    handler: SearchHandler<'a>,
}

impl<'a> ExploitFuzz<'a> {
    pub fn new(handler: SearchHandler<'a>) -> Self {
        Self { handler }
    }

    pub fn run(&mut self) {
        let mut input = self.handler.get_f_input();
        let orig_input_val = input.get_value();

        if self.handler.cond.is_first_time() {
            // use interesting values
            for i in 0..input.len() {
                let n = input.get_entry_len(i);
                let orig_v = input.get_entry(i);
                let interesting_vals = get_interesting_bytes(n);
                for &v in interesting_vals.iter() {
                    if self.handler.is_stopped_or_skip() {
                        break;
                    }
                    input.set(i, v);
                    self.handler.execute_input(&input);
                }
                input.set(i, orig_v);
            }
        }

        self.handler.max_times = config::MAX_EXPLOIT_EXEC_NUM.into();
        loop {
            if self.handler.is_stopped_or_skip() {
                break;
            }
            input.assign(&orig_input_val);
            input.randomize_all();
            self.handler.execute_input(&input);
        }

        // Fuzz enough time..
        /*
        if self.handler.cond.is_time_expired() {
            self.handler.cond.mark_as_done();
        }
        */
    }
}
