diff options
| author | Brian Potchik <brian@vector35.com> | 2022-10-31 15:20:31 -0400 |
|---|---|---|
| committer | Peter LaFosse <peter@vector35.com> | 2022-11-10 16:19:13 -0500 |
| commit | ad42d73cd36d27757e57928f5c1db490fc37fb88 (patch) | |
| tree | 433902b6bffbd2c0fcc4552d604d1bf15c011f1a | |
| parent | 51241bb7182524d2f7c6ed32459cf9329c847673 (diff) | |
Add LoadSettingsFile API to support ephemeral settings.
| -rw-r--r-- | binaryninjaapi.h | 13 | ||||
| -rw-r--r-- | binaryninjacore.h | 3 | ||||
| -rw-r--r-- | python/settings.py | 19 | ||||
| -rw-r--r-- | settings.cpp | 6 |
4 files changed, 40 insertions, 1 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index f6167129..55838df9 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -12558,6 +12558,19 @@ namespace BinaryNinja { static Ref<Settings> Instance(const std::string& schemaId = ""); virtual ~Settings() {} + /*! Sets the file that this \c Settings instance uses when initially loading, and modifying \ + settings for the specified scope. + + \note At times it may be useful to make ephemeral changes to settings that are not saved to file. This can be accomplished \ + by calling \c LoadSettingsFile without specifying a filename. This action also resets settings to their default value. + + \param fileName the settings filename + \param scope the BNSettingsScope + \param view a BinaryView object + \return True if the load is successful, False otherwise + */ + bool LoadSettingsFile(const std::string& fileName, BNSettingsScope scope = SettingsAutoScope, Ref<BinaryView> view = nullptr); + /*! Sets the resource identifier for this \c Settings instance. When accessing setting values at the \c SettingsResourceScope level, the resource identifier is passed along through the backing store interface. diff --git a/binaryninjacore.h b/binaryninjacore.h index 42f3d861..ee5fe260 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -36,7 +36,7 @@ // Current ABI version for linking to the core. This is incremented any time // there are changes to the API that affect linking, including new functions, // new types, or modifications to existing functions or types. -#define BN_CURRENT_CORE_ABI_VERSION 26 +#define BN_CURRENT_CORE_ABI_VERSION 27 // Minimum ABI version that is supported for loading of plugins. Plugins that // are linked to an ABI version less than this will not be able to load and @@ -6078,6 +6078,7 @@ extern "C" BINARYNINJACOREAPI BNSettings* BNCreateSettings(const char* schemaId); BINARYNINJACOREAPI BNSettings* BNNewSettingsReference(BNSettings* settings); BINARYNINJACOREAPI void BNFreeSettings(BNSettings* settings); + BINARYNINJACOREAPI bool BNLoadSettingsFile(BNSettings* settings, const char* fileName, BNSettingsScope scope, BNBinaryView* view); BINARYNINJACOREAPI void BNSettingsSetResourceId(BNSettings* settings, const char* resourceId); BINARYNINJACOREAPI bool BNSettingsRegisterGroup(BNSettings* settings, const char* group, const char* title); BINARYNINJACOREAPI bool BNSettingsRegisterSetting(BNSettings* settings, const char* key, const char* properties); diff --git a/python/settings.py b/python/settings.py index 55f0538f..8c0372b4 100644 --- a/python/settings.py +++ b/python/settings.py @@ -158,6 +158,25 @@ class Settings: """Returns the ``instance_id`` for this :class:`Settings` repository (read-only)""" return self._instance_id + """ + ``load_settings_file`` Sets the file that this class:`Settings` instance uses when initially loading, and modifying \ + settings for the specified scope. + + .. note:: At times it may be useful to make ephemeral changes to settings that are not saved to file. This can be accomplished \ + by calling :func:`load_settings_file` without specifying a filename. This action also resets settings to their default value. + + :param str filename: the settings filename + :param scope: the SettingsScope + :param BinaryView view: a BinaryView object + :rtype: bool + """ + def load_settings_file(self, filename=None, scope=SettingsScope.SettingsAutoScope, view=None): + if filename is None: + filename = "" + if view is not None: + view = view.handle + return core.BNLoadSettingsFile(self.handle, filename, scope, view) + def set_resource_id(self, resource_id=None): """ ``set_resource_id`` Sets the resource identifier for this class:`Settings` instance. When accessing setting values at the \ diff --git a/settings.cpp b/settings.cpp index 14d4f0e4..d3c80952 100644 --- a/settings.cpp +++ b/settings.cpp @@ -28,6 +28,12 @@ Ref<Settings> Settings::Instance(const std::string& instanceId) } +bool Settings::LoadSettingsFile(const string& fileName, BNSettingsScope scope, Ref<BinaryView> view) +{ + return BNLoadSettingsFile(m_object, fileName.c_str(), scope, view ? view->GetObject() : nullptr); +} + + void Settings::SetResourceId(const string& resourceId) { return BNSettingsSetResourceId(m_object, resourceId.c_str()); |
