From 89340c1526806c5a9b31d256779284db1971ae92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Sun, 8 Jan 2017 18:47:36 +0100 Subject: [PATCH] Move logfile functionality to the REPL as intended --- src/frida/application.py | 10 ---------- src/frida/repl.py | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/frida/application.py b/src/frida/application.py index 482d262..d0954b3 100644 --- a/src/frida/application.py +++ b/src/frida/application.py @@ -73,7 +73,6 @@ class ConsoleApplication(object): action='store_const', const='remote', dest="device_type", default=None) parser.add_option("-H", "--host", help="connect to remote frida-server on HOST", metavar="HOST", type='string', action='store', dest="host", default=None) - parser.add_option("-o", "--output", help="output to log file", dest="logfile", default=None) if self._needs_target(): def store_target(option, opt_str, target_value, parser, target_type, *args, **kwargs): if target_type == 'file': @@ -120,13 +119,6 @@ class ConsoleApplication(object): self._exit_status = None self._console_state = ConsoleState.EMPTY self._quiet = False - self._logfile = None; - if options.logfile is not None: - try: - self._logfile = open(options.logfile, 'w') - except Exception as e: - self._update_status('Failed to open logfile "%s"' % options.logfile) - sys.exit(1) if sum(map(lambda v: int(v is not None), (self._device_id, self._device_type, self._host))) > 1: parser.error("Only one of -D, -U, -R, and -H may be specified") @@ -317,8 +309,6 @@ class ConsoleApplication(object): else: color = Fore.RED if level == 'error' else Fore.YELLOW self._print(color + Style.BRIGHT + text + Style.RESET_ALL) - if self._logfile is not None: - self._logfile.write(text + "\n"); def find_device(type): for device in frida.enumerate_devices(): diff --git a/src/frida/repl.py b/src/frida/repl.py index a282eb2..a3b8773 100644 --- a/src/frida/repl.py +++ b/src/frida/repl.py @@ -43,12 +43,26 @@ def main(): action='store_true', dest="quiet", default=False) parser.add_option("--no-pause", help="automatically start main thread after startup", action='store_true', dest="no_pause", default=False) + parser.add_option("-o", "--output", help="output to log file", dest="logfile", default=None) def _initialize(self, parser, options, args): self._user_script = options.user_script self._pending_eval = options.eval_items self._quiet = options.quiet self._no_pause = options.no_pause + if options.logfile is not None: + try: + self._logfile = open(options.logfile, 'w') + except Exception as e: + self._update_status('Failed to open logfile "%s"' % options.logfile) + self._exit(1) + else: + self._logfile = None + + def _log(self, level, text): + ConsoleApplication._log(self, level, text) + if self._logfile is not None: + self._logfile.write(text + "\n") def _usage(self): return "usage: %prog [options] target"