Binary Ninja API C++: Settings
Classes | |
| class | BinaryNinja::Settings |
Settings provides a way to define and access settings in a hierarchical fashion. More... | |
◆ BinaryNinja::Settings
class BinaryNinja::Settings
Settings provides a way to define and access settings in a hierarchical fashion.
The value of a setting can be defined for each hierarchical level, where each level overrides the preceding level. The backing-store for setting values at each level is also configurable. This allows for ephemeral or platform-independent persistent settings storage for components within Binary Ninja or consumers of the Binary Ninja API.
Each Settings instance has an instanceId which identifies a schema. The schema defines the settings contents and the way in which settings are retrieved and manipulated. A new Settings instance defaults to using a value of default for the instanceId . The default settings schema defines all of the settings available for the active Binary Ninja components which include at a minimum, the settings defined by the Binary Ninja core. The default schema may additionally define settings for the UI and/or installed plugins. Extending existing schemas, or defining new ones is accomplished by calling RegisterGroup() and RegisterSetting() methods, or by deserializing an existing schema with DeserializeSchema() .
- Note
- All settings in the default settings schema are rendered with UI elements in the Settings View of Binary Ninja UI.
Allowing setting overrides is an important feature and Binary Ninja accomplishes this by allowing one to override a setting at various levels. The levels and their associated storage are shown in the following table. Default setting values are optional, and if specified, saved in the schema itself.
| Setting Level | Settings Scope | Preference | Storage |
|---|---|---|---|
| Default | SettingsDefaultScope | Lowest | Settings Schema |
| User | SettingsUserScope | - | <User Directory>/settings.json |
| Project | SettingsProjectScope | - | <Project Directory>/settings.json |
| Resource | SettingsResourceScope | Highest | Raw BinaryView (Storage in BNDB) |
Settings are identified by a key, which is a string in the form of <group>.<name> or <group>.<subGroup>.<name> . Groups provide a simple way to categorize settings. Sub-groups are optional and multiple sub-groups are allowed. When defining a settings group, the RegisterGroup method allows for specifying a UI friendly title for use in the Binary Ninja UI. Defining a new setting requires a unique setting key and a JSON string of property, value pairs. The following table describes the available properties and values.
| Property | JSON Data Type | Prerequisite | Optional | {Allowed Values} and Notes |
|---|---|---|---|---|
| "title" | string | None | No | Concise Setting Title |
| "type" | string | None | No | {"array", "boolean", "number", "string", "object"} |
| "sorted" | boolean | "type" is "array" | Yes | Automatically sort list items (default is false) |
| "isSerialized" | boolean | "type" is "string" | Yes | Treat the string as a serialized JSON object |
| "enum" | array : {string} | "type" is "array" | Yes | Enumeration definitions |
| "enumDescriptions" | array : {string} | "type" is "array" | Yes | Enumeration descriptions that match "enum" array |
| "minValue" | number | "type" is "number" | Yes | Specify 0 to infer unsigned (default is signed) |
| "maxValue" | number | "type" is "number" | Yes | Values less than or equal to INT_MAX result in a QSpinBox UI element |
| "precision" | number | "type" is "number" | Yes | Specify precision for a QDoubleSpinBox |
| "default" | {array, boolean, number, string, null} | None | Yes | Specify optimal default value |
| "aliases" | array : {string} | None | Yes | Array of deprecated setting key(s) |
| "description" | string | None | No | Detailed setting description |
| "ignore" | array : {string} | None | Yes | {"SettingsUserScope", "SettingsProjectScope", "SettingsResourceScope"} |
| "message" | string | None | Yes | An optional message with additional emphasis |
| "readOnly" | bool | None | Yes | Only enforced by UI elements |
| "optional" | bool | None | Yes | Indicates setting can be null |
| "hidden" | bool | "type" is "string" | Yes | Indicates the UI should conceal the content. The "ignore" property is required to specify the applicable storage scopes |
| "requiresRestart" | bool | None | Yes | Enable restart notification in the UI upon change |
| "uiSelectionAction" | string | "type" is "string" | Yes | {"file", "directory", <Registered UIAction Name>} Informs the UI to add a button to open a selection dialog or run a registered UIAction |
| "quickSettingsGroup" | string | None | Yes | Groups related items in the quick settings context menu using dividers to separate groups |
- Note
- In order to facilitate deterministic analysis results, settings from the default schema that impact analysis are serialized from Default, User, and Project scope into Resource scope during initial BinaryView analysis. This allows an analysis database to be opened at a later time with the same settings, regardless if Default, User, or Project settings have been modified.
- Settings that do not impact analysis (e.g. many UI settings) should use the "ignore" property to exclude "SettingsProjectScope" and "SettingsResourceScope" from the applicable scopes for the setting.
Example analysis plugin setting:
auto settings = Settings::Instance()
settings->RegisterGroup("myPlugin", "My Plugin")
settings->RegisterSetting("myPlugin.enablePreAnalysis",
R"~({
"title": "My Pre-Analysis Plugin",
"type": "boolean",
"default": false,
"description": "Enable extra analysis before core analysis.",
})~");
Metadata options = {{"myPlugin.enablePreAnalysis", Metadata(true)}};
Ref<BinaryView> bv = Load("/bin/ls", true, {}, options);
Settings::Instance()->Get<bool>("myPlugin.enablePreAnalysis");
Settings::Instance()->Get<bool>("myPlugin.enablePreAnalysis", bv);
Getting a settings value:
bool excludeUnreferencedStrings = Settings::Instance()->Get<bool>("ui.stringView.excludeUnreferencedStrings", bv);
Public Member Functions | |
| Settings (BNSettings *settings) | |
| virtual | ~Settings () |
| bool | LoadSettingsFile (const std::string &fileName, BNSettingsScope scope=SettingsAutoScope, Ref< BinaryView > view=nullptr) |
Sets the file that this Settings instance uses when initially loading, and modifying \ settings for the specified scope. | |
| void | SetResourceId (const std::string &resourceId="") |
Sets the resource identifier for this Settings instance. | |
| bool | RegisterGroup (const std::string &group, const std::string &title) |
Registers a group in the schema for this Settings instance. | |
| bool | RegisterSetting (const std::string &key, const std::string &properties) |
Registers a new setting with this Settings instance. | |
| bool | Contains (const std::string &key) |
| Determine if a setting identifier exists in the active settings schema. | |
| bool | IsEmpty (BNSettingsScope scope=SettingsAutoScope) |
| Determine if the active settings schema is empty. | |
| std::vector< std::string > | Keys () |
| Retrieve the list of setting identifiers in the active settings schema. | |
| template<typename T> | |
| T | QueryProperty (const std::string &key, const std::string &property) |
| bool | UpdateProperty (const std::string &key, const std::string &property) |
| bool | UpdateProperty (const std::string &key, const std::string &property, bool value) |
| bool | UpdateProperty (const std::string &key, const std::string &property, double value) |
| bool | UpdateProperty (const std::string &key, const std::string &property, int value) |
| bool | UpdateProperty (const std::string &key, const std::string &property, int64_t value) |
| bool | UpdateProperty (const std::string &key, const std::string &property, uint64_t value) |
| bool | UpdateProperty (const std::string &key, const std::string &property, const char *value) |
| bool | UpdateProperty (const std::string &key, const std::string &property, const std::string &value) |
| bool | UpdateProperty (const std::string &key, const std::string &property, const std::vector< std::string > &value) |
| bool | DeserializeSchema (const std::string &schema, BNSettingsScope scope=SettingsAutoScope, bool merge=true) |
| std::string | SerializeSchema () |
| bool | DeserializeSettings (const std::string &contents, Ref< BinaryView > view=nullptr, BNSettingsScope scope=SettingsAutoScope) |
| std::string | SerializeSettings (Ref< BinaryView > view=nullptr, BNSettingsScope scope=SettingsAutoScope) |
| bool | IsEmpty (Ref< BinaryView > view, BNSettingsScope scope=SettingsAutoScope) |
| bool | Reset (const std::string &key, Ref< BinaryView > view=nullptr, BNSettingsScope scope=SettingsAutoScope) |
| bool | ResetAll (Ref< BinaryView > view=nullptr, BNSettingsScope scope=SettingsAutoScope, bool schemaOnly=true) |
| template<typename T> | |
| T | Get (const std::string &key, Ref< BinaryView > view=nullptr, BNSettingsScope *scope=nullptr) |
| Get the current setting value for a particular key. | |
| std::string | GetJson (const std::string &key, Ref< BinaryView > view=nullptr, BNSettingsScope *scope=nullptr) |
| Get the current settings value for a particular key, as a JSON representation of its value. | |
| bool | Set (const std::string &key, bool value, Ref< BinaryView > view=nullptr, BNSettingsScope scope=SettingsAutoScope) |
| bool | Set (const std::string &key, double value, Ref< BinaryView > view=nullptr, BNSettingsScope scope=SettingsAutoScope) |
| bool | Set (const std::string &key, int value, Ref< BinaryView > view=nullptr, BNSettingsScope scope=SettingsAutoScope) |
| bool | Set (const std::string &key, int64_t value, Ref< BinaryView > view=nullptr, BNSettingsScope scope=SettingsAutoScope) |
| bool | Set (const std::string &key, uint64_t value, Ref< BinaryView > view=nullptr, BNSettingsScope scope=SettingsAutoScope) |
| bool | Set (const std::string &key, const char *value, Ref< BinaryView > view=nullptr, BNSettingsScope scope=SettingsAutoScope) |
| bool | Set (const std::string &key, const std::string &value, Ref< BinaryView > view=nullptr, BNSettingsScope scope=SettingsAutoScope) |
| bool | Set (const std::string &key, const std::vector< std::string > &value, Ref< BinaryView > view=nullptr, BNSettingsScope scope=SettingsAutoScope) |
| bool | SetJson (const std::string &key, const std::string &value, Ref< BinaryView > view=nullptr, BNSettingsScope scope=SettingsAutoScope) |
| bool | DeserializeSettings (const std::string &contents, Ref< Function > func, BNSettingsScope scope=SettingsAutoScope) |
| std::string | SerializeSettings (Ref< Function > func, BNSettingsScope scope=SettingsAutoScope) |
| bool | IsEmpty (Ref< Function > func, BNSettingsScope scope=SettingsAutoScope) |
| bool | Reset (const std::string &key, Ref< Function > func, BNSettingsScope scope=SettingsAutoScope) |
| bool | ResetAll (Ref< Function > func, BNSettingsScope scope=SettingsAutoScope, bool schemaOnly=true) |
| template<typename T> | |
| T | Get (const std::string &key, Ref< Function > func, BNSettingsScope *scope=nullptr) |
| std::string | GetJson (const std::string &key, Ref< Function > func, BNSettingsScope *scope=nullptr) |
| bool | Set (const std::string &key, bool value, Ref< Function > func, BNSettingsScope scope=SettingsAutoScope) |
| bool | Set (const std::string &key, double value, Ref< Function > func, BNSettingsScope scope=SettingsAutoScope) |
| bool | Set (const std::string &key, int value, Ref< Function > func, BNSettingsScope scope=SettingsAutoScope) |
| bool | Set (const std::string &key, int64_t value, Ref< Function > func, BNSettingsScope scope=SettingsAutoScope) |
| bool | Set (const std::string &key, uint64_t value, Ref< Function > func, BNSettingsScope scope=SettingsAutoScope) |
| bool | Set (const std::string &key, const char *value, Ref< Function > func, BNSettingsScope scope=SettingsAutoScope) |
| bool | Set (const std::string &key, const std::string &value, Ref< Function > func, BNSettingsScope scope=SettingsAutoScope) |
| bool | Set (const std::string &key, const std::vector< std::string > &value, Ref< Function > func, BNSettingsScope scope=SettingsAutoScope) |
| bool | SetJson (const std::string &key, const std::string &value, Ref< Function > func, BNSettingsScope scope=SettingsAutoScope) |
| template<> | |
| bool | Get (const std::string &key, Ref< Function > func, BNSettingsScope *scope) |
| template<> | |
| double | Get (const std::string &key, Ref< Function > func, BNSettingsScope *scope) |
| template<> | |
| int64_t | Get (const std::string &key, Ref< Function > func, BNSettingsScope *scope) |
| template<> | |
| uint64_t | Get (const std::string &key, Ref< Function > func, BNSettingsScope *scope) |
| template<> | |
| string | QueryProperty (const string &key, const string &property) |
| template<> | |
| vector< string > | QueryProperty (const string &key, const string &property) |
| template<> | |
| bool | Get (const string &key, Ref< BinaryView > view, BNSettingsScope *scope) |
| template<> | |
| double | Get (const string &key, Ref< BinaryView > view, BNSettingsScope *scope) |
| template<> | |
| int64_t | Get (const string &key, Ref< BinaryView > view, BNSettingsScope *scope) |
| template<> | |
| uint64_t | Get (const string &key, Ref< BinaryView > view, BNSettingsScope *scope) |
| template<> | |
| string | Get (const string &key, Ref< BinaryView > view, BNSettingsScope *scope) |
| template<> | |
| vector< string > | Get (const string &key, Ref< BinaryView > view, BNSettingsScope *scope) |
| template<> | |
| bool | Get (const string &key, Ref< Function > func, BNSettingsScope *scope) |
| template<> | |
| double | Get (const string &key, Ref< Function > func, BNSettingsScope *scope) |
| template<> | |
| int64_t | Get (const string &key, Ref< Function > func, BNSettingsScope *scope) |
| template<> | |
| uint64_t | Get (const string &key, Ref< Function > func, BNSettingsScope *scope) |
| template<> | |
| string | Get (const string &key, Ref< Function > func, BNSettingsScope *scope) |
| template<> | |
| vector< string > | Get (const string &key, Ref< Function > func, BNSettingsScope *scope) |
| Public Member Functions inherited from BinaryNinja::CoreRefCountObject< BNSettings, BNNewSettingsReference, BNFreeSettings > | |
| CoreRefCountObject () | |
| virtual | ~CoreRefCountObject () |
| BNSettings * | GetObject () const |
| void | AddRef () |
| void | Release () |
| void | AddRefForRegistration () |
| void | ReleaseForRegistration () |
| void | AddRefForCallback () |
| void | ReleaseForCallback () |
Static Public Member Functions | |
| static Ref< Settings > | Instance (const std::string &schemaId="") |
◆ ~Settings()
|
inlinevirtual |
◆ Instance()
◆ LoadSettingsFile()
Sets the file that this 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
LoadSettingsFilewithout specifying a filename. This action also resets settings to their default value.
- Parameters
- Returns
- True if the load is successful, False otherwise
◆ SetResourceId()
| void Settings::SetResourceId | ( | const std::string & | resourceId = "" | ) |
Sets the resource identifier for this Settings instance.
When accessing setting values at the SettingsResourceScope level, the resource identifier is passed along through the backing store interface.
- Note
- Currently the only available backing store for
SettingsResourceScopeis aBinaryViewobject. In the context of aBinaryViewthe resource identifier is theBinaryViewTypename. All settings for this type of backing store are saved in the 'Raw'BinaryViewType. This enables the configuration of setting values such that they are available duringBinaryViewcreation and initialization.
- Parameters
-
resourceId a unique identifier
◆ RegisterGroup()
| bool Settings::RegisterGroup | ( | const std::string & | group, |
| const std::string & | title ) |
Registers a group in the schema for this Settings instance.
- Parameters
-
group a unique identifier title a user friendly name appropriate for UI presentation
- Returns
- True on success, False on failure
◆ RegisterSetting()
| bool Settings::RegisterSetting | ( | const std::string & | key, |
| const std::string & | properties ) |
Registers a new setting with this Settings instance.
- Parameters
-
key a unique setting identifier in the form '<group>.<name>' properties a JSON string describes the setting schema
- Returns
- True on success, False on failure.
◆ Contains()
| bool Settings::Contains | ( | const std::string & | key | ) |
Determine if a setting identifier exists in the active settings schema.
- Parameters
-
key the setting identifier
- Returns
- True if the identifier exists in this active settings schema, False otherwise
◆ IsEmpty() [1/3]
Determine if the active settings schema is empty.
- Parameters
-
scope the settings scope to check, defaults to SettingsAutoScope
- Returns
- True if the active settings schema is empty, False otherwise
◆ Keys()
| vector< string > Settings::Keys | ( | ) |
Retrieve the list of setting identifiers in the active settings schema.
- Returns
- List of setting identifiers
◆ QueryProperty() [1/3]
template<typename T>
| T BinaryNinja::Settings::QueryProperty | ( | const std::string & | key, |
| const std::string & | property ) |
◆ UpdateProperty() [1/9]
| bool Settings::UpdateProperty | ( | const std::string & | key, |
| const std::string & | property ) |
◆ UpdateProperty() [2/9]
| bool Settings::UpdateProperty | ( | const std::string & | key, |
| const std::string & | property, | ||
| bool | value ) |
◆ UpdateProperty() [3/9]
| bool Settings::UpdateProperty | ( | const std::string & | key, |
| const std::string & | property, | ||
| double | value ) |
◆ UpdateProperty() [4/9]
| bool Settings::UpdateProperty | ( | const std::string & | key, |
| const std::string & | property, | ||
| int | value ) |
◆ UpdateProperty() [5/9]
| bool Settings::UpdateProperty | ( | const std::string & | key, |
| const std::string & | property, | ||
| int64_t | value ) |
◆ UpdateProperty() [6/9]
| bool Settings::UpdateProperty | ( | const std::string & | key, |
| const std::string & | property, | ||
| uint64_t | value ) |
◆ UpdateProperty() [7/9]
| bool Settings::UpdateProperty | ( | const std::string & | key, |
| const std::string & | property, | ||
| const char * | value ) |
◆ UpdateProperty() [8/9]
| bool Settings::UpdateProperty | ( | const std::string & | key, |
| const std::string & | property, | ||
| const std::string & | value ) |
◆ UpdateProperty() [9/9]
| bool Settings::UpdateProperty | ( | const std::string & | key, |
| const std::string & | property, | ||
| const std::vector< std::string > & | value ) |
◆ DeserializeSchema()
◆ SerializeSchema()
| string Settings::SerializeSchema | ( | ) |
◆ DeserializeSettings() [1/2]
◆ SerializeSettings() [1/2]
◆ IsEmpty() [2/3]
◆ Reset() [1/2]
◆ ResetAll() [1/2]
◆ Get() [1/18]
template<typename T>
| T BinaryNinja::Settings::Get | ( | const std::string & | key, |
| Ref< BinaryView > | view = nullptr, | ||
| BNSettingsScope * | scope = nullptr ) |
Get the current setting value for a particular key.
bool excludeUnreferencedStrings = Settings::Instance()->Get<bool>("ui.stringView.excludeUnreferencedStrings", data);
- Template Parameters
-
T type for the value you are retrieving
- Parameters
-
key Key for the setting view BinaryView, for factoring in resource-scoped settings scope Scope for the settings
- Returns
- Value for the setting, with type T
◆ GetJson() [1/2]
Get the current settings value for a particular key, as a JSON representation of its value.
string value = Settings::Instance()->GetJson("analysis.mode");
- Parameters
-
key Key for the setting view BinaryView, for factoring in resource-scoped settings scope Scope for the settings
- Returns
- JSON value for the setting, as a string
◆ Set() [1/16]
◆ Set() [2/16]
◆ Set() [3/16]
◆ Set() [4/16]
◆ Set() [5/16]
◆ Set() [6/16]
◆ Set() [7/16]
◆ Set() [8/16]
◆ SetJson() [1/2]
◆ DeserializeSettings() [2/2]
◆ SerializeSettings() [2/2]
◆ IsEmpty() [3/3]
◆ Reset() [2/2]
◆ ResetAll() [2/2]
◆ Get() [2/18]
template<typename T>
| T BinaryNinja::Settings::Get | ( | const std::string & | key, |
| Ref< Function > | func, | ||
| BNSettingsScope * | scope = nullptr ) |
◆ GetJson() [2/2]
◆ Set() [9/16]
◆ Set() [10/16]
◆ Set() [11/16]
◆ Set() [12/16]
◆ Set() [13/16]
◆ Set() [14/16]
◆ Set() [15/16]
◆ Set() [16/16]
◆ SetJson() [2/2]
◆ Get() [3/18]
◆ Get() [4/18]
◆ Get() [5/18]
◆ Get() [6/18]
◆ QueryProperty() [2/3]
template<>
| string BinaryNinja::Settings::QueryProperty | ( | const string & | key, |
| const string & | property ) |
◆ QueryProperty() [3/3]
template<>
| vector< string > BinaryNinja::Settings::QueryProperty | ( | const string & | key, |
| const string & | property ) |