From d10d1afa2fbd627eb1f5a1fbfedd16838511e0bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Fri, 1 Apr 2016 23:52:39 +0200 Subject: [PATCH] Wire up the `output` signal and provide a default implementation --- src/frida/application.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/frida/application.py b/src/frida/application.py index 810a4e1..491a8d5 100644 --- a/src/frida/application.py +++ b/src/frida/application.py @@ -96,6 +96,7 @@ class ConsoleApplication(object): self._device_type = options.device_type self._host = options.host self._device = None + self._schedule_on_output = lambda pid, fd, data: self._reactor.schedule(lambda: self._on_output(pid, fd, data)) self._schedule_on_device_lost = lambda: self._reactor.schedule(self._on_device_lost) self._spawned_pid = None self._spawned_argv = None @@ -153,6 +154,7 @@ class ConsoleApplication(object): except: pass if self._device is not None: + self._device.off('output', self._schedule_on_output) self._device.off('lost', self._schedule_on_device_lost) mgr.off('changed', on_devices_changed) frida.shutdown() @@ -202,6 +204,7 @@ class ConsoleApplication(object): self._device = frida.get_device_manager().add_remote_device(self._host) else: self._device = frida.get_local_device() + self._device.on('output', self._schedule_on_output) self._device.on('lost', self._schedule_on_device_lost) if self._target is not None: spawning = True @@ -238,6 +241,20 @@ class ConsoleApplication(object): if self._device is None: self._print("Waiting for USB device to appear...") + def _on_output(self, pid, fd, data): + if fd == 1: + prefix = "stdout> " + stream = sys.stdout + else: + prefix = "stderr> " + stream = sys.stderr + encoding = stream.encoding or 'UTF-8' + text = data.decode(encoding, errors='replace') + if text.endswith("\n"): + text = text[:-1] + lines = text.split("\n") + self._print(prefix + ("\n" + prefix).join(lines)) + def _on_device_lost(self): if self._exit_status is not None: return