diff options
Diffstat (limited to 'python/scriptingprovider.py')
| -rw-r--r-- | python/scriptingprovider.py | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/python/scriptingprovider.py b/python/scriptingprovider.py index 1bec8d61..e3f6e3b3 100644 --- a/python/scriptingprovider.py +++ b/python/scriptingprovider.py @@ -608,21 +608,36 @@ class PythonScriptingInstance(ScriptingInstance): self.completer = bncompleter.Completer(namespace = self.locals) - self.interpreter.push("from binaryninja import *") - startup_file = os.path.join(binaryninja.user_directory(), "startup.py") - if os.path.isfile(startup_file): - with open(startup_file, 'r') as f: - for line in f.readlines(): - self.interpreter.push(line) - # Finish input in case the file does not end with a newline - self.interpreter.push('\n') - - else: + if not os.path.isfile(startup_file): with open(startup_file, 'w') as f: - f.write("# Commands in this file will be run in the interactive python console on startup\n") - f.write("from binaryninja import *\n") - f.write("\n") + f.write("""# Commands in this file will be run in the interactive python console on startup +from binaryninja import * + +def connect_pycharm_debugger(port=33333): + # Get pip install string from PyCharm's Python Debug Server Configuration + # e.g. for PyCharm 2021.1.1 #PY-7142.13: + # pip install --user pydevd-pycharm~=211.7142.13 + import pydevd_pycharm + pydevd_pycharm.settrace('localhost', port=port, stdoutToServer=True, stderrToServer=True, suspend=False) + + +def connect_vscode_debugger(port=5678): + # Note: Calling this from startup.py will cause Binary Ninja to hang on startup until VSCode starts debugging + # pip install --user debugpy + import debugpy + import sys + if sys.platform == "win32": + debugpy.configure(python=f"{sys.base_exec_prefix}/python", qt="pyside2") + else: + debugpy.configure(python=f"{sys.base_exec_prefix}/bin/python3", qt="pyside2") + debugpy.listen(("127.0.0.1", port)) + debugpy.wait_for_client() + execute_on_main_thread(lambda: debugpy.debug_this_thread()) +""") + + with open(startup_file, 'r') as f: + self.interpreter.runsource(f.read(), filename="startup.py", symbol="exec") def execute(self, code): self.code = code |
