From a719ec03c082ad64dece5dcae8e386bd65879843 Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Fri, 25 Jun 2021 18:10:08 -0400 Subject: Give tag types unique ids and stop relying on unique names --- binaryninjaapi.h | 5 +++++ binaryninjacore.h | 3 +++ binaryview.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++--- function.cpp | 8 ++++---- 4 files changed, 56 insertions(+), 7 deletions(-) diff --git a/binaryninjaapi.h b/binaryninjaapi.h index daaff150..d1467d0f 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -1311,6 +1311,7 @@ __attribute__ ((format (printf, 1, 2))) TagType(BinaryView* view, const std::string& name, const std::string& icon, bool visible = true, Type type = UserTagType); BinaryView* GetView() const; + std::string GetId() const; std::string GetName() const; void SetName(const std::string& name); std::string GetIcon() const; @@ -1669,6 +1670,10 @@ __attribute__ ((format (printf, 1, 2))) void RemoveTagType(Ref tagType); Ref GetTagType(const std::string& name); Ref GetTagType(const std::string& name, TagType::Type type); + Ref GetTagTypeByName(const std::string& name); + Ref GetTagTypeByName(const std::string& name, TagType::Type type); + Ref GetTagTypeById(const std::string& id); + Ref GetTagTypeById(const std::string& id, TagType::Type type); std::vector> GetTagTypes(); void AddTag(Ref tag, bool user = false); diff --git a/binaryninjacore.h b/binaryninjacore.h index 73b072be..bb678720 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -3725,6 +3725,7 @@ __attribute__ ((format (printf, 1, 2))) BINARYNINJACOREAPI void BNFreeTagType(BNTagType* tagType); BINARYNINJACOREAPI void BNFreeTagTypeList(BNTagType** tagTypes, size_t count); BINARYNINJACOREAPI BNBinaryView* BNTagTypeGetView(BNTagType* tagType); + BINARYNINJACOREAPI char* BNTagTypeGetId(BNTagType* tagType); BINARYNINJACOREAPI char* BNTagTypeGetName(BNTagType* tagType); BINARYNINJACOREAPI void BNTagTypeSetName(BNTagType* tagType, const char* name); BINARYNINJACOREAPI char* BNTagTypeGetIcon(BNTagType* tagType); @@ -3747,6 +3748,8 @@ __attribute__ ((format (printf, 1, 2))) BINARYNINJACOREAPI void BNRemoveTagType(BNBinaryView* view, BNTagType* tagType); BINARYNINJACOREAPI BNTagType* BNGetTagType(BNBinaryView* view, const char* name); BINARYNINJACOREAPI BNTagType* BNGetTagTypeWithType(BNBinaryView* view, const char* name, BNTagTypeType type); + BINARYNINJACOREAPI BNTagType* BNGetTagTypeById(BNBinaryView* view, const char* id); + BINARYNINJACOREAPI BNTagType* BNGetTagTypeByIdWithType(BNBinaryView* view, const char* id, BNTagTypeType type); BINARYNINJACOREAPI BNTagType** BNGetTagTypes(BNBinaryView* view, size_t* count); BINARYNINJACOREAPI void BNAddTag(BNBinaryView* view, BNTag* tag, bool user); diff --git a/binaryview.cpp b/binaryview.cpp index b4ed691d..139e319c 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -405,6 +405,15 @@ BinaryView* TagType::GetView() const } +std::string TagType::GetId() const +{ + char* str = BNTagTypeGetId(m_object); + string result = str; + BNFreeString(str); + return result; +} + + std::string TagType::GetName() const { char* str = BNTagTypeGetName(m_object); @@ -2392,6 +2401,18 @@ void BinaryView::RemoveTagType(Ref tagType) Ref BinaryView::GetTagType(const std::string& name) +{ + return GetTagTypeByName(name); +} + + +Ref BinaryView::GetTagType(const std::string& name, TagType::Type type) +{ + return GetTagTypeByName(name, type); +} + + +Ref BinaryView::GetTagTypeByName(const std::string& name) { BNTagType* tagType = BNGetTagType(m_object, name.c_str()); if (!tagType) @@ -2401,7 +2422,7 @@ Ref BinaryView::GetTagType(const std::string& name) } -Ref BinaryView::GetTagType(const std::string& name, TagType::Type type) +Ref BinaryView::GetTagTypeByName(const std::string& name, TagType::Type type) { BNTagType* tagType = BNGetTagTypeWithType(m_object, name.c_str(), type); if (!tagType) @@ -2411,6 +2432,26 @@ Ref BinaryView::GetTagType(const std::string& name, TagType::Type type) } +Ref BinaryView::GetTagTypeById(const std::string& name) +{ + BNTagType* tagType = BNGetTagTypeById(m_object, name.c_str()); + if (!tagType) + return nullptr; + + return Ref(new TagType(tagType)); +} + + +Ref BinaryView::GetTagTypeById(const std::string& name, TagType::Type type) +{ + BNTagType* tagType = BNGetTagTypeByIdWithType(m_object, name.c_str(), type); + if (!tagType) + return nullptr; + + return Ref(new TagType(tagType)); +} + + std::vector> BinaryView::GetTagTypes() { size_t count; @@ -2584,7 +2625,7 @@ void BinaryView::RemoveTagReference(const TagReference& ref) Ref BinaryView::CreateAutoDataTag(uint64_t addr, const std::string& tagTypeName, const std::string& data, bool unique) { - Ref tagType = GetTagType(tagTypeName); + Ref tagType = GetTagTypeByName(tagTypeName); if (!tagType) return nullptr; @@ -2594,7 +2635,7 @@ Ref BinaryView::CreateAutoDataTag(uint64_t addr, const std::string& tagType Ref BinaryView::CreateUserDataTag(uint64_t addr, const std::string& tagTypeName, const std::string& data, bool unique) { - Ref tagType = GetTagType(tagTypeName); + Ref tagType = GetTagTypeByName(tagTypeName); if (!tagType) return nullptr; diff --git a/function.cpp b/function.cpp index 58968938..36d5a313 100644 --- a/function.cpp +++ b/function.cpp @@ -1647,7 +1647,7 @@ void Function::RemoveUserFunctionTag(Ref tag) Ref Function::CreateAutoAddressTag(Architecture* arch, uint64_t addr, const std::string& tagTypeName, const std::string& data, bool unique) { - Ref tagType = GetView()->GetTagType(tagTypeName); + Ref tagType = GetView()->GetTagTypeByName(tagTypeName); if (!tagType) return nullptr; @@ -1677,7 +1677,7 @@ Ref Function::CreateAutoAddressTag(Architecture* arch, uint64_t addr, Ref Function::CreateUserAddressTag(Architecture* arch, uint64_t addr, const std::string& tagTypeName, const std::string& data, bool unique) { - Ref tagType = GetView()->GetTagType(tagTypeName); + Ref tagType = GetView()->GetTagTypeByName(tagTypeName); if (!tagType) return nullptr; @@ -1706,7 +1706,7 @@ Ref Function::CreateUserAddressTag(Architecture* arch, uint64_t addr, Ref Function::CreateAutoFunctionTag(const std::string& tagTypeName, const std::string& data, bool unique) { - Ref tagType = GetView()->GetTagType(tagTypeName); + Ref tagType = GetView()->GetTagTypeByName(tagTypeName); if (!tagType) return nullptr; @@ -1736,7 +1736,7 @@ Ref Function::CreateAutoFunctionTag(Ref tagType, const std::string Ref Function::CreateUserFunctionTag(const std::string& tagTypeName, const std::string& data, bool unique) { - Ref tagType = GetView()->GetTagType(tagTypeName); + Ref tagType = GetView()->GetTagTypeByName(tagTypeName); if (!tagType) return nullptr; -- cgit v1.3.1