From ce08fff22e4bed3d977cfd662ed2a6d8caa82997 Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Mon, 14 Sep 2020 17:15:37 -0400 Subject: Database api Co-Authored-By: Josh Ferrell --- binaryninjaapi.h | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) (limited to 'binaryninjaapi.h') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 7927ede9..5a0773ef 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -724,6 +724,42 @@ __attribute__ ((format (printf, 1, 2))) BNMessageBoxButtonResult ShowMessageBox(const std::string& title, const std::string& text, BNMessageBoxButtonSet buttons = OKButtonSet, BNMessageBoxIcon icon = InformationIcon); + /*! + Split a single progress function into equally sized subparts. + This function takes the original progress function and returns a new function whose signature + is the same but whose output is shortened to correspond to the specified subparts. + + E.g. If subpart = 0 and subpartCount = 3, this returns a function that calls originalFn and has + all of its progress multiplied by 1/3 and 0/3 added. + + Internally this works by calling originalFn with total = 1000000 and doing math on the current value + + \param originalFn Original progress function (usually updates a UI) + \param subpart Index of subpart whose function to return, from 0 to (subpartCount - 1) + \param subpartCount Total number of subparts + \return A function that will call originalFn() within a modified progress region + */ + std::function SplitProgress(std::function originalFn, size_t subpart, size_t subpartCount); + + + /*! + Split a single progress function into subparts. + This function takes the original progress function and returns a new function whose signature + is the same but whose output is shortened to correspond to the specified subparts. + + The length of a subpart is proportional to the sum of all the weights. + E.g. If subpart = 1 and subpartWeights = { 0.25, 0.5, 0.25 }, this will return a function that calls + originalFn and maps its progress to the range [0.25, 0.75] + + Internally this works by calling originalFn with total = 1000000 and doing math on the current value + + \param originalFn Original progress function (usually updates a UI) + \param subpart Index of subpart whose function to return, from 0 to (subpartWeights.size() - 1) + \param subpartWeights Weights of subparts, described above + \return A function that will call originalFn() within a modified progress region + */ + std::function SplitProgress(std::function originalFn, size_t subpart, std::vector subpartWeights); + std::string GetUniqueIdentifierString(); std::map GetMemoryUsageInfo(); @@ -763,6 +799,9 @@ __attribute__ ((format (printf, 1, 2))) uint8_t& operator[](size_t offset); const uint8_t& operator[](size_t offset) const; + bool operator==(const DataBuffer& other) const; + bool operator!=(const DataBuffer& other) const; + std::string ToEscapedString() const; static DataBuffer FromEscapedString(const std::string& src); std::string ToBase64() const; @@ -819,6 +858,89 @@ __attribute__ ((format (printf, 1, 2))) }; struct InstructionTextToken; + struct UndoEntry; + + struct DatabaseException: std::runtime_error + { + DatabaseException(const std::string& desc): std::runtime_error(desc.c_str()) {} + }; + + class KeyValueStore: public CoreRefCountObject + { + public: + KeyValueStore(); + KeyValueStore(const DataBuffer& buffer); + KeyValueStore(BNKeyValueStore* store); + + std::vector GetKeys() const; + + bool HasValue(const std::string& name) const; + Json::Value GetValue(const std::string& name) const; + DataBuffer GetBuffer(const std::string& name) const; + void SetValue(const std::string& name, const Json::Value& value); + void SetBuffer(const std::string& name, const DataBuffer& value); + + DataBuffer GetSerializedData() const; + + void BeginNamespace(const std::string& name); + void EndNamespace(); + + bool IsEmpty() const; + size_t ValueSize() const; + size_t DataSize() const; + size_t ValueStorageSize() const; + size_t NamespaceSize() const; + }; + + class Database; + + class Snapshot: public CoreRefCountObject + { + public: + Snapshot(BNSnapshot* snapshot); + + Ref GetDatabase(); + int64_t GetId(); + std::string GetName(); + bool IsAutoSave(); + Ref GetFirstParent(); + std::vector> GetParents(); + std::vector> GetChildren(); + DataBuffer GetFileContents(); + DataBuffer GetFileContentsHash(); + std::vector GetUndoEntries(); + std::vector GetUndoEntries(const std::function& progress); + Ref ReadData(); + Ref ReadData(const std::function& progress); + bool HasAncestor(Ref other); + }; + + class FileMetadata; + + class Database: public CoreRefCountObject + { + public: + Database(BNDatabase* database); + + Ref GetSnapshot(int64_t id); + std::vector> GetSnapshots(); + void SetCurrentSnapshot(int64_t id); + Ref GetCurrentSnapshot(); + int64_t WriteSnapshotData(std::vector parents, Ref file, const std::string& name, const Ref& data, bool autoSave, const std::function& progress); + void RemoveSnapshot(int64_t id); + + std::vector GetGlobalKeys() const; + bool HasGlobal(const std::string& key) const; + Json::Value ReadGlobal(const std::string& key) const; + void WriteGlobal(const std::string& key, const Json::Value& val); + DataBuffer ReadGlobalData(const std::string& key) const; + void WriteGlobalData(const std::string& key, const DataBuffer& val); + + Ref GetFile(); + + Ref ReadAnalysisCache() const; + void WriteAnalysisCache(Ref val); + }; struct UndoAction { @@ -893,6 +1015,11 @@ __attribute__ ((format (printf, 1, 2))) bool SaveAutoSnapshot(BinaryView* data, Ref settings); bool SaveAutoSnapshot(BinaryView* data, const std::function& progressCallback, Ref settings); + void GetSnapshotData(Ref data, Ref cache, + const std::function& progress); + void ApplySnapshotData(BinaryView* file, Ref data, Ref cache, + const std::function& progress, bool openForConfiguration = false, bool restoreRawView = true); + Ref GetDatabase(); bool Rebase(BinaryView* data, uint64_t address); bool Rebase(BinaryView* data, uint64_t address, const std::function& progressCallback); @@ -908,6 +1035,7 @@ __attribute__ ((format (printf, 1, 2))) std::vector> GetUsers(); std::vector GetUndoEntries(); + void ClearUndoEntries(); bool OpenProject(); void CloseProject(); -- cgit v1.3.1