From e3d07f20186241a9781cd2ad0b9c1d0aa8b02490 Mon Sep 17 00:00:00 2001 From: Arnaud Diederen Date: Thu, 24 Oct 2019 09:24:42 +0200 Subject: [PATCH] BUGFIX: IDAPython: inspect.stack() could fail on recent versions of Python3 (e.g., Python 3.7.4) Don't leave empty strings ('') as '__file__' members of builtin modules' globals; some modules such as inspect expect that built-in modules don't have such an attribute. --- pywraps/py_idaapi.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pywraps/py_idaapi.py b/pywraps/py_idaapi.py index 61623f1..a56cf76 100644 --- a/pywraps/py_idaapi.py +++ b/pywraps/py_idaapi.py @@ -453,8 +453,11 @@ def IDAPython_ExecScript(script, g, print_error=True): sys.argv = [ script ] # Adjust the __file__ path in the globals we pass to the script - old__file__ = g['__file__'] if '__file__' in g else '' - g['__file__'] = script + FILE_ATTR = "__file__" + has__file__ = FILE_ATTR in g + if has__file__: + old__file__ = g[FILE_ATTR] + g[FILE_ATTR] = script try: with open(script) as fin: @@ -467,7 +470,10 @@ def IDAPython_ExecScript(script, g, print_error=True): print(PY_COMPILE_ERR) finally: # Restore state - g['__file__'] = old__file__ + if has__file__: + g[FILE_ATTR] = old__file__ + else: + del g[FILE_ATTR] sys.argv = argv return PY_COMPILE_ERR