diff options
| -rw-r--r-- | docs/getting-started.md | 14 | ||||
| -rw-r--r-- | ui/scriptingconsole.h | 7 |
2 files changed, 19 insertions, 2 deletions
diff --git a/docs/getting-started.md b/docs/getting-started.md index 4ef85a95..06acfe94 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -520,6 +520,20 @@ The python interpreter can be customized to run scripts on startup using `startu From here, you can add any custom functions or objects you want to be available in the console. If you want to restore the original copy of `startup.py` at any time, simply delete the file and restart Binary Ninja. A fresh copy of the above will be generated. +#### "Run Script..." + +The "Run Script..." option in the File Menu allows loading a python script from your filesystem and executing it +within the console. It can also be ran via the Command Palette or bound to a key. + +The script will have access to the same variables the Python console does, including the built-in special functions and +variables defined by BinaryNinja, and any variables you have already defined within the console. It may be helpful to +think of it as an equivalent to pasting the contents of the script within the console. + +While `__name__` in the console is set to `'__console__'`, within a script it will be set to `'__main__'`. `__file__` is not +defined within the console, but within the script, it will be set to the absolute path of the script. + +Any variables or functions defined globally within the script will be available within the console, and to future scripts. + #### Python Debugging See the [plugin development guide](dev/plugins.md#debugging-python). diff --git a/ui/scriptingconsole.h b/ui/scriptingconsole.h index 0324e37b..acedb0d7 100644 --- a/ui/scriptingconsole.h +++ b/ui/scriptingconsole.h @@ -144,6 +144,7 @@ class BINARYNINJAUIAPI ScriptingConsole : public GlobalAreaWidget, BinaryNinja:: QLabel* m_prompt; QPushButton* m_button; QTimer* m_runTimer; + bool m_scriptActive; BinaryNinja::Ref<BinaryNinja::Logger> m_logger; std::mutex m_mutex; @@ -166,6 +167,8 @@ class BINARYNINJAUIAPI ScriptingConsole : public GlobalAreaWidget, BinaryNinja:: Q_SIGNALS: void viewChanged(QWidget* frame); + void onScriptExecution(); + void onScriptCompletion(); protected: void customEvent(QEvent* event) override; @@ -178,7 +181,7 @@ class BINARYNINJAUIAPI ScriptingConsole : public GlobalAreaWidget, BinaryNinja:: QString getProviderName() const { return m_providerName; } QString getInstanceName() const { return m_instanceName; } ScriptingInstanceRef getInstance() { return m_instance; } - BNScriptingProviderInputReadyState getCurrentState() { return m_currentState; } + bool getScriptIsActive() const { return m_scriptActive; } void clearConsole(); void hideConsole(); @@ -197,5 +200,5 @@ class BINARYNINJAUIAPI ScriptingConsole : public GlobalAreaWidget, BinaryNinja:: std::vector<std::string> reverseSearch(const QString& text); void closing(); - void runScriptFromFile(std::string filename = std::string()); + void runScriptFromFile(const std::string& filename); }; |
