From 0de62768c8afc5ca27576b59d4591ca8dbbd7cee Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Sat, 24 Jun 2017 01:33:04 -0400 Subject: Adding settings system apis, and binaryview metadata apis --- setting.cpp | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 setting.cpp (limited to 'setting.cpp') diff --git a/setting.cpp b/setting.cpp new file mode 100644 index 00000000..b1efdbae --- /dev/null +++ b/setting.cpp @@ -0,0 +1,162 @@ +#include "binaryninjaapi.h" + +using namespace BinaryNinja; +using namespace std; + + +bool Setting::ProcessMainSettingsFile() +{ + return BNProcessMainSettingsFile(); +} + +bool Setting::GetBool(const std::string& pluginName, const std::string& name, bool defaultValue) +{ + return BNSettingGetBool(pluginName.c_str(), name.c_str(), defaultValue); +} + +uint64_t Setting::GetInteger(const std::string& pluginName, const std::string& name, uint64_t defaultValue) +{ + return BNSettingGetInteger(pluginName.c_str(), name.c_str(), defaultValue); +} + +std::string Setting::GetString(const std::string& pluginName, const std::string& name, const std::string& defaultValue) +{ + return BNSettingGetString(pluginName.c_str(), name.c_str(), defaultValue.c_str()); +} + +double Setting::GetDouble(const std::string& pluginName, const std::string& name, double defaultValue) +{ + return BNSettingGetDouble(pluginName.c_str(), name.c_str(), defaultValue); +} + +std::vector Setting::GetIntegerList(const std::string& pluginName, const std::string& name, const std::vector& defaultValue) +{ + uint64_t* buffer = new uint64_t[defaultValue.size()]; + memcpy(&buffer[0], &defaultValue[0], sizeof(uint64_t) * defaultValue.size()); + size_t size = defaultValue.size(); + uint64_t* outBuffer = BNSettingGetIntegerList(pluginName.c_str(), name.c_str(), buffer, &size); + if (buffer == outBuffer) + return defaultValue; + + vector out(buffer, buffer + size); + delete[] buffer; + return out; +} + +std::vector Setting::GetStringList(const std::string& pluginName, const std::string& name, const std::vector& defaultValue) +{ + 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(); + const char** outBuffer = BNSettingGetStringList(pluginName.c_str(), name.c_str(), (const char**)buffer, &size); + if (buffer == outBuffer) + return defaultValue; + + vector out; + for (size_t i = 0; i < size; i++) + out.push_back(string(outBuffer[i])); + for (size_t i = 0; i < defaultValue.size(); i++) + BNFreeString(buffer[i]); + delete[] buffer; + return out; +} + + +bool Setting::IsPresent(const std::string& pluginName, const std::string& name) +{ + return BNSettingIsPresent(pluginName.c_str(), name.c_str()); +} + +bool Setting::IsBool(const std::string& pluginName, const std::string& name) +{ + return BNSettingIsBool(pluginName.c_str(), name.c_str()); +} + +bool Setting::IsInteger(const std::string& pluginName, const std::string& name) +{ + return BNSettingIsInteger(pluginName.c_str(), name.c_str()); +} + +bool Setting::IsString(const std::string& pluginName, const std::string& name) +{ + return BNSettingIsString(pluginName.c_str(), name.c_str()); +} + +bool Setting::IsIntegerList(const std::string& pluginName, const std::string& name) +{ + return BNSettingIsIntegerList(pluginName.c_str(), name.c_str()); +} + +bool Setting::IsStringList(const std::string& pluginName, const std::string& name) +{ + return BNSettingIsStringList(pluginName.c_str(), name.c_str()); +} + +bool Setting::IsDouble(const std::string& pluginName, const std::string& name) +{ + return BNSettingIsDouble(pluginName.c_str(), name.c_str()); +} + + + +bool CoreSetting::GetBool(const std::string& name, bool defaultValue) +{ + return BNSettingGetBool("core", name.c_str(), defaultValue); +} +uint64_t CoreSetting::GetInteger(const std::string& name, uint64_t defaultValue) +{ + return BNSettingGetInteger("core", name.c_str(), defaultValue); +} +std::string CoreSetting::GetString(const std::string& name, const std::string& defaultValue) +{ + return Setting::GetString("core", name.c_str(), defaultValue); +} +double CoreSetting::GetDouble(const std::string& name, double defaultValue) +{ + return BNSettingGetDouble("core", name.c_str(), defaultValue); +} +std::vector CoreSetting::GetIntegerList(const std::string& name, const std::vector& defaultValue) +{ + return Setting::GetIntegerList("core", name.c_str(), defaultValue); +} +std::vector CoreSetting::GetStringList(const std::string& name, const std::vector& defaultValue) +{ + return Setting::GetStringList("core", name.c_str(), defaultValue); +} + +bool CoreSetting::IsPresent(const std::string& name) +{ + return BNSettingIsPresent("core", name.c_str()); +} + +bool CoreSetting::IsBool(const std::string& name) +{ + return BNSettingIsBool("core", name.c_str()); +} + +bool CoreSetting::IsInteger(const std::string& name) +{ + return BNSettingIsInteger("core", name.c_str()); +} + +bool CoreSetting::IsString(const std::string& name) +{ + return BNSettingIsString("core", name.c_str()); +} + +bool CoreSetting::IsIntegerList(const std::string& name) +{ + return BNSettingIsIntegerList("core", name.c_str()); +} + +bool CoreSetting::IsStringList(const std::string& name) +{ + return BNSettingIsStringList("core", name.c_str()); +} + +bool CoreSetting::IsDouble(const std::string& name) +{ + return BNSettingIsDouble("core", name.c_str()); +} + -- cgit v1.3.1