From ad42d73cd36d27757e57928f5c1db490fc37fb88 Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Mon, 31 Oct 2022 15:20:31 -0400 Subject: Add LoadSettingsFile API to support ephemeral settings. --- binaryninjaapi.h | 13 +++++++++++++ binaryninjacore.h | 3 ++- python/settings.py | 19 +++++++++++++++++++ settings.cpp | 6 ++++++ 4 files changed, 40 insertions(+), 1 deletion(-) 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 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 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::Instance(const std::string& instanceId) } +bool Settings::LoadSettingsFile(const string& fileName, BNSettingsScope scope, Ref 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()); -- cgit v1.3.1