示例#1
0
 def divide_by_signal(self, confirmation_loops=0, function=shutil.copyfile):
     if self.output_dir is not None and not os.path.exists(self.output_dir):
         os.mkdir(self.output_dir)
     ex = Executer(self.config)
     for path, _, files in os.walk(self.search_dir):
         for filename in files:
             if filename.endswith(self.config.run_extension):
                 continue
             filepath = os.path.join(path, filename)
             command = self.config.get_command_line(self.binary_to_use,
                                                    filepath)
             Logger.debug("Executing:", command, debug_level=4)
             Logger.busy()
             signal = ex.run_command(command, env=self.config.env)
             while confirmation_loops > 0:
                 Logger.busy()
                 new_signal = ex.run_command(command, env=self.config.env)
                 if new_signal == signal:
                     signal = new_signal
                     confirmation_loops -= 1
                 else:
                     Logger.info(
                         "Detected varying return codes for exactly the same run"
                     )
                     signal = SignalFinder.VARYING_SIGNAL
                     break
             Logger.debug("We consider signal %i for input file %s" %
                          (signal, filename),
                          debug_level=5)
             destination_dir = self.get_folder_path_for_signal(signal)
             if not os.path.exists(destination_dir):
                 os.mkdir(destination_dir)
             function(filepath, os.path.join(destination_dir, filename))
 def divide_by_signal(self, confirmation_loops=0, function=shutil.copyfile):
     if self.output_dir is not None and not os.path.exists(self.output_dir):
         os.mkdir(self.output_dir)
     ex = Executer(self.config)
     for path, _, files in os.walk(self.search_dir):
         for filename in files:
             if filename.endswith(self.config.run_extension):
                 continue
             filepath = os.path.join( path, filename )
             command = self.config.get_command_line(self.binary_to_use, filepath)
             Logger.debug("Executing:", command, debug_level=4)
             Logger.busy()
             signal = ex.get_signal_for_run(command, env=self.config.env)
             while confirmation_loops > 0:
                 Logger.busy()
                 new_signal = ex.get_signal_for_run(command, env=self.config.env)
                 if new_signal == signal:
                     signal = new_signal
                     confirmation_loops -= 1
                 else:
                     Logger.info("Detected varying return codes for exactly the same run")
                     signal = SignalFinder.VARYING_SIGNAL
                     break
             Logger.debug("We consider signal %i for input file %s" % (signal, filename), debug_level=5)
             destination_dir = self.get_folder_path_for_signal(signal)
             if not os.path.exists(destination_dir):
                 os.mkdir(destination_dir)
             function(filepath, os.path.join(destination_dir, filename))
 def get_crash_eip(self, cmd):
     eip = None
     Logger.busy()
     gdb_output = self.executer.get_output_for_run(cmd, self.executer.pipe, self.config.run_timeout_tmin, env=self.config.env, stderr=self.executer.pipe)
     #Logger.debug("GDB output:", gdb_output)
     m = self.regular_expr.search(gdb_output)
     if m:
         eip = m.group(1)
         eip = int(eip, 16)
     #if not signal == SignalFinder.TIMEOUT_SIGNAL:
     #    Logger.error("Minimizing this file took too long, aborted")
     return eip
 def get_crash_eip(self, cmd):
     eip = None
     Logger.busy()
     gdb_output = self.executer.run_command(cmd, env=self.config.env, stdout=self.executer.pipe, stderr=self.executer.pipe)
     #Logger.debug("GDB output:", gdb_output)
     m = self.regular_expr.search(gdb_output)
     if m:
         eip = m.group(1)
         eip = int(eip, 16)
     #if not signal == SignalFinder.TIMEOUT_SIGNAL:
     #    Logger.error("Minimizing this file took too long, aborted")
     return eip
 def minimize_testcases(self):
     if self.output_dir is not None and not os.path.exists(self.output_dir):
         os.mkdir(self.output_dir)
     executer = Executer(self.config)
     for path, _, files in os.walk(self.search_dir):
         for filename in files:
             if filename.endswith(self.config.run_extension):
                 continue
             Logger.info("Minimizing", filename)
             filepath = os.path.join(path, filename)
             cmd = self.config.get_afl_tmin_command_line(filepath, os.path.join(self.output_dir, filename))
             Logger.debug("Executing:", cmd)
             Logger.busy()
             signal = executer.run_command(cmd, timeout=self.config.run_timeout_tmin, env=self.config.env)
             if signal == SignalFinder.TIMEOUT_SIGNAL:
                 Logger.error("Minimizing this file took too long, aborted")
