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 --- binaryninjaapi.h | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) (limited to 'binaryninjaapi.h') 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 GetUniqueSectionNames(const std::vector& names); std::vector 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 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 T Read(); + template std::vector 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 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 GetIntegerList(const std::string& settingGroup, const std::string& name, const std::vector& defaultValue={}); + static std::vector GetStringList(const std::string& settingGroup, const std::string& name, const std::vector& 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 GetIntegerList(const std::string& name, const std::vector& defaultValue={}); + static std::vector GetStringList(const std::string& name, const std::vector& 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 + { + 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& data); + Metadata(const std::vector& data); + Metadata(const std::vector& data); + Metadata(const std::vector& data); + Metadata(const std::vector& data); + Metadata(const std::vector& 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 GetBooleanList() const; + std::vector GetStringList() const; + std::vector GetUnsignedIntegerList() const; + std::vector GetSignedIntegerList() const; + std::vector GetDoubleList() const; + std::vector 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; + }; } -- cgit v1.3.1