From 087fdd83b85dd894d5b895557a378bb01828d0ff Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Tue, 28 May 2019 13:47:14 -0400 Subject: Tags --- binaryninjaapi.h | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 2 deletions(-) (limited to 'binaryninjaapi.h') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 25c32b1c..02dc26c2 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -881,6 +881,7 @@ namespace BinaryNinja class Function; struct DataVariable; class Symbol; + class Tag; class BinaryDataNotification { @@ -1090,9 +1091,15 @@ namespace BinaryNinja struct InstructionTextToken { + enum + { + WidthIsByteCount = 0 + }; + BNInstructionTextTokenType type; std::string text; uint64_t value; + uint64_t width; size_t size, operand; BNInstructionTextTokenContext context; uint8_t confidence; @@ -1103,10 +1110,10 @@ namespace BinaryNinja InstructionTextToken(uint8_t confidence, BNInstructionTextTokenType t, const std::string& txt); InstructionTextToken(BNInstructionTextTokenType type, const std::string& text, uint64_t value = 0, size_t size = 0, size_t operand = BN_INVALID_OPERAND, uint8_t confidence = BN_FULL_CONFIDENCE, - const std::vector& typeName={}); + const std::vector& typeName={}, uint64_t width = WidthIsByteCount); InstructionTextToken(BNInstructionTextTokenType type, BNInstructionTextTokenContext context, const std::string& text, uint64_t address, uint64_t value = 0, size_t size = 0, - size_t operand = BN_INVALID_OPERAND, uint8_t confidence = BN_FULL_CONFIDENCE, const std::vector& typeName={}); + size_t operand = BN_INVALID_OPERAND, uint8_t confidence = BN_FULL_CONFIDENCE, const std::vector& typeName={}, uint64_t width = WidthIsByteCount); InstructionTextToken(const BNInstructionTextToken& token); InstructionTextToken WithConfidence(uint8_t conf); @@ -1116,12 +1123,14 @@ namespace BinaryNinja }; + class Tag; struct DisassemblyTextLine { uint64_t addr; size_t instrIndex; std::vector tokens; BNHighlightColor highlight; + std::vector> tags; DisassemblyTextLine(); }; @@ -1187,6 +1196,67 @@ namespace BinaryNinja bool autoDiscovered; }; + class TagType: public CoreRefCountObject + { + public: + typedef BNTagTypeType Type; + + TagType(BNTagType* tagType); + TagType(BinaryView* view); + TagType(BinaryView* view, const std::string& name, const std::string& icon, bool visible = true, Type type = UserTagType); + + BinaryView* GetView() const; + std::string GetName() const; + void SetName(const std::string& name); + std::string GetIcon() const; + void SetIcon(const std::string& icon); + bool GetVisible() const; + void SetVisible(bool visible); + Type GetType() const; + void SetType(Type type); + }; + + class Tag: public CoreRefCountObject + { + public: + Tag(BNTag* tag); + Tag(Ref type, const std::string& data = ""); + + Ref GetType() const; + std::string GetData() const; + void SetData(const std::string& data); + + static BNTag** CreateTagList(const std::vector>& tags, size_t* count); + static std::vector> ConvertTagList(BNTag** tags, size_t count); + static std::vector> ConvertAndFreeTagList(BNTag** tags, size_t count); + }; + + class Architecture; + class Function; + struct TagReference + { + typedef BNTagReferenceType RefType; + + RefType refType; + bool autoDefined; + Ref tag; + Ref arch; + Ref func; + uint64_t addr; + + TagReference(); + TagReference(const BNTagReference& ref); + + bool operator==(const TagReference& other) const; + bool operator!=(const TagReference& other) const; + + operator BNTagReference() const; + + static BNTagReference* CreateTagReferenceList(const std::vector& tags, size_t* count); + static std::vector ConvertTagReferenceList(BNTagReference* tags, size_t count); + static std::vector ConvertAndFreeTagReferenceList(BNTagReference* tags, size_t count); + }; + class Relocation; class Segment: public CoreRefCountObject { @@ -1456,6 +1526,38 @@ namespace BinaryNinja void DefineImportedFunction(Ref importAddressSym, Ref func); + void AddTagType(Ref tagType); + void RemoveTagType(Ref tagType); + Ref GetTagType(const std::string& name); + Ref GetTagType(const std::string& name, TagType::Type type); + std::vector> GetTagTypes(); + + void AddTag(Ref tag); + void RemoveTag(Ref tag); + Ref GetTag(uint64_t tagId); + + std::vector GetAllTagReferences(); + std::vector GetAllAddressTagReferences(); + std::vector GetAllFunctionTagReferences(); + std::vector GetAllTagReferencesOfType(Ref tagType); + std::vector GetTagReferencesOfType(Ref tagType); + + std::vector GetDataTagReferences(); + std::vector> GetDataTags(uint64_t addr); + std::vector> GetDataTagsOfType(uint64_t addr, Ref tagType); + std::vector> GetDataTagsInRange(uint64_t start, uint64_t end); + void AddAutoDataTag(uint64_t addr, Ref tag); + void RemoveAutoDataTag(uint64_t addr, Ref tag); + void AddUserDataTag(uint64_t addr, Ref tag); + void RemoveUserDataTag(uint64_t addr, Ref tag); + void RemoveTagReference(const TagReference& ref); + + Ref CreateAutoDataTag(uint64_t addr, const std::string& tagTypeName, const std::string& data, bool unique = false); + Ref CreateUserDataTag(uint64_t addr, const std::string& tagTypeName, const std::string& data, bool unique = false); + + Ref CreateAutoDataTag(uint64_t addr, Ref tagType, const std::string& data, bool unique = false); + Ref CreateUserDataTag(uint64_t addr, Ref tagType, const std::string& data, bool unique = false); + bool IsNeverBranchPatchAvailable(Architecture* arch, uint64_t addr); bool IsAlwaysBranchPatchAvailable(Architecture* arch, uint64_t addr); bool IsInvertBranchPatchAvailable(Architecture* arch, uint64_t addr); @@ -2748,6 +2850,35 @@ namespace BinaryNinja void SetUserInstructionHighlight(Architecture* arch, uint64_t addr, uint8_t r, uint8_t g, uint8_t b, uint8_t alpha = 255); + std::vector GetAllTagReferences(); + std::vector GetTagReferencesOfType(Ref tagType); + + std::vector GetAddressTagReferences(); + std::vector> GetAddressTags(Architecture* arch, uint64_t addr); + std::vector> GetAddressTagsOfType(Architecture* arch, uint64_t addr, Ref tagType); + void AddAutoAddressTag(Architecture* arch, uint64_t addr, Ref tag); + void RemoveAutoAddressTag(Architecture* arch, uint64_t addr, Ref tag); + void AddUserAddressTag(Architecture* arch, uint64_t addr, Ref tag); + void RemoveUserAddressTag(Architecture* arch, uint64_t addr, Ref tag); + + std::vector GetFunctionTagReferences(); + std::vector> GetFunctionTags(); + std::vector> GetFunctionTagsOfType(Ref tagType); + void AddAutoFunctionTag(Ref tag); + void RemoveAutoFunctionTag(Ref tag); + void AddUserFunctionTag(Ref tag); + void RemoveUserFunctionTag(Ref tag); + + Ref CreateAutoAddressTag(Architecture* arch, uint64_t addr, const std::string& tagTypeName, const std::string& data, bool unique = false); + Ref CreateUserAddressTag(Architecture* arch, uint64_t addr, const std::string& tagTypeName, const std::string& data, bool unique = false); + Ref CreateAutoFunctionTag(const std::string& tagTypeName, const std::string& data, bool unique = false); + Ref CreateUserFunctionTag(const std::string& tagTypeName, const std::string& data, bool unique = false); + + Ref CreateAutoAddressTag(Architecture* arch, uint64_t addr, Ref tagType, const std::string& data, bool unique = false); + Ref CreateUserAddressTag(Architecture* arch, uint64_t addr, Ref tagType, const std::string& data, bool unique = false); + Ref CreateAutoFunctionTag(Ref tagType, const std::string& data, bool unique = false); + Ref CreateUserFunctionTag(Ref tagType, const std::string& data, bool unique = false); + void Reanalyze(); void RequestAdvancedAnalysisData(); -- cgit v1.3.1