本文整理匯總了Python中utilities.Logger.Logger類的典型用法代碼示例。如果您正苦於以下問題:Python Logger類的具體用法?Python Logger怎麽用?Python Logger使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Logger類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: remove_readmes
def remove_readmes(self):
for path, _, files in os.walk(self.search_dir):
for filename in files:
if filename == "README.txt":
filepath = os.path.join(path, filename)
Logger.info("Deleting the file:", filepath)
os.remove(filepath)
示例2: divide_by_exploitability
def divide_by_exploitability(self, function=shutil.move):
if self.output_dir is not None and not os.path.exists(self.output_dir):
os.mkdir(self.output_dir)
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)
gdb_out_filepath = filepath+self.config.get_gdb_exploitable_file_extension()
if os.path.exists(gdb_out_filepath):
file_content = file(gdb_out_filepath, "rb").read()
out_dir_main = self.output_dir
if out_dir_main is None:
out_dir_main = path
out_dir = os.path.join(out_dir_main, "UNCATEGORIZED") + os.path.sep
for classification in self.classifications:
if self._get_search_string_for_classification(classification) in file_content:
out_dir = os.path.join(out_dir_main, classification) + os.path.sep
break
if not os.path.exists(out_dir):
os.mkdir(out_dir)
Logger.debug("Moving", filepath+"* to", out_dir, debug_level=4)
for file_all_extensions in glob.glob(filepath+"*"):
function(file_all_extensions, out_dir)
else:
Logger.warning("Seems like there is no gdb output file %s, can not find exploitability" % gdb_out_filepath)
示例3: divide_by_signal
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))
示例4: run_forest_run
def run_forest_run(self):
if self.output_dir is not None and not os.path.exists(self.output_dir):
os.mkdir(self.output_dir)
new_file_path = os.path.join(self.config.tmp_dir, "feelingLucky.txt")
cmd = self.config.get_gdb_command_line(self.config.get_most_standard_binary(), new_file_path, self.gdb_script_path)
for path, _, files in os.walk(self.search_dir):
for filename in files:
eips = []
indexes = []
if filename.endswith(self.config.run_extension):
continue
Logger.info("Trying my luck with", filename)
filepath = os.path.join(path, filename)
orig_file = file(filepath, "rb").read()
Logger.debug(filepath, debug_level=4)
for index in xrange(0,len(orig_file)-len(self.lucky_hex_values)):
new_file = orig_file[:index] + self.lucky_hex_values + orig_file[index+len(self.lucky_hex_values):]
#Logger.debug(new_file[:100])
file(new_file_path, "w").write(new_file)
crash_eip = self.get_crash_eip(cmd)
if crash_eip:
if not crash_eip in eips:
eips.append(crash_eip)
indexes.append(index)
if self.lucky_hex_values <= crash_eip and crash_eip <= self.lucky_hex_values_upper_bound:
o = os.path.join(self.output_dir, filename)
Logger.info("WTF, we actually were able to control EIP! See file ", o)
file(o, "w").write(new_file)
# else:
# Logger.debug("Binary crashed, but at eip:", hex(crash_eip), "index to put lucky hex value in file:", index, debug_level=7)
Logger.info("Seen the following crashing eips for this file:", list_as_intervals(eips, as_hex=True))
Logger.info("File indexes that lead to different crashes for this file:", list_as_intervals(indexes))
示例5: delete_duplicates_recursively
def delete_duplicates_recursively(self):
Logger.info("Removing duplicates in", self.search_dir)
for duplicate in self.find_duplicate_contents(self.search_dir):
if duplicate.endswith(self.config.run_extension):
continue
Logger.info("Deleting the duplicate file:", duplicate)
os.remove(duplicate)
示例6: run_command
def run_command(self, command, timeout=None, env={}, stdout=file("/dev/null"), stderr=file("/dev/null")):
#TODO: make stdout / stderr configurable
if not timeout:
timeout = self.config.run_timeout
process = subprocess.Popen(command, stdin=None, shell=False, stdout=stdout, stderr=stderr)
self.current_process = process
signal.signal(signal.SIGALRM, self._handle_alarm)
#We also had a problem that memory corruptions...
signal.signal(signal.SIGTTOU, self._handle_sigttou)
signal.alarm(timeout)
self.timeout_flag = False
self.sigttou_flag = False
#TODO: get rid of magic number
ret_signal = self.TIMEOUT_SIGNAL
#blocking call:
process.communicate()
signal.alarm(0)
#This line is reached when timeout_flag was set by _handle_alarm if it was called
if self.timeout_flag:
Logger.debug("Process was killed as it exceeded the time limit", debug_level=3)
ret_signal = self.TIMEOUT_SIGNAL
elif self.sigttou_flag:
Logger.debug("Some memory corruption resulted in a SIGTTOU signal being thrown (usually stops process). We caught it.", debug_level=3)
ret_signal = signal.SIGTTOU
else:
ret_signal = process.returncode
return ret_signal
示例7: _handle_alarm
def _handle_alarm(self, signum, frame):
# If the alarm is triggered, we're still in the communicate()
# call, so use kill() to end the process
self.timeout_flag = True
try:
self.current_process.kill()
except OSError as ose:
Logger.info("Kill failed. Sometimes the process exactly exits before we try to kill it... coward. Nothing to worry about.", ose)
示例8: rename_all_files
def rename_all_files(self, extension=""):
i = 1
for path, _, files in os.walk(self.search_dir):
for filename in files:
formatstr = "%0"+str(self.config.max_digets+4)+"d"
new_filename = formatstr % i
shutil.move(os.path.join(path, filename), os.path.join(path, new_filename+extension))
i = i+1
Logger.info("Renamed all files starting from 1, last file was named", new_filename+extension)
示例9: get_crash_eip
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
示例10: rename_same_name_files
def rename_same_name_files(self):
filenames = []
for path, _, files in os.walk(self.search_dir):
for filename in files:
i = 1
new_filename = filename
name, extension = os.path.splitext(filename)
while new_filename in filenames:
formatstr = "%0"+str(self.config.max_digets)+"d"
new_number = formatstr % i
new_filename = name + "_" + new_number + extension
i += 1
if not new_filename == filename:
Logger.info("Found filename that is already taken, renaming", filename, "to", new_filename)
shutil.move(os.path.join(path, filename), os.path.join(path, new_filename))
filenames.append(new_filename)
示例11: _handle_sigttou
def _handle_sigttou(self, signum, frame):
#Had some issues that when memory corruptions occured in a subprocess
#(no matter if shielded by multiprocess and subprocess module),
#that a SIGTTOU was sent to the entire Python main process.
#According to https://en.wikipedia.org/wiki/SIGTTOU this
#results in the process being stopped (and it looks like SIGSTP on the cmd):
#[1]+ Stopped ./AflCrashAnalyzer.py
#Of course we don't want that. Debugging was hard but then
#realized after this program was stopped:
#$ echo $?
#150
#So that's SIGTTOU on Linux at least.
#This handler will prevent the process to stop.
self.sigttou_flag = True
try:
self.current_process.kill()
except OSError as ose:
Logger.info("Kill failed. Sometimes the process exactly exits before we try to kill it... coward. Nothing to worry about.", ose)
示例12: do_sane_output_runs
def do_sane_output_runs(self):
if self.output_dir is not None and not os.path.exists(self.output_dir):
os.mkdir(self.output_dir)
if self.config.target_binary_plain is None and self.config.target_binary_asan is None:
Logger.warning("You didn't specify any non-instrumented binary, running tests with instrumented binaries")
self.instrumented_combined_stdout_stderr()
self.instrumented_combined_stdout_stderr(gdb_run=True)
else:
Logger.info("Plain run")
self.plain_combined_stdout_stderr()
Logger.info("Plain gdb run")
self.plain_combined_stdout_stderr(gdb_run=True)
Logger.info("ASAN run")
self.asan_combined_stdout_stderr()
示例13: _combined_stdout_stderr
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")
executer.get_output_for_run(command, fp, env=self.config.env)
fp.close()
示例14: notify_restaurant
def notify_restaurant(self):
if self.restaurant.has_gps_printer:
# Send GPS push
pass
return True
elif self.restaurant.has_merchant_app:
# Send GCM Push
pass
return True
else:
try:
for contact in self.restaurant.numbers.all():
if contact.number_type == NUMBER_TYPE[1][0]:
s = SMS()
s.send(mobile_number=contact.number, sms_text=self.order_text())
OrderLog.objects.create(order=self, message="Restaurant notified via SMS, to"
" be followed up by a call",
owner_type='system', owner_id=self.agent.id)
return True
except ObjectDoesNotExist:
Logger.log_ticket(order=self, message=dict(STOCK_MESSAGES)['failed_to_notify'],
owner=self.agent, owner_type='system', ticket_type=TICKET_TYPE[1][0])
return False
示例15: minimize_testcases
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")