summaryrefslogtreecommitdiff
path: root/settings.cpp
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 /settings.cpp
parente01f0e0fe635c0fe703fbdd09d44a5d7da7c4b93 (diff)
Initial Enhanced Settings System.
Diffstat (limited to 'settings.cpp')
-rw-r--r--settings.cpp227
1 files changed, 128 insertions, 99 deletions
diff --git a/settings.cpp b/settings.cpp
index ca1e42a3..62425f5b 100644
--- a/settings.cpp
+++ b/settings.cpp
@@ -1,178 +1,207 @@
#include "binaryninjaapi.h"
+#include "json/json.h"
#include <string.h>
using namespace BinaryNinja;
using namespace std;
-bool Setting::GetBool(const std::string& pluginName, const std::string& name, bool defaultValue)
+bool Settings::RegisterGroup(const string& group, const string& title)
{
- return BNSettingGetBool(pluginName.c_str(), name.c_str(), defaultValue);
+ return BNSettingsRegisterGroup(m_registry.c_str(), group.c_str(), title.c_str());
}
-int64_t Setting::GetInteger(const std::string& pluginName, const std::string& name, int64_t defaultValue)
+
+bool Settings::RegisterSetting(const string& id, const string& properties)
{
- return BNSettingGetInteger(pluginName.c_str(), name.c_str(), defaultValue);
+ return BNSettingsRegisterSetting(m_registry.c_str(), id.c_str(), properties.c_str());
}
-std::string Setting::GetString(const std::string& pluginName, const std::string& name, const std::string& defaultValue)
+
+bool Settings::UpdateProperty(const std::string& id, const std::string& property)
{
- char* str = BNSettingGetString(pluginName.c_str(), name.c_str(), defaultValue.c_str());
- string result(str);
- BNFreeString(str);
- return result;
+ return BNSettingsUpdateProperty(m_registry.c_str(), id.c_str(), property.c_str());
}
-double Setting::GetDouble(const std::string& pluginName, const std::string& name, double defaultValue)
+
+bool Settings::UpdateProperty(const std::string& id, const std::string& property, bool value)
{
- return BNSettingGetDouble(pluginName.c_str(), name.c_str(), defaultValue);
+ return BNSettingsUpdateBoolProperty(m_registry.c_str(), id.c_str(), property.c_str(), value);
}
-std::vector<int64_t> Setting::GetIntegerList(const std::string& pluginName,
- const std::string& name,
- const std::vector<int64_t>& defaultValue)
+
+bool Settings::UpdateProperty(const std::string& id, const std::string& property, double value)
{
- int64_t* buffer = new int64_t[defaultValue.size()];
- memcpy(&buffer[0], &defaultValue[0], sizeof(int64_t) * defaultValue.size());
- size_t size = defaultValue.size();
- int64_t* outBuffer = BNSettingGetIntegerList(pluginName.c_str(), name.c_str(), buffer, &size);
- delete[] buffer;
+ return BNSettingsUpdateDoubleProperty(m_registry.c_str(), id.c_str(), property.c_str(), value);
+}
+
- vector<int64_t> out(outBuffer, outBuffer + size);
- BNFreeSettingIntegerList(outBuffer);
- return out;
+bool Settings::UpdateProperty(const std::string& id, const std::string& property, int value)
+{
+ return BNSettingsUpdateInt64Property(m_registry.c_str(), id.c_str(), property.c_str(), value);
}
-std::vector<std::string> Setting::GetStringList(const std::string& pluginName,
- const std::string& name,
- const std::vector<std::string>& defaultValue)
+
+bool Settings::UpdateProperty(const std::string& id, const std::string& property, int64_t value)
{
- char** buffer = new char*[defaultValue.size()];
- for (size_t i = 0; i < defaultValue.size(); i++)
- buffer[i] = BNAllocString(defaultValue[i].c_str());
- size_t size = defaultValue.size();
- char** outBuffer = (char**)BNSettingGetStringList(pluginName.c_str(), name.c_str(), (const char**)buffer, &size);
+ return BNSettingsUpdateInt64Property(m_registry.c_str(), id.c_str(), property.c_str(), value);
+}
- vector<string> result;
- result.reserve(size);
- for (size_t i = 0; i < size; i++)
- result.emplace_back(outBuffer[i]);
- for (size_t i = 0; i < defaultValue.size(); i++)
- BNFreeString(buffer[i]);
- delete[] buffer;
- BNFreeStringList(outBuffer, size);
- return result;
+bool Settings::UpdateProperty(const std::string& id, const std::string& property, uint64_t value)
+{
+ return BNSettingsUpdateUInt64Property(m_registry.c_str(), id.c_str(), property.c_str(), value);
}
-bool Setting::IsPresent(const std::string& pluginName, const std::string& name)
+bool Settings::UpdateProperty(const std::string& id, const std::string& property, const char* value)
{
- return BNSettingIsPresent(pluginName.c_str(), name.c_str());
+ return BNSettingsUpdateStringProperty(m_registry.c_str(), id.c_str(), property.c_str(), value);
}
-bool Setting::IsBool(const std::string& pluginName, const std::string& name)
+
+bool Settings::UpdateProperty(const std::string& id, const std::string& property, const std::string& value)
{
- return BNSettingIsBool(pluginName.c_str(), name.c_str());
+ return BNSettingsUpdateStringProperty(m_registry.c_str(), id.c_str(), property.c_str(), value.c_str());
}
-bool Setting::IsInteger(const std::string& pluginName, const std::string& name)
+
+bool Settings::UpdateProperty(const std::string& id, const std::string& property, const std::vector<std::string>& value)
{
- return BNSettingIsInteger(pluginName.c_str(), name.c_str());
+ char** buffer = new char*[value.size()];
+ if (!buffer)
+ return false;
+
+ for (size_t i = 0; i < value.size(); i++)
+ buffer[i] = BNAllocString(value[i].c_str());
+
+ bool result = BNSettingsUpdateStringListProperty(m_registry.c_str(), id.c_str(), property.c_str(), (const char**)buffer, value.size());
+ BNFreeStringList(buffer, value.size());
+ return result;
}
-bool Setting::IsString(const std::string& pluginName, const std::string& name)
+
+string Settings::GetSchema()
{
- return BNSettingIsString(pluginName.c_str(), name.c_str());
+ char* schemaStr = BNSettingsGetSchema(m_registry.c_str());
+ string schema(schemaStr);
+ BNFreeString(schemaStr);
+ return schema;
}
-bool Setting::IsIntegerList(const std::string& pluginName, const std::string& name)
+
+bool Settings::Reset(const string& id, Ref<BinaryView> view, BNSettingsScope scope)
{
- return BNSettingIsIntegerList(pluginName.c_str(), name.c_str());
+ return BNSettingsReset(m_registry.c_str(), id.c_str(), view ? view->GetObject() : nullptr, scope);
}
-bool Setting::IsStringList(const std::string& pluginName, const std::string& name)
+
+bool Settings::ResetAll(Ref<BinaryView> view, BNSettingsScope scope)
{
- return BNSettingIsStringList(pluginName.c_str(), name.c_str());
+ return BNSettingsResetAll(m_registry.c_str(), view ? view->GetObject() : nullptr, scope);
}
-bool Setting::IsDouble(const std::string& pluginName, const std::string& name)
+
+template<> bool Settings::Get<bool>(const string& id, Ref<BinaryView> view, BNSettingsScope* scope)
{
- return BNSettingIsDouble(pluginName.c_str(), name.c_str());
+ return BNSettingsGetBool(m_registry.c_str(), id.c_str(), view ? view->GetObject() : nullptr, scope);
}
-bool Setting::Set(const std::string& settingGroup,
- const std::string& name,
- bool value,
- bool autoFlush)
+
+template<> double Settings::Get<double>(const string& id, Ref<BinaryView> view, BNSettingsScope* scope)
{
- return BNSettingSetBool(settingGroup.c_str(), name.c_str(), value, autoFlush);
+ return BNSettingsGetDouble(m_registry.c_str(), id.c_str(), view ? view->GetObject() : nullptr, scope);
}
-bool Setting::Set(const std::string& settingGroup,
- const std::string& name,
- int64_t value,
- bool autoFlush)
+
+template<> int64_t Settings::Get<int64_t>(const string& id, Ref<BinaryView> view, BNSettingsScope* scope)
{
- return BNSettingSetInteger(settingGroup.c_str(), name.c_str(), value, autoFlush);
+ return BNSettingsGetInt64(m_registry.c_str(), id.c_str(), view ? view->GetObject() : nullptr, scope);
}
-bool Setting::Set(const std::string& settingGroup,
- const std::string& name,
- const std::string& value,
- bool autoFlush)
+
+template<> uint64_t Settings::Get<uint64_t>(const string& id, Ref<BinaryView> view, BNSettingsScope* scope)
{
- return BNSettingSetString(settingGroup.c_str(), name.c_str(), value.c_str(), autoFlush);
+ return BNSettingsGetUInt64(m_registry.c_str(), id.c_str(), view ? view->GetObject() : nullptr, scope);
}
-bool Setting::Set(const std::string& settingGroup,
- const std::string& name,
- const std::vector<int64_t>& value,
- bool autoFlush)
+
+template<> string Settings::Get<string>(const string& id, Ref<BinaryView> view, BNSettingsScope* scope)
{
- return BNSettingSetIntegerList(settingGroup.c_str(), name.c_str(), &value[0], value.size(), autoFlush);
+ char* tmpStr = BNSettingsGetString(m_registry.c_str(), id.c_str(), view ? view->GetObject() : nullptr, scope);
+ string result(tmpStr);
+ BNFreeString(tmpStr);
+ return result;
}
-bool Setting::Set(const std::string& settingGroup,
- const std::string& name,
- const std::vector<std::string>& value,
- bool autoFlush)
+
+template<> vector<string> Settings::Get<vector<string>>(const string& id, Ref<BinaryView> view, BNSettingsScope* scope)
{
- char** buffer = new char*[value.size()];
- if (!buffer)
- return false;
- for (size_t i = 0; i < value.size(); i++)
- buffer[i] = BNAllocString(value[i].c_str());
+ size_t size = 0;
+ char** outBuffer = (char**)BNSettingsGetStringList(m_registry.c_str(), id.c_str(), view ? view->GetObject() : nullptr, scope, &size);
- bool result = BNSettingSetStringList(settingGroup.c_str(),
- name.c_str(),
- (const char**)buffer,
- value.size(),
- autoFlush);
+ vector<string> result;
+ result.reserve(size);
+ for (size_t i = 0; i < size; i++)
+ result.emplace_back(outBuffer[i]);
- BNFreeStringList(buffer, value.size());
+ BNFreeStringList(outBuffer, size);
return result;
}
-bool Setting::Set(const std::string& settingGroup,
- const std::string& name,
- double value,
- bool autoFlush)
+
+bool Settings::Set(const string& id, bool value, Ref<BinaryView> view, BNSettingsScope scope)
+{
+ return BNSettingsSetBool(m_registry.c_str(), view ? view->GetObject() : nullptr, scope, id.c_str(), value);
+}
+
+
+bool Settings::Set(const string& id, double value, Ref<BinaryView> view, BNSettingsScope scope)
{
- return BNSettingSetDouble(settingGroup.c_str(), name.c_str(), value, autoFlush);
+ return BNSettingsSetDouble(m_registry.c_str(), view ? view->GetObject() : nullptr, scope, id.c_str(), value);
}
-bool Setting::RemoveSettingGroup(const std::string& settingGroup, bool autoFlush)
+
+bool Settings::Set(const string& id, int value, Ref<BinaryView> view, BNSettingsScope scope)
{
- return BNSettingRemoveSettingGroup(settingGroup.c_str(), autoFlush);
+ return BNSettingsSetInt64(m_registry.c_str(), view ? view->GetObject() : nullptr, scope, id.c_str(), value);
}
-bool Setting::RemoveSetting(const std::string& settingGroup, const std::string& setting, bool autoFlush)
+
+bool Settings::Set(const string& id, int64_t value, Ref<BinaryView> view, BNSettingsScope scope)
{
- return BNSettingRemoveSetting(settingGroup.c_str(), setting.c_str(), autoFlush);
+ return BNSettingsSetInt64(m_registry.c_str(), view ? view->GetObject() : nullptr, scope, id.c_str(), value);
}
-bool Setting::FlushSettings()
+
+bool Settings::Set(const string& id, uint64_t value, Ref<BinaryView> view, BNSettingsScope scope)
{
- return BNSettingFlushSettings();
+ return BNSettingsSetUInt64(m_registry.c_str(), view ? view->GetObject() : nullptr, scope, id.c_str(), value);
+}
+
+
+bool Settings::Set(const string& id, const char* value, Ref<BinaryView> view, BNSettingsScope scope)
+{
+ return BNSettingsSetString(m_registry.c_str(), view ? view->GetObject() : nullptr, scope, id.c_str(), value);
+}
+
+
+bool Settings::Set(const string& id, const string& value, Ref<BinaryView> view, BNSettingsScope scope)
+{
+ return BNSettingsSetString(m_registry.c_str(), view ? view->GetObject() : nullptr, scope, id.c_str(), value.c_str());
+}
+
+
+bool Settings::Set(const string& id, const vector<string>& value, Ref<BinaryView> view, BNSettingsScope scope)
+{
+ char** buffer = new char*[value.size()];
+ if (!buffer)
+ return false;
+
+ for (size_t i = 0; i < value.size(); i++)
+ buffer[i] = BNAllocString(value[i].c_str());
+
+ bool result = BNSettingsSetStringList(m_registry.c_str(), view ? view->GetObject() : nullptr, scope, id.c_str(), (const char**)buffer, value.size());
+ BNFreeStringList(buffer, value.size());
+ return result;
}