summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorBrian Potchik <brian@vector35.com>2018-10-14 22:47:22 -0400
committerBrian Potchik <brian@vector35.com>2018-10-18 17:50:25 -0400
commit80cb1f68c83112c4d99893ad2f23bf22abdc4a6d (patch)
tree9ebd185b5d61fedccfd811d5b4a4720a1f669da0 /python
parente01f0e0fe635c0fe703fbdd09d44a5d7da7c4b93 (diff)
Initial Enhanced Settings System.
Diffstat (limited to 'python')
-rw-r--r--python/__init__.py2
-rw-r--r--python/downloadprovider.py10
-rw-r--r--python/setting.py145
-rw-r--r--python/settings.py174
4 files changed, 180 insertions, 151 deletions
diff --git a/python/__init__.py b/python/__init__.py
index 9f8cbc79..2c6cb311 100644
--- a/python/__init__.py
+++ b/python/__init__.py
@@ -125,7 +125,7 @@ from binaryninja.highlight import *
from binaryninja.scriptingprovider import *
from binaryninja.downloadprovider import *
from binaryninja.pluginmanager import *
-from binaryninja.setting import *
+from binaryninja.settings import *
from binaryninja.metadata import *
from binaryninja.flowgraph import *
diff --git a/python/downloadprovider.py b/python/downloadprovider.py
index b619b40c..5ce8cfce 100644
--- a/python/downloadprovider.py
+++ b/python/downloadprovider.py
@@ -28,7 +28,7 @@ import traceback
import binaryninja._binaryninjacore as core
import binaryninja
-from binaryninja.setting import Setting
+from binaryninja.settings import Settings
from binaryninja import with_metaclass
from binaryninja import startup
from binaryninja import log
@@ -171,7 +171,7 @@ if (sys.platform != "win32") and (sys.version_info >= (2, 7, 9)):
@abc.abstractmethod
def perform_request(self, url):
try:
- proxy_setting = Setting('download-client').get_string('https-proxy')
+ proxy_setting = Settings().get_string('downloadClient.httpsProxy')
if proxy_setting:
opener = build_opener(ProxyHandler({'https': proxy_setting}))
install_opener(opener)
@@ -209,7 +209,7 @@ if (sys.platform != "win32") and (sys.version_info >= (2, 7, 9)):
return 0
class PythonDownloadProvider(DownloadProvider):
- name = "DefaultDownloadProvider"
+ name = "PythonDownloadProvider"
instance_class = PythonDownloadInstance
PythonDownloadProvider().register()
@@ -229,7 +229,7 @@ else:
@abc.abstractmethod
def perform_request(self, url):
try:
- proxy_setting = Setting('download-client').get_string('https-proxy')
+ proxy_setting = Settings().get_string('downloadClient.httpsProxy')
if proxy_setting:
proxies = {"https": proxy_setting}
else:
@@ -263,7 +263,7 @@ else:
return 0
class PythonDownloadProvider(DownloadProvider):
- name = "DefaultDownloadProvider"
+ name = "PythonDownloadProvider"
instance_class = PythonDownloadInstance
PythonDownloadProvider().register()
diff --git a/python/setting.py b/python/setting.py
deleted file mode 100644
index 93f6b72a..00000000
--- a/python/setting.py
+++ /dev/null
@@ -1,145 +0,0 @@
-# Copyright (c) 2015-2017 Vector 35 LLC
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to
-# deal in the Software without restriction, including without limitation the
-# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
-# sell copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-# IN THE SOFTWARE.
-
-import ctypes
-
-# Binary Ninja components
-from binaryninja import _binaryninjacore as core
-
-# 2-3 compatibility
-from binaryninja import range
-from binaryninja import pyNativeStr
-
-
-class Setting(object):
- def __init__(self, plugin_name="core"):
- self.plugin_name = plugin_name
-
- def get_bool(self, name, default_value=False):
- return core.BNSettingGetBool(self.plugin_name, name, default_value)
-
- def get_integer(self, name, default_value=0):
- return core.BNSettingGetInteger(self.plugin_name, name, default_value)
-
- def get_string(self, name, default_value=""):
- return core.BNSettingGetString(self.plugin_name, name, default_value)
-
- def get_integer_list(self, name, default_value=[]):
- length = ctypes.c_ulonglong()
- length.value = len(default_value)
- default_list = (ctypes.c_longlong * len(default_value))()
- for i in range(len(default_value)):
- default_list[i] = default_value[i]
- result = core.BNSettingGetIntegerList(self.plugin_name, name, default_list, ctypes.byref(length))
- out_list = []
- for i in range(length.value):
- out_list.append(result[i])
- core.BNFreeSettingIntegerList(result)
- return out_list
-
- def get_string_list(self, name, default_value=[]):
- length = ctypes.c_ulonglong()
- length.value = len(default_value)
- default_list = (ctypes.c_char_p * len(default_value))()
- for i in range(len(default_value)):
- default_list[i] = default_value[i].encode('charmap')
- result = core.BNSettingGetStringList(self.plugin_name, name, default_list, ctypes.byref(length))
- out_list = []
- for i in range(length.value):
- out_list.append(pyNativeStr(result[i]))
- core.BNFreeStringList(result, length)
- return out_list
-
- def get_double(self, name, default_value=0.0):
- return core.BNSettingGetDouble(self.plugin_name, name, default_value)
-
- def is_bool(self, name):
- return core.BNSettingIsBool(self.plugin_name, name)
-
- def is_integer(self, name):
- return core.BNSettingIsInteger(self.plugin_name, name)
-
- def is_string(self, name):
- return core.BNSettingIsString(self.plugin_name, name)
-
- def is_string_list(self, name):
- return core.BNSettingIsStringList(self.plugin_name, name)
-
- def is_integer_list(self, name):
- return core.BNSettingIsIntegerList(self.plugin_name, name)
-
- def is_double(self, name):
- return core.BNSettingIsDouble(self.plugin_name, name)
-
- def is_present(self, name):
- return core.BNSettingIsPresent(self.plugin_name, name)
-
- def set_bool(self, name, value, auto_flush=True):
- return core.BNSettingSetBool(self.plugin_name, name, value, auto_flush)
-
- def set_integer(self, name, value, auto_flush=True):
- return core.BNSettingSetInteger(self.plugin_name, name, value, auto_flush)
-
- def set_string(self, name, value, auto_flush=True):
- return core.BNSettingSetString(self.plugin_name, name, value, auto_flush)
-
- def set_integer_list(self, name, value, auto_flush=True):
- length = ctypes.c_ulonglong()
- length.value = len(value)
- default_list = (ctypes.c_longlong * len(value))()
- for i in range(len(value)):
- default_list[i] = value[i]
-
- return core.BNSettingSetIntegerList(self.plugin_name, name, default_list, length, auto_flush)
-
- def set_string_list(self, name, value, auto_flush=True):
- length = ctypes.c_ulonglong()
- length.value = len(value)
- default_list = (ctypes.c_char_p * len(value))()
- for i in range(len(value)):
- default_list[i] = value[i].encode('charmap')
-
- return core.BNSettingSetStringList(self.plugin_name, name, default_list, length, auto_flush)
-
- def set_double(self, name, value, auto_flush=True):
- return core.BNSettingSetDouble(self.plugin_name, name, value, auto_flush)
-
- def set(self, name, value, auto_flush=True):
- if isinstance(value, bool):
- return self.set_bool(name, value, auto_flush)
- elif isinstance(value, int):
- return self.set_integer(name, value, auto_flush)
- elif isinstance(value, str):
- return self.set_string(name, value, auto_flush)
- elif isinstance(value, list) and len(value) == 0:
- return self.set_integer_list(name, value, auto_flush)
- elif isinstance(value, list) and len(value) > 0 and isinstance(value[0], int):
- return self.set_integer_list(name, value, auto_flush)
- elif isinstance(value, list) and len(value) > 0 and isinstance(value[0], str):
- return self.set_string_list(name, value, auto_flush)
- elif isinstance(value, float):
- return self.set_double(name, value, auto_flush)
- raise ValueError("value is not one of (int, bool, float, str, [int], [str]) types")
-
- def remove_setting_group(self, auto_flush=True):
- core.BNSettingRemoveSettingGroup(self.plugin_name, auto_flush)
-
- def remove_setting(self, setting, auto_flush=True):
- core.BNSettingRemoveSetting(self.plugin_name, setting, auto_flush)
diff --git a/python/settings.py b/python/settings.py
new file mode 100644
index 00000000..ce7c140a
--- /dev/null
+++ b/python/settings.py
@@ -0,0 +1,174 @@
+# Copyright (c) 2015-2018 Vector 35 LLC
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
+
+import ctypes
+
+# Binary Ninja components
+from binaryninja import _binaryninjacore as core
+
+# 2-3 compatibility
+from binaryninja import range
+from binaryninja import pyNativeStr
+from binaryninja.enums import SettingsScope
+
+
+class Settings(object):
+ def __init__(self, registry_id = "default"):
+ self.registry_id = registry_id
+
+ def register_group(self, group, title):
+ """
+ ``register_group`` registers a group for use with this Settings registry. Groups provide a simple way to organize settings.
+
+ :param str group: a unique identifier
+ :param str title: a user friendly name appropriate for UI presentation
+ :return: True on success, False on falure.
+ :rtype: bool
+ :Example:
+
+ >>> Settings().register_group("solver", "Solver")
+ True
+ >>>
+ """
+ return core.BNSettingsRegisterGroup(self.registry_id, group, title)
+
+ def register_setting(self, id, properties):
+ """
+ ``register_setting`` registers a new setting with this Settings registry.
+
+ :param str id: a unique setting identifier in the form <group>.<id>
+ :param str properties: a JSON string describes the setting schema
+ :return: True on success, False on falure.
+ :rtype: bool
+ :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", "id" : "basicBlockSlicing"}')
+ True
+ """
+ return core.BNSettingsRegisterSetting(self.registry_id, id, properties)
+
+ def update_property(self, id, setting_property):
+ return core.BNSettingsUpdateProperty(self.registry_id, tr(), id, setting_property)
+
+ def get_schema(self):
+ return core.BNSettingsGetSchema(self.registry_id);
+
+ def reset(self, id, view = None, scope = SettingsScope.SettingsAutoScope):
+ if view is not None:
+ view = view.handle
+ return core.BNSettingsReset(self.registry_id, id, view, scope)
+
+ def reset_all(self, view = None, scope = SettingsScope.SettingsAutoScope):
+ if view is not None:
+ view = view.handle
+ return core.BNSettingsResetAll(self.registry_id, view, scope)
+
+ def get_bool(self, id, view = None):
+ if view is not None:
+ view = view.handle
+ return core.BNSettingsGetBool(self.registry_id, id, view, None)
+
+ def get_double(self, id, view = None):
+ if view is not None:
+ view = view.handle
+ return core.BNSettingsGetDouble(self.registry_id, id, view, None)
+
+ def get_integer(self, id, view = None):
+ if view is not None:
+ view = view.handle
+ return core.BNSettingsGetUInt64(self.registry_id, id, view, None)
+
+ def get_string(self, id, view = None):
+ if view is not None:
+ view = view.handle
+ return core.BNSettingsGetString(self.registry_id, id, view, None)
+
+ def get_string_list(self, id, view = None):
+ if view is not None:
+ view = view.handle
+ length = ctypes.c_ulonglong()
+ result = core.BNSettingsGetStringList(self.registry_id, id, view, None, ctypes.byref(length))
+ out_list = []
+ for i in range(length.value):
+ out_list.append(pyNativeStr(result[i]))
+ core.BNFreeStringList(result, length)
+ return out_list
+
+ def get_bool_with_scope(self, id, view = None, scope = SettingsScope.SettingsAutoScope):
+ if view is not None:
+ view = view.handle
+ c_scope = core.SettingsScopeEnum(scope)
+ result = core.BNSettingsGetBool(self.registry_id, id, view, ctypes.byref(c_scope))
+ return (result, SettingsScope(c_scope.value))
+
+ def get_double_with_scope(self, id, view = None, scope = SettingsScope.SettingsAutoScope):
+ if view is not None:
+ view = view.handle
+ c_scope = core.SettingsScopeEnum(scope)
+ result = core.BNSettingsGetDouble(self.registry_id, id, view, ctypes.byref(c_scope))
+ return (result, SettingsScope(c_scope.value))
+
+ def get_integer_with_scope(self, id, view = None, scope = SettingsScope.SettingsAutoScope):
+ if view is not None:
+ view = view.handle
+ c_scope = core.SettingsScopeEnum(scope)
+ result = core.BNSettingsGetUInt64(self.registry_id, id, view, ctypes.byref(c_scope))
+ return (result, SettingsScope(c_scope.value))
+
+ def get_string_with_scope(self, id, view = None, scope = SettingsScope.SettingsAutoScope):
+ if view is not None:
+ view = view.handle
+ c_scope = core.SettingsScopeEnum(scope)
+ result = core.BNSettingsGetString(self.registry_id, id, view, ctypes.byref(c_scope))
+ return (result, SettingsScope(c_scope.value))
+
+ def get_string_list_with_scope(self, id, view = None, scope = SettingsScope.SettingsAutoScope):
+ if view is not None:
+ view = view.handle
+ c_scope = core.SettingsScopeEnum(scope)
+ length = ctypes.c_ulonglong()
+ result = core.BNSettingsGetStringList(self.registry_id, id, view, ctypes.byref(c_scope), ctypes.byref(length))
+ out_list = []
+ for i in range(length.value):
+ out_list.append(pyNativeStr(result[i]))
+ core.BNFreeStringList(result, length)
+ return (out_list, SettingsScope(c_scope.value))
+
+ def set_bool(self, id, value, view = None, scope = SettingsScope.SettingsAutoScope):
+ return core.BNSettingsSetBool(self.registry_id, view, scope, id, value)
+
+ def set_double(self, id, value, view = None, scope = SettingsScope.SettingsAutoScope):
+ return core.BNSettingsSetDouble(self.registry_id, view, scope, id, value)
+
+ def set_integer(self, id, value, view = None, scope = SettingsScope.SettingsAutoScope):
+ return core.BNSettingsSetUInt64(self.registry_id, view, scope, id, value)
+
+ def set_string(self, id, value, view = None, scope = SettingsScope.SettingsAutoScope):
+ return core.BNSettingsSetString(self.registry_id, view, scope, id, value)
+
+ def set_string_list(self, id, value, view = None, scope = SettingsScope.SettingsAutoScope):
+ length = ctypes.c_ulonglong()
+ length.value = len(value)
+ string_list = (ctypes.c_char_p * len(value))()
+ for i in range(len(value)):
+ string_list[i] = value[i].encode('charmap')
+ return core.BNSettingsSetStringList(self.registry_id, view, scope, id, string_list, length)