summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--binaryninjaapi.h2
-rw-r--r--binaryninjacore.h2
-rw-r--r--python/binaryview.py5
-rw-r--r--python/settings.py21
-rw-r--r--settings.cpp24
5 files changed, 53 insertions, 1 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 20db0aef..7e18a259 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -4537,6 +4537,7 @@ namespace BinaryNinja
bool RegisterSetting(const std::string& key, const std::string& properties);
bool Contains(const std::string& key);
bool IsEmpty();
+ std::vector<std::string> Keys();
template<typename T> T QueryProperty(const std::string& key, const std::string& property);
@@ -4560,6 +4561,7 @@ namespace BinaryNinja
bool ResetAll(Ref<BinaryView> view = nullptr, BNSettingsScope scope = SettingsAutoScope);
template<typename T> T Get(const std::string& key, Ref<BinaryView> view = nullptr, BNSettingsScope* scope = nullptr);
+ std::string GetJson(const std::string& key, Ref<BinaryView> view = nullptr, BNSettingsScope* scope = nullptr);
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);
diff --git a/binaryninjacore.h b/binaryninjacore.h
index 852e2a7e..1bf9b6c0 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -3945,6 +3945,7 @@ extern "C"
BINARYNINJACOREAPI bool BNSettingsRegisterSetting(BNSettings* settings, const char* key, const char* properties);
BINARYNINJACOREAPI bool BNSettingsContains(BNSettings* settings, const char* key);
BINARYNINJACOREAPI bool BNSettingsIsEmpty(BNSettings* settings);
+ BINARYNINJACOREAPI const char** BNSettingsKeysList(BNSettings* settings, size_t* inoutSize);
BINARYNINJACOREAPI const char** BNSettingsQueryPropertyStringList(BNSettings* settings, const char* key, const char* property, size_t* inoutSize);
BINARYNINJACOREAPI bool BNSettingsUpdateProperty(BNSettings* settings, const char* key, const char* property);
BINARYNINJACOREAPI bool BNSettingsUpdateBoolProperty(BNSettings* settings, const char* key, const char* property, bool value);
@@ -3969,6 +3970,7 @@ extern "C"
BINARYNINJACOREAPI uint64_t BNSettingsGetUInt64(BNSettings* settings, const char* key, BNBinaryView* view, BNSettingsScope* scope);
BINARYNINJACOREAPI char* BNSettingsGetString(BNSettings* settings, const char* key, BNBinaryView* view, BNSettingsScope* scope);
BINARYNINJACOREAPI const char** BNSettingsGetStringList(BNSettings* settings, const char* key, BNBinaryView* view, BNSettingsScope* scope, size_t* inoutSize);
+ BINARYNINJACOREAPI char* BNSettingsGetJsonString(BNSettings* settings, const char* key, BNBinaryView* view, BNSettingsScope* scope);
BINARYNINJACOREAPI bool BNSettingsSetBool(BNSettings* settings, BNBinaryView* view, BNSettingsScope scope, const char* key, bool value);
BINARYNINJACOREAPI bool BNSettingsSetDouble(BNSettings* settings, BNBinaryView* view, BNSettingsScope scope, const char* key, double value);
diff --git a/python/binaryview.py b/python/binaryview.py
index a6bb6882..c5d9c363 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -687,7 +687,10 @@ class BinaryViewType(with_metaclass(_BinaryViewTypeMetaclass, object)):
return settings.Settings(handle=load_settings)
def get_load_settings_for_data(self, data):
- load_settings = core.BNGetBinaryViewLoadSettingsForData(self.handle, data.handle)
+ view_handle = None
+ if data is not None:
+ view_handle = data.handle
+ load_settings = core.BNGetBinaryViewLoadSettingsForData(self.handle, view_handle)
if load_settings is None:
return None
return settings.Settings(handle=load_settings)
diff --git a/python/settings.py b/python/settings.py
index 95501622..66f84fe9 100644
--- a/python/settings.py
+++ b/python/settings.py
@@ -111,6 +111,15 @@ class Settings(object):
def is_empty(self):
return core.BNSettingsIsEmpty(self.handle)
+ def keys(self):
+ length = ctypes.c_ulonglong()
+ result = core.BNSettingsKeysList(self.handle, 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 query_property_string_list(self, key, property_name):
length = ctypes.c_ulonglong()
result = core.BNSettingsQueryPropertyStringList(self.handle, key, property_name, ctypes.byref(length))
@@ -173,6 +182,11 @@ class Settings(object):
core.BNFreeStringList(result, length)
return out_list
+ def get_json(self, key, view = None):
+ if view is not None:
+ view = view.handle
+ return core.BNSettingsGetJsonString(self.handle, key, view, None)
+
def get_bool_with_scope(self, key, view = None, scope = SettingsScope.SettingsAutoScope):
if view is not None:
view = view.handle
@@ -213,6 +227,13 @@ class Settings(object):
core.BNFreeStringList(result, length)
return (out_list, SettingsScope(c_scope.value))
+ def get_json_with_scope(self, key, view = None, scope = SettingsScope.SettingsAutoScope):
+ if view is not None:
+ view = view.handle
+ c_scope = core.SettingsScopeEnum(scope)
+ result = core.BNSettingsGetJsonString(self.handle, key, view, ctypes.byref(c_scope))
+ return (result, SettingsScope(c_scope.value))
+
def set_bool(self, key, value, view = None, scope = SettingsScope.SettingsAutoScope):
if view is not None:
view = view.handle
diff --git a/settings.cpp b/settings.cpp
index fdc74335..46119905 100644
--- a/settings.cpp
+++ b/settings.cpp
@@ -58,6 +58,21 @@ bool Settings::IsEmpty()
}
+vector<string> Settings::Keys()
+{
+ size_t size = 0;
+ char** outBuffer = (char**)BNSettingsKeysList(m_object, &size);
+
+ vector<string> result;
+ result.reserve(size);
+ for (size_t i = 0; i < size; i++)
+ result.emplace_back(outBuffer[i]);
+
+ BNFreeStringList(outBuffer, size);
+ return result;
+}
+
+
template<> vector<string> Settings::QueryProperty<vector<string>>(const string& key, const string& property)
{
size_t size = 0;
@@ -232,6 +247,15 @@ template<> vector<string> Settings::Get<vector<string>>(const string& key, Ref<B
}
+string Settings::GetJson(const string& key, Ref<BinaryView> view, BNSettingsScope* scope)
+{
+ char* tmpStr = BNSettingsGetJsonString(m_object, key.c_str(), view ? view->GetObject() : nullptr, scope);
+ string result(tmpStr);
+ BNFreeString(tmpStr);
+ return result;
+}
+
+
bool Settings::Set(const string& key, bool value, Ref<BinaryView> view, BNSettingsScope scope)
{
return BNSettingsSetBool(m_object, view ? view->GetObject() : nullptr, scope, key.c_str(), value);