From 7d0b3327b26a655756951fa988f918f5cb6f728b Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Fri, 18 Jun 2021 15:46:01 -0400 Subject: startup.py file runs commands on startup --- python/scriptingprovider.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'python/scriptingprovider.py') diff --git a/python/scriptingprovider.py b/python/scriptingprovider.py index 473cd36f..1bec8d61 100644 --- a/python/scriptingprovider.py +++ b/python/scriptingprovider.py @@ -609,6 +609,20 @@ 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: + 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") def execute(self, code): self.code = code -- cgit v1.3.1