settings module¶
|
|
- class Settings(instance_id: str | None = None, handle=None)[source]¶
Bases:
object
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 aninstance_id
which identifies a schema. The schema defines the settings contents and the way in which settings are retrieved and manipulated. A newSettings
instance defaults to using a value of ‘default’ for theinstance_id
. 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 callingregister_group
andregister_setting
methods, or by deserializing an existing schema withdeserialize_schema
.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
register_group
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 “string”
Yes
Enumeration definitions
“enumDescriptions”
array : {string}
“type” is “string”
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”
boolean
None
Yes
Only enforced by UI elements
“optional”
boolean
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
boolean
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
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.
Note
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:
>>> my_settings = Settings() >>> title = "My Pre-Analysis Plugin" >>> description = "Enable extra analysis before core analysis." >>> properties = f'{{"title" : "{title}", "description" : "{description}", "type" : "boolean", "default" : false}}' >>> my_settings.register_group("myPlugin", "My Plugin") True >>> my_settings.register_setting("myPlugin.enablePreAnalysis", properties) True >>> my_bv = load("/bin/ls", options={'myPlugin.enablePreAnalysis' : True}) >>> Settings().get_bool("myPlugin.enablePreAnalysis") False >>> Settings().get_bool("myPlugin.enablePreAnalysis", my_bv) True
Example UI plugin setting:
>>> my_settings = Settings() >>> title = "My UI Plugin" >>> description = "Enable My UI Plugin table display." >>> properties = f'{{"title" : "{title}", "description" : "{description}", "type" : "boolean", "default" : true, "ignore" : ["SettingsProjectScope", "SettingsResourceScope"]}}' >>> my_settings.register_group("myPlugin", "My Plugin") True >>> my_settings.register_setting("myPlugin.enableTableView", properties) True >>> my_bv = load("/bin/ls", options={'myPlugin.enableTableView' : True}) >>> Settings().get_bool("myPlugin.enableTableView") True
- Parameters:
instance_id (str | None) –
- contains(key: str) bool [source]¶
contains
determine if a setting identifier exists in the active settings schema
- deserialize_schema(schema: str, scope: SettingsScope = SettingsScope.SettingsAutoScope, merge: bool = True) bool [source]¶
- Parameters:
schema (str) –
scope (SettingsScope) –
merge (bool) –
- Return type:
- deserialize_settings(contents: str, resource: BinaryView | Function | None = None, scope: SettingsScope = SettingsScope.SettingsAutoScope) bool [source]¶
- Parameters:
contents (str) –
resource (BinaryView | Function | None) –
scope (SettingsScope) –
- Return type:
- get_bool(key: str, resource: BinaryView | Function | None = None) bool [source]¶
- Parameters:
key (str) –
resource (BinaryView | Function | None) –
- Return type:
- get_bool_with_scope(key: str, resource: ~binaryninja.binaryview.BinaryView | ~binaryninja.function.Function | None = None, scope: ~binaryninja.enums.SettingsScope = SettingsScope.SettingsAutoScope) -> (<class 'bool'>, <enum 'SettingsScope'>)[source]¶
- Parameters:
key (str) –
resource (BinaryView | Function | None) –
scope (SettingsScope) –
- Return type:
(<class ‘bool’>, <enum ‘SettingsScope’>)
- get_double(key: str, resource: BinaryView | Function | None = None) float [source]¶
- Parameters:
key (str) –
resource (BinaryView | Function | None) –
- Return type:
- get_double_with_scope(key: str, resource: ~binaryninja.binaryview.BinaryView | ~binaryninja.function.Function | None = None, scope: ~binaryninja.enums.SettingsScope = SettingsScope.SettingsAutoScope) -> (<class 'float'>, <enum 'SettingsScope'>)[source]¶
- Parameters:
key (str) –
resource (BinaryView | Function | None) –
scope (SettingsScope) –
- Return type:
(<class ‘float’>, <enum ‘SettingsScope’>)
- get_integer(key: str, resource: BinaryView | Function | None = None) int [source]¶
- Parameters:
key (str) –
resource (BinaryView | Function | None) –
- Return type:
- get_integer_with_scope(key: str, resource: ~binaryninja.binaryview.BinaryView | ~binaryninja.function.Function | None = None, scope: ~binaryninja.enums.SettingsScope = SettingsScope.SettingsAutoScope) -> (<class 'int'>, <enum 'SettingsScope'>)[source]¶
- Parameters:
key (str) –
resource (BinaryView | Function | None) –
scope (SettingsScope) –
- Return type:
(<class ‘int’>, <enum ‘SettingsScope’>)
- get_json(key: str, resource: BinaryView | Function | None = None) str [source]¶
- Parameters:
key (str) –
resource (BinaryView | Function | None) –
- Return type:
- get_json_with_scope(key: str, resource: ~binaryninja.binaryview.BinaryView | ~binaryninja.function.Function | None = None, scope: ~binaryninja.enums.SettingsScope = SettingsScope.SettingsAutoScope) -> (<class 'str'>, <enum 'SettingsScope'>)[source]¶
- Parameters:
key (str) –
resource (BinaryView | Function | None) –
scope (SettingsScope) –
- Return type:
(<class ‘str’>, <enum ‘SettingsScope’>)
- get_string(key: str, resource: BinaryView | Function | None = None) str [source]¶
- Parameters:
key (str) –
resource (BinaryView | Function | None) –
- Return type:
- get_string_list(key: str, resource: BinaryView | Function | None = None) List[str] [source]¶
- Parameters:
key (str) –
resource (BinaryView | Function | None) –
- Return type:
- get_string_list_with_scope(key: str, resource: ~binaryninja.binaryview.BinaryView | ~binaryninja.function.Function | None = None, scope: ~binaryninja.enums.SettingsScope = SettingsScope.SettingsAutoScope) -> (typing.List[str], <enum 'SettingsScope'>)[source]¶
- Parameters:
key (str) –
resource (BinaryView | Function | None) –
scope (SettingsScope) –
- Return type:
- get_string_with_scope(key: str, resource: ~binaryninja.binaryview.BinaryView | ~binaryninja.function.Function | None = None, scope: ~binaryninja.enums.SettingsScope = SettingsScope.SettingsAutoScope) -> (<class 'str'>, <enum 'SettingsScope'>)[source]¶
- Parameters:
key (str) –
resource (BinaryView | Function | None) –
scope (SettingsScope) –
- Return type:
(<class ‘str’>, <enum ‘SettingsScope’>)
- is_empty() bool [source]¶
is_empty
determine if the active settings schema is empty- Returns:
True if the active settings schema is empty, False otherwise
- Return type:
- keys() List[str] [source]¶
keys
retrieve the list of setting identifiers in the active settings schema
- load_settings_file(filename: str = '', scope: SettingsScope = SettingsScope.SettingsAutoScope, view: BinaryView | None = None) bool [source]¶
- Parameters:
filename (str) –
scope (SettingsScope) –
view (BinaryView | None) –
- Return type:
- register_group(group: str, title: str) bool [source]¶
register_group
registers a group in the schema for thisSettings
instance
- register_setting(key: str, properties: str) bool [source]¶
register_setting
registers a new setting with thisSettings
instance- Parameters:
- Returns:
True on success, False on failure.
- Return type:
- Example:
>>> Settings().register_group("solver", "Solver") True >>> Settings().register_setting("solver.basicBlockSlicing", '{"description" : "Enable the basic block slicing in the solver.", "title" : "Basic Block Slicing", "default" : true, "type" : "boolean"}') True
- reset(key: str, resource: BinaryView | Function | None = None, scope: SettingsScope = SettingsScope.SettingsAutoScope) bool [source]¶
- Parameters:
key (str) –
resource (BinaryView | Function | None) –
scope (SettingsScope) –
- Return type:
- reset_all(resource: BinaryView | Function | None = None, scope: SettingsScope = SettingsScope.SettingsAutoScope, schema_only=True) bool [source]¶
- Parameters:
resource (BinaryView | Function | None) –
scope (SettingsScope) –
- Return type:
- serialize_settings(resource: BinaryView | Function | None = None, scope: SettingsScope = SettingsScope.SettingsAutoScope) str [source]¶
- Parameters:
resource (BinaryView | Function | None) –
scope (SettingsScope) –
- Return type:
- set_bool(key: str, value: bool, resource: BinaryView | Function | None = None, scope: SettingsScope = SettingsScope.SettingsAutoScope) bool [source]¶
- Parameters:
key (str) –
value (bool) –
resource (BinaryView | Function | None) –
scope (SettingsScope) –
- Return type:
- set_double(key: str, value: float, resource: BinaryView | Function | None = None, scope: SettingsScope = SettingsScope.SettingsAutoScope) bool [source]¶
- Parameters:
key (str) –
value (float) –
resource (BinaryView | Function | None) –
scope (SettingsScope) –
- Return type:
- set_integer(key: str, value: int, resource: BinaryView | Function | None = None, scope: SettingsScope = SettingsScope.SettingsAutoScope) bool [source]¶
- Parameters:
key (str) –
value (int) –
resource (BinaryView | Function | None) –
scope (SettingsScope) –
- Return type:
- set_json(key: str, value: str, resource: BinaryView | Function | None = None, scope: SettingsScope = SettingsScope.SettingsAutoScope) bool [source]¶
- Parameters:
key (str) –
value (str) –
resource (BinaryView | Function | None) –
scope (SettingsScope) –
- Return type:
- set_resource_id(resource_id: str = '')[source]¶
set_resource_id
Sets the resource identifier for this class:Settings instance. When accessing setting values at theSettingsResourceScope
level, the resource identifier is passed along through the backing store interface.Note
Currently the only available backing store for
SettingsResourceScope
is aBinaryView
object. In the context of aBinaryView
the resource identifier is theBinaryViewType
name. 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 duringBinaryView
creation and initialization.- Parameters:
resource_id (str) – a unique identifier
- Return type:
None
- set_string(key: str, value: str, resource: BinaryView | Function | None = None, scope: SettingsScope = SettingsScope.SettingsAutoScope) bool [source]¶
- Parameters:
key (str) –
value (str) –
resource (BinaryView | Function | None) –
scope (SettingsScope) –
- Return type:
- set_string_list(key: str, value: List[str], resource: BinaryView | Function | None = None, scope: SettingsScope = SettingsScope.SettingsAutoScope) bool [source]¶
- Parameters:
key (str) –
resource (BinaryView | Function | None) –
scope (SettingsScope) –
- Return type:
- default_handle = <binaryninja._binaryninjacore.LP_BNSettings object>¶