From 23674496526c99535e2e5669d2da82b6e34bf7ab Mon Sep 17 00:00:00 2001 From: elicn Date: Thu, 26 Sep 2024 16:15:14 +0300 Subject: [PATCH] Fix qilingida problems caused by custom stderr --- qiling/extensions/idaplugin/qilingida.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/qiling/extensions/idaplugin/qilingida.py b/qiling/extensions/idaplugin/qilingida.py index c3bb64ecf..9aaebc353 100644 --- a/qiling/extensions/idaplugin/qilingida.py +++ b/qiling/extensions/idaplugin/qilingida.py @@ -886,7 +886,13 @@ def __init__(self): self.env = {} def start(self, *args, **kwargs): - self.ql = Qiling(argv=self.path, rootfs=self.rootfs, verbose=QL_VERBOSE.DEBUG, env=self.env, log_plain=True, *args, **kwargs) + # ida replaces sys.stderr with their own customized class that is not fully compatible with the + # standard stream protocol. here we patch stderr replacement to make it look like a proper file. + # this has to happen before Qiling init + if not hasattr(sys.stderr, 'fileno'): + setattr(sys.stderr, 'fileno', lambda: sys.__stderr__.fileno()) + + self.ql = Qiling(argv=self.path, rootfs=self.rootfs, verbose=QL_VERBOSE.DEBUG, env=self.env, *args, **kwargs) if sys.platform != 'win32': self.ql.os.stdin = QlEmuMisc.QLStdIO('stdin', sys.__stdin__.fileno())