示例#6
0
 def minimize_testcases(self):
     if self.output_dir is not None and not os.path.exists(self.output_dir):
         os.mkdir(self.output_dir)
     executer = Executer(self.config)
     for path, _, files in os.walk(self.search_dir):
         for filename in files:
             if filename.endswith(self.config.run_extension):
                 continue
             Logger.info("Minimizing", filename)
             filepath = os.path.join(path, filename)
             cmd = self.config.get_afl_tmin_command_line(
                 filepath, os.path.join(self.output_dir, filename))
             Logger.debug("Executing:", cmd)
             Logger.busy()
             signal = executer.run_command(
                 cmd,
                 timeout=self.config.run_timeout_tmin,
                 env=self.config.env)
             if signal == SignalFinder.TIMEOUT_SIGNAL:
                 Logger.error("Minimizing this file took too long, aborted")
示例#7
0
 def _combined_stdout_stderr(self, binary, gdb_run, hint):
     executer = Executer(self.config)
     for path, _, files in os.walk(self.search_dir):
         for filename in files:
             if filename.endswith(self.config.run_extension):
                 continue
             filepath = os.path.join(path, filename)
             if gdb_run:
                 command = self.config.get_gdb_command_line(
                     binary, filepath)
                 new_filename = filename + "-" + os.path.basename(
                     binary) + hint + self.config.gdb_prefix
             else:
                 command = self.config.get_command_line(binary, filepath)
                 new_filename = filename + "-" + os.path.basename(
                     binary) + hint
             Logger.debug("Looking for stdout/stderr output:",
                          command,
                          debug_level=4)
             if self.output_dir:
                 output_file_name = get_new_output_file_name(
                     self.output_dir, new_filename,
                     self.config.run_extension, self.config.max_digets)
                 new_filepath = os.path.join(self.output_dir,
                                             output_file_name)
             else:
                 output_file_name = get_new_output_file_name(
                     path, new_filename, self.config.run_extension,
                     self.config.max_digets)
                 new_filepath = os.path.join(path, output_file_name)
             fp = file(new_filepath, "w")
             Logger.busy()
             executer.run_command(command,
                                  env=self.config.env,
                                  stdout=fp,
                                  stderr=fp)
             fp.close()
 def _combined_stdout_stderr(self, binary, gdb_run, hint):
     executer = Executer(self.config)
     for path, _, files in os.walk(self.search_dir):
         for filename in files:
             if filename.endswith(self.config.run_extension):
                 continue
             filepath = os.path.join(path, filename)
             if gdb_run:
                 command = self.config.get_gdb_command_line(binary, filepath)
                 new_filename = filename+"-"+os.path.basename(binary)+hint+self.config.gdb_prefix
             else:
                 command = self.config.get_command_line(binary, filepath)
                 new_filename = filename+"-"+os.path.basename(binary)+hint
             Logger.debug("Looking for stdout/stderr output:", command, debug_level=4)
             if self.output_dir:
                 output_file_name = get_new_output_file_name(self.output_dir, new_filename, self.config.run_extension, self.config.max_digets)
                 new_filepath = os.path.join(self.output_dir, output_file_name)
             else:
                 output_file_name = get_new_output_file_name(path, new_filename, self.config.run_extension, self.config.max_digets)
                 new_filepath = os.path.join(path, output_file_name)
             fp = file(new_filepath, "w")
             Logger.busy()
             executer.run_command(command, env=self.config.env, stdout=fp, stderr=fp)
             fp.close()