summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2021-06-25 18:10:08 -0400
committerGlenn Smith <glenn@vector35.com>2021-07-01 01:32:28 -0400
commita719ec03c082ad64dece5dcae8e386bd65879843 (patch)
tree3df98c553ecd3cf187edec9683c1c9ae280297fd
parent8f0f90294096ed12e099b0572e28b531636e4fd8 (diff)
Give tag types unique ids and stop relying on unique names
-rw-r--r--binaryninjaapi.h5
-rw-r--r--binaryninjacore.h3
-rw-r--r--binaryview.cpp47
-rw-r--r--function.cpp8
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> tagType);
Ref<TagType> GetTagType(const std::string& name);
Ref<TagType> GetTagType(const std::string& name, TagType::Type type);
+ Ref<TagType> GetTagTypeByName(const std::string& name);
+ Ref<TagType> GetTagTypeByName(const std::string& name, TagType::Type type);
+ Ref<TagType> GetTagTypeById(const std::string& id);
+ Ref<TagType> GetTagTypeById(const std::string& id, TagType::Type type);
std::vector<Ref<TagType>> GetTagTypes();
void AddTag(Ref<Tag> 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);
@@ -2393,6 +2402,18 @@ void BinaryView::RemoveTagType(Ref<TagType> tagType)
Ref<TagType> BinaryView::GetTagType(const std::string& name)
{
+ return GetTagTypeByName(name);
+}
+
+
+Ref<TagType> BinaryView::GetTagType(const std::string& name, TagType::Type type)
+{
+ return GetTagTypeByName(name, type);
+}
+
+
+Ref<TagType> BinaryView::GetTagTypeByName(const std::string& name)
+{
BNTagType* tagType = BNGetTagType(m_object, name.c_str());
if (!tagType)
return nullptr;
@@ -2401,7 +2422,7 @@ Ref<TagType> BinaryView::GetTagType(const std::string& name)
}
-Ref<TagType> BinaryView::GetTagType(const std::string& name, TagType::Type type)
+Ref<TagType> 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<TagType> BinaryView::GetTagType(const std::string& name, TagType::Type type)
}
+Ref<TagType> BinaryView::GetTagTypeById(const std::string& name)
+{
+ BNTagType* tagType = BNGetTagTypeById(m_object, name.c_str());
+ if (!tagType)
+ return nullptr;
+
+ return Ref<TagType>(new TagType(tagType));
+}
+
+
+Ref<TagType> BinaryView::GetTagTypeById(const std::string& name, TagType::Type type)
+{
+ BNTagType* tagType = BNGetTagTypeByIdWithType(m_object, name.c_str(), type);
+ if (!tagType)
+ return nullptr;
+
+ return Ref<TagType>(new TagType(tagType));
+}
+
+
std::vector<Ref<TagType>> BinaryView::GetTagTypes()
{
size_t count;
@@ -2584,7 +2625,7 @@ void BinaryView::RemoveTagReference(const TagReference& ref)
Ref<Tag> BinaryView::CreateAutoDataTag(uint64_t addr, const std::string& tagTypeName, const std::string& data, bool unique)
{
- Ref<TagType> tagType = GetTagType(tagTypeName);
+ Ref<TagType> tagType = GetTagTypeByName(tagTypeName);
if (!tagType)
return nullptr;
@@ -2594,7 +2635,7 @@ Ref<Tag> BinaryView::CreateAutoDataTag(uint64_t addr, const std::string& tagType
Ref<Tag> BinaryView::CreateUserDataTag(uint64_t addr, const std::string& tagTypeName, const std::string& data, bool unique)
{
- Ref<TagType> tagType = GetTagType(tagTypeName);
+ Ref<TagType> 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> tag)
Ref<Tag> Function::CreateAutoAddressTag(Architecture* arch, uint64_t addr, const std::string& tagTypeName, const std::string& data, bool unique)
{
- Ref<TagType> tagType = GetView()->GetTagType(tagTypeName);
+ Ref<TagType> tagType = GetView()->GetTagTypeByName(tagTypeName);
if (!tagType)
return nullptr;
@@ -1677,7 +1677,7 @@ Ref<Tag> Function::CreateAutoAddressTag(Architecture* arch, uint64_t addr, Ref<T
Ref<Tag> Function::CreateUserAddressTag(Architecture* arch, uint64_t addr, const std::string& tagTypeName, const std::string& data, bool unique)
{
- Ref<TagType> tagType = GetView()->GetTagType(tagTypeName);
+ Ref<TagType> tagType = GetView()->GetTagTypeByName(tagTypeName);
if (!tagType)
return nullptr;
@@ -1706,7 +1706,7 @@ Ref<Tag> Function::CreateUserAddressTag(Architecture* arch, uint64_t addr, Ref<T
Ref<Tag> Function::CreateAutoFunctionTag(const std::string& tagTypeName, const std::string& data, bool unique)
{
- Ref<TagType> tagType = GetView()->GetTagType(tagTypeName);
+ Ref<TagType> tagType = GetView()->GetTagTypeByName(tagTypeName);
if (!tagType)
return nullptr;
@@ -1736,7 +1736,7 @@ Ref<Tag> Function::CreateAutoFunctionTag(Ref<TagType> tagType, const std::string
Ref<Tag> Function::CreateUserFunctionTag(const std::string& tagTypeName, const std::string& data, bool unique)
{
- Ref<TagType> tagType = GetView()->GetTagType(tagTypeName);
+ Ref<TagType> tagType = GetView()->GetTagTypeByName(tagTypeName);
if (!tagType)
return nullptr;