summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--binaryninjaapi.h104
-rw-r--r--binaryninjacore.h107
-rw-r--r--binaryreader.cpp37
-rw-r--r--binaryview.cpp51
-rw-r--r--metadata.cpp238
-rw-r--r--python/__init__.py1
-rw-r--r--python/setting.py114
-rw-r--r--python/startup.py1
-rw-r--r--setting.cpp162
9 files changed, 814 insertions, 1 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index e5ae77f5..10f021b4 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -375,6 +375,7 @@ namespace BinaryNinja
void InitCorePlugins();
void InitUserPlugins();
void InitRepoPlugins();
+
std::string GetBundledPluginDirectory();
void SetBundledPluginDirectory(const std::string& path);
std::string GetInstallDirectory();
@@ -845,6 +846,15 @@ namespace BinaryNinja
};
struct QualifiedNameAndType;
+ class Metadata;
+
+ class QueryMetadataException: public std::exception
+ {
+ const std::string m_error;
+ public:
+ QueryMetadataException(const std::string& error): std::exception(), m_error(error) {}
+ virtual const char* what() const NOEXCEPT { return m_error.c_str(); }
+ };
/*! BinaryView is the base class for creating views on binary data (e.g. ELF, PE, Mach-O).
BinaryView should be subclassed to create a new BinaryView
@@ -1116,6 +1126,12 @@ namespace BinaryNinja
std::vector<std::string> GetUniqueSectionNames(const std::vector<std::string>& names);
std::vector<BNAddressRange> GetAllocatedRanges();
+
+ void StoreMetadata(const std::string& key, Metadata* inValue);
+ bool QueryMetadata(const std::string& key, Metadata** outValue);
+ std::string GetStringMetadata(const std::string& key);
+ std::vector<uint8_t> GetRawMetadata(const std::string& key);
+ uint64_t GetUIntMetadata(const std::string& key);
};
class BinaryData: public BinaryView
@@ -1195,7 +1211,11 @@ namespace BinaryNinja
void Read(void* dest, size_t len);
DataBuffer Read(size_t len);
+ template <typename T> T Read();
+ template <typename T> std::vector<T> ReadVector(size_t count);
std::string ReadString(size_t len);
+ std::string ReadCString(size_t maxLength=-1);
+
uint8_t Read8();
uint16_t Read16();
uint32_t Read32();
@@ -2842,4 +2862,88 @@ namespace BinaryNinja
bool UninstallPlugin(const std::string& repoName, const std::string& pluginPath);
Ref<Repository> GetDefaultRepository();
};
+
+ class Setting
+ {
+ public:
+ static bool ProcessMainSettingsFile();
+ static bool GetBool(const std::string& settingGroup, const std::string& name, bool defaultValue);
+ static uint64_t GetInteger(const std::string& settingGroup, const std::string& name, uint64_t defaultValue=0);
+ static std::string GetString(const std::string& settingGroup, const std::string& name, const std::string& defaultValue="");
+ static std::vector<uint64_t> GetIntegerList(const std::string& settingGroup, const std::string& name, const std::vector<uint64_t>& defaultValue={});
+ static std::vector<std::string> GetStringList(const std::string& settingGroup, const std::string& name, const std::vector<std::string>& defaultValue={});
+ static double GetDouble(const std::string& settingGroup, const std::string& name, double defaultValue=0.0);
+
+ static bool IsPresent(const std::string& settingGroup, const std::string& name);
+ static bool IsBool(const std::string& settingGroup, const std::string& name);
+ static bool IsInteger(const std::string& settingGroup, const std::string& name);
+ static bool IsString(const std::string& settingGroup, const std::string& name);
+ static bool IsIntegerList(const std::string& settingGroup, const std::string& name);
+ static bool IsStringList(const std::string& settingGroup, const std::string& name);
+ static bool IsDouble(const std::string& settingGroup, const std::string& name);
+ };
+
+ class CoreSetting
+ {
+ public:
+ static bool GetBool(const std::string& name, bool defaultValue);
+ static uint64_t GetInteger(const std::string& name, uint64_t defaultValue=0);
+ static std::string GetString(const std::string& name, const std::string& defaultValue="");
+ static std::vector<uint64_t> GetIntegerList(const std::string& name, const std::vector<uint64_t>& defaultValue={});
+ static std::vector<std::string> GetStringList(const std::string& name, const std::vector<std::string>& defaultValue={});
+ static double GetDouble(const std::string& name, double defaultValue=0.0);
+
+ static bool IsPresent(const std::string& name);
+ static bool IsBool(const std::string& name);
+ static bool IsInteger(const std::string& name);
+ static bool IsString(const std::string& name);
+ static bool IsIntegerList(const std::string& name);
+ static bool IsStringList(const std::string& name);
+ static bool IsDouble(const std::string& name);
+ };
+
+ typedef BNMetadataType MetadataType;
+
+ class Metadata: public CoreRefCountObject<BNMetadata, BNNewMetadataReference, BNFreeMetadata>
+ {
+ public:
+ Metadata(BNMetadata* structuredData);
+ Metadata(bool data);
+ Metadata(const std::string& data);
+ Metadata(uint64_t data);
+ Metadata(int64_t data);
+ Metadata(double data);
+ Metadata(const std::vector<bool>& data);
+ Metadata(const std::vector<std::string>& data);
+ Metadata(const std::vector<uint64_t>& data);
+ Metadata(const std::vector<int64_t>& data);
+ Metadata(const std::vector<double>& data);
+ Metadata(const std::vector<uint8_t>& data);
+ virtual ~Metadata() {}
+
+ MetadataType GetType() const;
+ bool GetBoolean() const;
+ std::string GetString() const;
+ uint64_t GetUnsignedInteger() const;
+ int64_t GetSignedInteger() const;
+ double GetDouble() const;
+ std::vector<bool> GetBooleanList() const;
+ std::vector<std::string> GetStringList() const;
+ std::vector<uint64_t> GetUnsignedIntegerList() const;
+ std::vector<int64_t> GetSignedIntegerList() const;
+ std::vector<double> GetDoubleList() const;
+ std::vector<uint8_t> GetRaw() const;
+
+ bool IsBoolean() const;
+ bool IsString() const;
+ bool IsUnsignedInteger() const;
+ bool IsSignedInteger() const;
+ bool IsDouble() const;
+ bool IsBooleanList() const;
+ bool IsStringList() const;
+ bool IsUnsignedIntegerList() const;
+ bool IsSignedIntegerList() const;
+ bool IsDoubleList() const;
+ bool IsRaw() const;
+ };
}
diff --git a/binaryninjacore.h b/binaryninjacore.h
index d053eb2b..58b0198a 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -137,6 +137,7 @@ extern "C"
struct BNRepository;
struct BNRepoPlugin;
struct BNRepositoryManager;
+ struct BNMetadata;
typedef bool (*BNLoadPluginCallback)(const char* repoPath, const char* pluginPath, void* ctx);
@@ -1257,6 +1258,7 @@ extern "C"
SuccessfulScriptExecution
};
+
struct BNScriptingInstanceCallbacks
{
void* context;
@@ -1474,6 +1476,21 @@ extern "C"
double seconds;
};
+ enum BNMetadataType
+ {
+ BooleanDataType,
+ StringDataType,
+ UnsignedIntegerDataType,
+ SignedIntegerDataType,
+ DoubleDataType,
+ BooleanListDataType,
+ StringListDataType,
+ UnsignedIntegerListDataType,
+ SignedIntegerListDataType,
+ DoubleListDataType,
+ RawDataType
+ };
+
BINARYNINJACOREAPI char* BNAllocString(const char* contents);
BINARYNINJACOREAPI void BNFreeString(char* str);
BINARYNINJACOREAPI void BNFreeStringList(char** strs, size_t count);
@@ -1504,6 +1521,7 @@ extern "C"
BINARYNINJACOREAPI char* BNGetUserDirectory(void);
BINARYNINJACOREAPI char* BNGetUserPluginDirectory(void);
BINARYNINJACOREAPI char* BNGetRepositoriesDirectory(void);
+ BINARYNINJACOREAPI char* BNGetSettingsFileName(void);
BINARYNINJACOREAPI void BNSaveLastRun(void);
BINARYNINJACOREAPI char* BNGetPathRelativeToBundledPluginDirectory(const char* path);
@@ -2859,7 +2877,94 @@ extern "C"
// Filesystem functionality
BINARYNINJACOREAPI int BNDeleteFile(const char* path);
BINARYNINJACOREAPI int BNDeleteDirectory(const char* path, int contentsOnly);
- BINARYNINJACOREAPI int BNCreateDirectory(const char* path);
+ BINARYNINJACOREAPI bool BNCreateDirectory(const char* path, bool createSubdirectories);
+ BINARYNINJACOREAPI bool BNPathExists(const char* path);
+ BINARYNINJACOREAPI bool BNIsPathDirectory(const char* path);
+ BINARYNINJACOREAPI bool BNIsPathRegularFile(const char* path);
+
+ // Settings APIs
+ BINARYNINJACOREAPI bool BNProcessMainSettingsFile();
+ BINARYNINJACOREAPI bool BNSettingGetBool(const char* settingGroup, const char* name, bool defaultValue);
+ BINARYNINJACOREAPI uint64_t BNSettingGetInteger(const char* settingGroup, const char* name, uint64_t defaultValue);
+ BINARYNINJACOREAPI char* BNSettingGetString(const char* settingGroup, const char* name, const char* defaultValue);
+ // intoutSize is number of elements in defaultValue one entry and number of elements in return type on exit
+ BINARYNINJACOREAPI uint64_t* BNSettingGetIntegerList(const char* settingGroup, const char* name, uint64_t* defaultValue, size_t* inoutSize);
+ // intoutSize is number of elements in defaultValue one entry and number of elements in return type on exit
+ BINARYNINJACOREAPI const char** BNSettingGetStringList(const char* settingGroup, const char* name, const char** defaultValue, size_t* inoutSize);
+ BINARYNINJACOREAPI double BNSettingGetDouble(const char* settingGroup, const char* name, double defaultValue);
+
+ BINARYNINJACOREAPI void BNFreeSettingStringList(char** stringList, size_t size);
+ BINARYNINJACOREAPI void BNFreeSettingIntegerList(uint64_t* integerList);
+ //Check the type of a core setting
+ BINARYNINJACOREAPI bool BNSettingIsBool(const char* name, const char* settingGroup);
+ BINARYNINJACOREAPI bool BNSettingIsInteger(const char* name, const char* settingGroup);
+ BINARYNINJACOREAPI bool BNSettingIsString(const char* name, const char* settingGroup);
+ BINARYNINJACOREAPI bool BNSettingIsStringList(const char* name, const char* settingGroup);
+ BINARYNINJACOREAPI bool BNSettingIsIntegerList(const char* name, const char* settingGroup);
+ BINARYNINJACOREAPI bool BNSettingIsDouble(const char* name, const char* settingGroup);
+ // Check if a plugin setting is present
+ BINARYNINJACOREAPI bool BNSettingIsPresent(const char* settingGroup, const char* name);
+
+ BINARYNINJACOREAPI bool BNSettingSetBool(const char* settingGroup, const char* name, bool value, bool autoFlush);
+ BINARYNINJACOREAPI bool BNSettingSetInteger(const char* settingGroup, const char* name, uint64_t value, bool autoFlush);
+ BINARYNINJACOREAPI bool BNSettingSetString(const char* settingGroup, const char* name, const char* value, bool autoFlush);
+ BINARYNINJACOREAPI bool BNSettingSetDouble(const char* settingGroup, const char* name, double value, bool autoFlush);
+ BINARYNINJACOREAPI bool BNSettingSetIntegerList(const char* settingGroup, const char* name, const uint64_t* value, size_t size, bool autoFlush);
+ BINARYNINJACOREAPI bool BNSettingSetStringList(const char* settingGroup, const char* name, const char** value, size_t size, bool autoFlush);
+
+ BINARYNINJACOREAPI bool BNSettingFlushSettings();
+
+ //Metadata APIs
+
+ // Create Metadata of various types
+ BINARYNINJACOREAPI BNMetadata* BNNewMetadataReference(BNMetadata* data);
+ BINARYNINJACOREAPI BNMetadata* BNCreateStructuredBooleanData(bool data);
+ BINARYNINJACOREAPI BNMetadata* BNCreateStructuredStringData(const char* data);
+ BINARYNINJACOREAPI BNMetadata* BNCreateStructuredUnsignedIntegerData(uint64_t data);
+ BINARYNINJACOREAPI BNMetadata* BNCreateStructuredSignedIntegerData(int64_t data);
+ BINARYNINJACOREAPI BNMetadata* BNCreateStructuredDoubleData(double data);
+ BINARYNINJACOREAPI BNMetadata* BNCreateStructuredBooleanListData(const bool* data, size_t size);
+ BINARYNINJACOREAPI BNMetadata* BNCreateStructuredStringListData(const char** data, size_t size);
+ BINARYNINJACOREAPI BNMetadata* BNCreateStructuredUnsignedIntegerListData(const uint64_t* data, size_t size);
+ BINARYNINJACOREAPI BNMetadata* BNCreateStructuredSignedIntegerListData(const int64_t* data, size_t size);
+ BINARYNINJACOREAPI BNMetadata* BNCreateStructuredDoubleListData(const double* data, size_t size);
+ BINARYNINJACOREAPI BNMetadata* BNCreateStructuredRawData(const uint8_t* data, size_t size);
+ BINARYNINJACOREAPI void BNFreeMetadata(BNMetadata* data);
+ BINARYNINJACOREAPI void BNFreeMetadataBooleanList(bool* data);
+ BINARYNINJACOREAPI void BNFreeMetadataStringList(char** data, size_t size);
+ BINARYNINJACOREAPI void BNFreeMetadataUnsignedIntegerList(uint64_t* data);
+ BINARYNINJACOREAPI void BNFreeMetadataSignedIntegerList(int64_t* data);
+ BINARYNINJACOREAPI void BNFreeMetadataDoubleList(double* data);
+ BINARYNINJACOREAPI void BNFreeMetadataRaw(uint8_t* data);
+ // Retrieve Structured Data
+ BINARYNINJACOREAPI bool BNMetadataGetBoolean(BNMetadata* data);
+ BINARYNINJACOREAPI char* BNMetadataGetString(BNMetadata* data);
+ BINARYNINJACOREAPI uint64_t BNMetadataGetUnsignedInteger(BNMetadata* data);
+ BINARYNINJACOREAPI int64_t BNMetadataGetSignedInteger(BNMetadata* data);
+ BINARYNINJACOREAPI double BNMetadataGetDouble(BNMetadata* data);
+ BINARYNINJACOREAPI bool* BNMetadataGetBooleanList(BNMetadata* data, size_t* size);
+ BINARYNINJACOREAPI char** BNMetadataGetStringList(BNMetadata* data, size_t* size);
+ BINARYNINJACOREAPI uint64_t* BNMetadataGetUnsignedIntegerList(BNMetadata* data, size_t* size);
+ BINARYNINJACOREAPI int64_t* BNMetadataGetSignedIntegerList(BNMetadata* data, size_t* size);
+ BINARYNINJACOREAPI double* BNMetadataGetDoubleList(BNMetadata* data, size_t* size);
+ BINARYNINJACOREAPI uint8_t* BNMetadataGetRaw(BNMetadata* data, size_t* size);
+ //Query type of Metadata
+ BINARYNINJACOREAPI BNMetadataType BNMetadataGetType(BNMetadata* data);
+ BINARYNINJACOREAPI bool BNMetadataIsBoolean(BNMetadata* data);
+ BINARYNINJACOREAPI bool BNMetadataIsString(BNMetadata* data);
+ BINARYNINJACOREAPI bool BNMetadataIsUnsignedInteger(BNMetadata* data);
+ BINARYNINJACOREAPI bool BNMetadataIsSignedInteger(BNMetadata* data);
+ BINARYNINJACOREAPI bool BNMetadataIsDouble(BNMetadata* data);
+ BINARYNINJACOREAPI bool BNMetadataIsBooleanList(BNMetadata* data);
+ BINARYNINJACOREAPI bool BNMetadataIsStringList(BNMetadata* data);
+ BINARYNINJACOREAPI bool BNMetadataIsUnsignedIntegerList(BNMetadata* data);
+ BINARYNINJACOREAPI bool BNMetadataIsSignedIntegerList(BNMetadata* data);
+ BINARYNINJACOREAPI bool BNMetadataIsDoubleList(BNMetadata* data);
+ BINARYNINJACOREAPI bool BNMetadataIsRaw(BNMetadata* data);
+
+ // Store/Query structured data to/from a BinaryView
+ BINARYNINJACOREAPI void BNBinaryViewStoreMetadata(BNBinaryView* view, const char* key, BNMetadata* value);
+ BINARYNINJACOREAPI bool BNBinaryViewQueryMetadata(BNBinaryView* view, const char* key, BNMetadata** value);
#ifdef __cplusplus
}
#endif
diff --git a/binaryreader.cpp b/binaryreader.cpp
index ad4859ff..7538e442 100644
--- a/binaryreader.cpp
+++ b/binaryreader.cpp
@@ -266,3 +266,40 @@ bool BinaryReader::IsEndOfFile() const
{
return BNIsEndOfFile(m_stream);
}
+
+
+template <typename T>
+T BinaryReader::Read()
+{
+ T value;
+ Read((char*)&value, sizeof(T));
+ return value;
+}
+
+template<typename T>
+vector<T> BinaryReader::ReadVector(size_t count)
+{
+ T* buff = new T[count];
+ Read((char*)buff, count * sizeof(T));
+ std::vector<T> out(buff, buff + count);
+ return out;
+}
+
+
+string BinaryReader::ReadCString(size_t maxSize)
+{
+ string result;
+ try
+ {
+ for (size_t i = 0; i < maxSize; i++)
+ {
+ char cur = Read8();
+ if (cur == 0)
+ break;
+ result.push_back(cur);
+ }
+ }
+ catch (ReadException& r)
+ {;}
+ return result;
+} \ No newline at end of file
diff --git a/binaryview.cpp b/binaryview.cpp
index b18b065b..6eb299a3 100644
--- a/binaryview.cpp
+++ b/binaryview.cpp
@@ -1826,6 +1826,57 @@ vector<BNAddressRange> BinaryView::GetAllocatedRanges()
}
+void BinaryView::StoreMetadata(const std::string& key, Metadata* inValue)
+{
+ if (!inValue)
+ return;
+ BNBinaryViewStoreMetadata(m_object, key.c_str(), inValue->GetObject());
+}
+
+
+bool BinaryView::QueryMetadata(const std::string& key, Metadata** outValue)
+{
+ BNMetadata* value = nullptr;
+ bool status = BNBinaryViewQueryMetadata(m_object, key.c_str(), &value);
+ if (!status)
+ {
+ *outValue = nullptr;
+ return false;
+ }
+ *outValue = new Metadata(value);
+ return true;
+}
+
+string BinaryView::GetStringMetadata(const string& key)
+{
+ Metadata* data;
+ if (!QueryMetadata(key, &data) || !data || data->IsString())
+ throw QueryMetadataException("Failed to find key: " + key);
+ auto result = data->GetString();
+ delete data;
+ return result;
+}
+
+vector<uint8_t> BinaryView::GetRawMetadata(const string& key)
+{
+ Metadata* data;
+ if (!QueryMetadata(key, &data) || !data || data->IsRaw())
+ throw QueryMetadataException("Failed to find key: " + key);
+ auto result = data->GetRaw();
+ delete data;
+ return result;
+}
+
+uint64_t BinaryView::GetUIntMetadata(const string& key)
+{
+ Metadata* data;
+ if (!QueryMetadata(key, &data) || !data || data->IsUnsignedInteger())
+ throw QueryMetadataException("Failed to find key: " + key);
+ auto result = data->GetUnsignedInteger();
+ delete data;
+ return result;
+}
+
BinaryData::BinaryData(FileMetadata* file): BinaryView(BNCreateBinaryDataView(file->GetObject()))
{
}
diff --git a/metadata.cpp b/metadata.cpp
new file mode 100644
index 00000000..2f398940
--- /dev/null
+++ b/metadata.cpp
@@ -0,0 +1,238 @@
+#include "binaryninjaapi.h"
+
+using namespace std;
+using namespace BinaryNinja;
+
+Metadata::Metadata(BNMetadata* structuredData)
+{
+ m_object = structuredData;
+}
+
+Metadata::Metadata(bool data)
+{
+ m_object = BNCreateStructuredBooleanData(data);
+}
+
+Metadata::Metadata(const string& data)
+{
+ m_object = BNCreateStructuredStringData(data.c_str());
+}
+
+Metadata::Metadata(uint64_t data)
+{
+ m_object = BNCreateStructuredUnsignedIntegerData(data);
+}
+
+Metadata::Metadata(int64_t data)
+{
+ m_object = BNCreateStructuredSignedIntegerData(data);
+}
+
+Metadata::Metadata(double data)
+{
+ m_object = BNCreateStructuredDoubleData(data);
+}
+
+Metadata::Metadata(const vector<bool>& data)
+{
+ auto input = new bool[data.size()];
+ for (size_t i = 0; i < data.size(); i++)
+ input[i] = data[i];
+
+ m_object = BNCreateStructuredBooleanListData(input, data.size());
+ delete[] input;
+}
+
+Metadata::Metadata(const vector<string>& data)
+{
+ char** input = new char*[data.size()];
+ for (size_t i = 0; i < data.size(); i++)
+ input[i] = BNAllocString(data[i].c_str());
+
+ m_object = BNCreateStructuredStringListData((const char**)input, data.size());
+
+ for (size_t i = 0; i < data.size(); i++)
+ BNFreeString(input[i]);
+ delete[] input;
+}
+
+Metadata::Metadata(const vector<uint64_t>& data)
+{
+ auto input = new uint64_t[data.size()];
+ for (size_t i = 0; i < data.size(); i++)
+ input[i] = data[i];
+
+ m_object = BNCreateStructuredUnsignedIntegerListData(input, data.size());
+ delete[] input;
+}
+
+Metadata::Metadata(const vector<int64_t>& data)
+{
+ auto input = new int64_t[data.size()];
+ for (size_t i = 0; i < data.size(); i++)
+ input[i] = data[i];
+
+ m_object = BNCreateStructuredSignedIntegerListData(input, data.size());
+ delete[] input;
+}
+
+Metadata::Metadata(const vector<double>& data)
+{
+ auto input = new double[data.size()];
+ for (size_t i = 0; i < data.size(); i++)
+ input[i] = data[i];
+
+ m_object = BNCreateStructuredDoubleListData(input, data.size());
+ delete[] input;
+}
+
+Metadata::Metadata(const vector<uint8_t>& data)
+{
+ auto input = new uint8_t[data.size()];
+ for (size_t i = 0; i < data.size(); i++)
+ input[i] = data[i];
+
+ m_object = BNCreateStructuredRawData(input, data.size());
+ delete[] input;
+}
+
+MetadataType Metadata::GetType() const
+{
+ return BNMetadataGetType(m_object);
+}
+
+bool Metadata::GetBoolean() const
+{
+ return BNMetadataGetBoolean(m_object);
+}
+
+string Metadata::GetString() const
+{
+ return BNMetadataGetString(m_object);
+}
+
+uint64_t Metadata::GetUnsignedInteger() const
+{
+ return BNMetadataGetUnsignedInteger(m_object);
+}
+
+int64_t Metadata::GetSignedInteger() const
+{
+ return BNMetadataGetSignedInteger(m_object);
+}
+
+double Metadata::GetDouble() const
+{
+ return BNMetadataGetDouble(m_object);
+}
+
+vector<bool> Metadata::GetBooleanList() const
+{
+ size_t outSize;
+ bool* outList = BNMetadataGetBooleanList(m_object, &outSize);
+ vector<bool> result(outList, outList + outSize);
+ BNFreeMetadataBooleanList(outList);
+ return result;
+}
+
+vector<string> Metadata::GetStringList() const
+{
+ size_t outSize;
+ char** outList = BNMetadataGetStringList(m_object, &outSize);
+ vector<string> result;
+ for (size_t i = 0; i < outSize; i++)
+ result.push_back(string(outList[i]));
+ BNFreeMetadataStringList(outList, outSize);
+ return result;
+}
+
+vector<uint64_t> Metadata::GetUnsignedIntegerList() const
+{
+ size_t outSize;
+ uint64_t* outList = BNMetadataGetUnsignedIntegerList(m_object, &outSize);
+ vector<uint64_t> result(outList, outList + outSize);
+ BNFreeMetadataUnsignedIntegerList(outList);
+ return result;
+}
+
+vector<int64_t> Metadata::GetSignedIntegerList() const
+{
+ size_t outSize;
+ int64_t* outList = BNMetadataGetSignedIntegerList(m_object, &outSize);
+ vector<int64_t> result(outList, outList + outSize);
+ BNFreeMetadataSignedIntegerList(outList);
+ return result;
+}
+
+vector<double> Metadata::GetDoubleList() const
+{
+ size_t outSize;
+ double* outList = BNMetadataGetDoubleList(m_object, &outSize);
+ vector<double> result(outList, outList + outSize);
+ BNFreeMetadataDoubleList(outList);
+ return result;
+}
+
+vector<uint8_t> Metadata::GetRaw() const
+{
+ size_t outSize;
+ uint8_t* outList = BNMetadataGetRaw(m_object, &outSize);
+ vector<uint8_t> result(outList, outList + outSize);
+ BNFreeMetadataRaw(outList);
+ return result;
+}
+
+bool Metadata::IsBoolean() const
+{
+ return BNMetadataIsBoolean(m_object);
+}
+
+bool Metadata::IsString() const
+{
+ return BNMetadataIsString(m_object);
+}
+
+bool Metadata::IsUnsignedInteger() const
+{
+ return BNMetadataIsUnsignedInteger(m_object);
+}
+
+bool Metadata::IsSignedInteger() const
+{
+ return BNMetadataIsSignedInteger(m_object);
+}
+
+bool Metadata::IsDouble() const
+{
+ return BNMetadataIsDouble(m_object);
+}
+
+bool Metadata::IsBooleanList() const
+{
+ return BNMetadataIsBooleanList(m_object);
+}
+
+bool Metadata::IsStringList() const
+{
+ return BNMetadataIsStringList(m_object);
+}
+
+bool Metadata::IsUnsignedIntegerList() const
+{
+ return BNMetadataIsUnsignedIntegerList(m_object);
+}
+
+bool Metadata::IsSignedIntegerList() const
+{
+ return BNMetadataIsSignedIntegerList(m_object);
+}
+
+bool Metadata::IsDoubleList() const
+{
+ return BNMetadataIsDoubleList(m_object);
+}
+
+bool Metadata::IsRaw() const
+{
+ return BNMetadataIsRaw(m_object);
+}
diff --git a/python/__init__.py b/python/__init__.py
index 4f58a6db..ec25839b 100644
--- a/python/__init__.py
+++ b/python/__init__.py
@@ -47,6 +47,7 @@ from .undoaction import *
from .highlight import *
from .scriptingprovider import *
from .pluginmanager import *
+from .setting import *
def shutdown():
diff --git a/python/setting.py b/python/setting.py
new file mode 100644
index 00000000..975f393e
--- /dev/null
+++ b/python/setting.py
@@ -0,0 +1,114 @@
+# 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
+import _binaryninjacore as core
+
+
+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):
+ length = ctypes.c_ulonglong()
+ length.value = 0
+ default_list = ctypes.POINTER(ctypes.c_ulonglong)()
+ result = core.BNSettingGetIntegerList(self.plugin_name, name, default_list, ctypes.byref(length))
+ out_list = []
+ for i in xrange(length.value):
+ out_list.append(result[i])
+ core.BNFreeSettingIntegerList(result, length)
+ return out_list
+
+ def get_string_list(self, name):
+ length = ctypes.c_ulonglong()
+ length.value = 0
+ default_list = ctypes.POINTER(ctypes.c_char_p)()
+ result = core.BNSettingGetStringList(self.plugin_name, name, default_list, ctypes.byref(length))
+ out_list = []
+ for i in xrange(length.value):
+ out_list.append(result[i])
+ core.BNFreeSettingStringList(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_integerList(self, name, value, auto_flush=True):
+ length = ctypes.c_ulonglong()
+ length.value = len(value)
+ default_list = (ctypes.c_ulonglong * len(value))()
+ for i in xrange(len(value)):
+ default_list[i] = value[i]
+
+ return core.BNSettingSetIntegerList(self.plugin_name, name, default_list, length, auto_flush)
+
+ def set_stringList(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 xrange(len(value)):
+ default_list[i] = str(value[i])
+
+ 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)
diff --git a/python/startup.py b/python/startup.py
index 0abc47cb..d37b2f9b 100644
--- a/python/startup.py
+++ b/python/startup.py
@@ -28,6 +28,7 @@ def _init_plugins():
global _plugin_init
if not _plugin_init:
_plugin_init = True
+ core.BNProcessMainSettingsFile()
core.BNInitCorePlugins()
core.BNInitUserPlugins()
core.BNInitRepoPlugins()
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<uint64_t> Setting::GetIntegerList(const std::string& pluginName, const std::string& name, const std::vector<uint64_t>& 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<uint64_t> out(buffer, buffer + size);
+ delete[] buffer;
+ return out;
+}
+
+std::vector<std::string> Setting::GetStringList(const std::string& pluginName, const std::string& name, const std::vector<std::string>& 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<string> 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<uint64_t> CoreSetting::GetIntegerList(const std::string& name, const std::vector<uint64_t>& defaultValue)
+{
+ return Setting::GetIntegerList("core", name.c_str(), defaultValue);
+}
+std::vector<std::string> CoreSetting::GetStringList(const std::string& name, const std::vector<std::string>& 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());
+}
+