From 3808f91664f9632eb9d754a1ff99447b50468b36 Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Sat, 3 Jul 2021 01:08:47 -0400 Subject: Cleanup tags and comments in many places Fixes #1926 #2374 #2325 #2204 #1652 and possibly others --- binaryninjaapi.h | 33 ++++- binaryninjacore.h | 38 +++++- binaryview.cpp | 80 +++++++++++- function.cpp | 144 +++++++++++++++++++++ python/binaryview.py | 206 ++++++++++++++++++++++++++++-- python/function.py | 345 +++++++++++++++++++++++++++++++++++++++++++++++++-- ui/linearview.h | 7 ++ ui/uicomment.h | 72 ++++++----- 8 files changed, 862 insertions(+), 63 deletions(-) diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 6d4119ca..7927ede9 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -1695,20 +1695,30 @@ __attribute__ ((format (printf, 1, 2))) std::vector GetAllAddressTagReferences(); std::vector GetAllFunctionTagReferences(); std::vector GetAllTagReferencesOfType(Ref tagType); - std::vector GetTagReferencesOfType(Ref tagType); + std::vector GetTagReferencesOfType(Ref tagType); size_t GetTagReferencesOfTypeCount(Ref tagType); size_t GetAllTagReferencesOfTypeCount(Ref tagType); std::map, size_t> GetAllTagReferenceTypeCounts(); std::vector GetDataTagReferences(); + std::vector GetAutoDataTagReferences(); + std::vector GetUserDataTagReferences(); std::vector> GetDataTags(uint64_t addr); + std::vector> GetAutoDataTags(uint64_t addr); + std::vector> GetUserDataTags(uint64_t addr); std::vector> GetDataTagsOfType(uint64_t addr, Ref tagType); - std::vector> GetDataTagsInRange(uint64_t start, uint64_t end); + std::vector> GetAutoDataTagsOfType(uint64_t addr, Ref tagType); + std::vector> GetUserDataTagsOfType(uint64_t addr, Ref tagType); + std::vector GetDataTagsInRange(uint64_t start, uint64_t end); + std::vector GetAutoDataTagsInRange(uint64_t start, uint64_t end); + std::vector GetUserDataTagsInRange(uint64_t start, uint64_t end); void AddAutoDataTag(uint64_t addr, Ref tag); void RemoveAutoDataTag(uint64_t addr, Ref tag); + void RemoveAutoDataTagsOfType(uint64_t addr, Ref tagType); void AddUserDataTag(uint64_t addr, Ref tag); void RemoveUserDataTag(uint64_t addr, Ref tag); + void RemoveUserDataTagsOfType(uint64_t addr, Ref tagType); void RemoveTagReference(const TagReference& ref); Ref CreateAutoDataTag(uint64_t addr, const std::string& tagTypeName, const std::string& data, bool unique = false); @@ -3309,20 +3319,39 @@ __attribute__ ((format (printf, 1, 2))) std::vector GetTagReferencesOfType(Ref tagType); std::vector GetAddressTagReferences(); + std::vector GetAutoAddressTagReferences(); + std::vector GetUserAddressTagReferences(); std::vector> GetAddressTags(Architecture* arch, uint64_t addr); + std::vector> GetAutoAddressTags(Architecture* arch, uint64_t addr); + std::vector> GetUserAddressTags(Architecture* arch, uint64_t addr); std::vector> GetAddressTagsOfType(Architecture* arch, uint64_t addr, Ref tagType); + std::vector> GetAutoAddressTagsOfType(Architecture* arch, uint64_t addr, Ref tagType); + std::vector> GetUserAddressTagsOfType(Architecture* arch, uint64_t addr, Ref tagType); + std::vector GetAddressTagsInRange(Architecture* arch, uint64_t start, uint64_t end); + std::vector GetAutoAddressTagsInRange(Architecture* arch, uint64_t start, uint64_t end); + std::vector GetUserAddressTagsInRange(Architecture* arch, uint64_t start, uint64_t end); void AddAutoAddressTag(Architecture* arch, uint64_t addr, Ref tag); void RemoveAutoAddressTag(Architecture* arch, uint64_t addr, Ref tag); + void RemoveAutoAddressTagsOfType(Architecture* arch, uint64_t addr, Ref tagType); void AddUserAddressTag(Architecture* arch, uint64_t addr, Ref tag); void RemoveUserAddressTag(Architecture* arch, uint64_t addr, Ref tag); + void RemoveUserAddressTagsOfType(Architecture* arch, uint64_t addr, Ref tagType); std::vector GetFunctionTagReferences(); + std::vector GetAutoFunctionTagReferences(); + std::vector GetUserFunctionTagReferences(); std::vector> GetFunctionTags(); + std::vector> GetAutoFunctionTags(); + std::vector> GetUserFunctionTags(); std::vector> GetFunctionTagsOfType(Ref tagType); + std::vector> GetAutoFunctionTagsOfType(Ref tagType); + std::vector> GetUserFunctionTagsOfType(Ref tagType); void AddAutoFunctionTag(Ref tag); void RemoveAutoFunctionTag(Ref tag); + void RemoveAutoFunctionTagsOfType(Ref tagType); void AddUserFunctionTag(Ref tag); void RemoveUserFunctionTag(Ref tag); + void RemoveUserFunctionTagsOfType(Ref tagType); 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); diff --git a/binaryninjacore.h b/binaryninjacore.h index 0f6ac60c..bbb96497 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -27,14 +27,14 @@ // Current ABI version for linking to the core. This is incremented any time // there are changes to the API that affect linking, including new functions, // new types, or modifications to existing functions or types. -#define BN_CURRENT_CORE_ABI_VERSION 11 +#define BN_CURRENT_CORE_ABI_VERSION 12 // Minimum ABI version that is supported for loading of plugins. Plugins that // are linked to an ABI version less than this will not be able to load and // will require rebuilding. The minimum version is increased when there are // incompatible changes that break binary compatibility, such as changes to // existing types or functions. -#define BN_MINIMUM_CORE_ABI_VERSION 11 +#define BN_MINIMUM_CORE_ABI_VERSION 12 #ifdef __GNUC__ # ifdef BINARYNINJACORE_LIBRARY @@ -589,6 +589,7 @@ extern "C" ShowCallParameterNames = 6, ShowRegisterHighlight = 7, ShowFunctionAddress = 8, + ShowFunctionHeader = 9, // Linear disassembly options GroupLinearDisassemblyFunctions = 64, @@ -3790,15 +3791,25 @@ __attribute__ ((format (printf, 1, 2))) BINARYNINJACOREAPI BNTagReference* BNGetAllTagReferencesOfType(BNBinaryView* view, BNTagType* tagType, size_t* count); BINARYNINJACOREAPI BNTagReference* BNGetTagReferencesOfType(BNBinaryView* view, BNTagType* tagType, size_t* count); BINARYNINJACOREAPI BNTagReference* BNGetDataTagReferences(BNBinaryView* view, size_t* count); + BINARYNINJACOREAPI BNTagReference* BNGetAutoDataTagReferences(BNBinaryView* view, size_t* count); + BINARYNINJACOREAPI BNTagReference* BNGetUserDataTagReferences(BNBinaryView* view, size_t* count); + BINARYNINJACOREAPI void BNRemoveTagReference(BNBinaryView* view, BNTagReference ref); BINARYNINJACOREAPI void BNFreeTagReferences(BNTagReference* refs, size_t count); BINARYNINJACOREAPI BNTag** BNGetDataTags(BNBinaryView* view, uint64_t addr, size_t* count); + BINARYNINJACOREAPI BNTag** BNGetAutoDataTags(BNBinaryView* view, uint64_t addr, size_t* count); + BINARYNINJACOREAPI BNTag** BNGetUserDataTags(BNBinaryView* view, uint64_t addr, size_t* count); BINARYNINJACOREAPI BNTag** BNGetDataTagsOfType(BNBinaryView* view, uint64_t addr, BNTagType* tagType, size_t* count); - BINARYNINJACOREAPI BNTag** BNGetDataTagsInRange(BNBinaryView* view, uint64_t start, uint64_t end, size_t* count); + BINARYNINJACOREAPI BNTag** BNGetAutoDataTagsOfType(BNBinaryView* view, uint64_t addr, BNTagType* tagType, size_t* count); + BINARYNINJACOREAPI BNTag** BNGetUserDataTagsOfType(BNBinaryView* view, uint64_t addr, BNTagType* tagType, size_t* count); + BINARYNINJACOREAPI BNTagReference* BNGetDataTagsInRange(BNBinaryView* view, uint64_t start, uint64_t end, size_t* count); + BINARYNINJACOREAPI BNTagReference* BNGetAutoDataTagsInRange(BNBinaryView* view, uint64_t start, uint64_t end, size_t* count); + BINARYNINJACOREAPI BNTagReference* BNGetUserDataTagsInRange(BNBinaryView* view, uint64_t start, uint64_t end, size_t* count); BINARYNINJACOREAPI void BNAddAutoDataTag(BNBinaryView* view, uint64_t addr, BNTag* tag); BINARYNINJACOREAPI void BNRemoveAutoDataTag(BNBinaryView* view, uint64_t addr, BNTag* tag); + BINARYNINJACOREAPI void BNRemoveAutoDataTagsOfType(BNBinaryView* view, uint64_t addr, BNTagType* tagType); BINARYNINJACOREAPI void BNAddUserDataTag(BNBinaryView* view, uint64_t addr, BNTag* tag); BINARYNINJACOREAPI void BNRemoveUserDataTag(BNBinaryView* view, uint64_t addr, BNTag* tag); - BINARYNINJACOREAPI void BNRemoveTagReference(BNBinaryView* view, BNTagReference ref); + BINARYNINJACOREAPI void BNRemoveUserDataTagsOfType(BNBinaryView* view, uint64_t addr, BNTagType* tagType); BINARYNINJACOREAPI size_t BNGetTagReferencesOfTypeCount(BNBinaryView* view, BNTagType* tagType); BINARYNINJACOREAPI size_t BNGetAllTagReferencesOfTypeCount(BNBinaryView* view, BNTagType* tagType); @@ -3809,20 +3820,39 @@ __attribute__ ((format (printf, 1, 2))) BINARYNINJACOREAPI BNTagReference* BNGetFunctionTagReferencesOfType(BNFunction* func, BNTagType* tagType, size_t* count); BINARYNINJACOREAPI BNTagReference* BNGetAddressTagReferences(BNFunction* func, size_t* count); + BINARYNINJACOREAPI BNTagReference* BNGetAutoAddressTagReferences(BNFunction* func, size_t* count); + BINARYNINJACOREAPI BNTagReference* BNGetUserAddressTagReferences(BNFunction* func, size_t* count); BINARYNINJACOREAPI BNTag** BNGetAddressTags(BNFunction* func, BNArchitecture* arch, uint64_t addr, size_t* count); + BINARYNINJACOREAPI BNTag** BNGetAutoAddressTags(BNFunction* func, BNArchitecture* arch, uint64_t addr, size_t* count); + BINARYNINJACOREAPI BNTag** BNGetUserAddressTags(BNFunction* func, BNArchitecture* arch, uint64_t addr, size_t* count); BINARYNINJACOREAPI BNTag** BNGetAddressTagsOfType(BNFunction* func, BNArchitecture* arch, uint64_t addr, BNTagType* tagType, size_t* count); + BINARYNINJACOREAPI BNTag** BNGetAutoAddressTagsOfType(BNFunction* func, BNArchitecture* arch, uint64_t addr, BNTagType* tagType, size_t* count); + BINARYNINJACOREAPI BNTag** BNGetUserAddressTagsOfType(BNFunction* func, BNArchitecture* arch, uint64_t addr, BNTagType* tagType, size_t* count); + BINARYNINJACOREAPI BNTagReference* BNGetAddressTagsInRange(BNFunction* func, BNArchitecture* arch, uint64_t start, uint64_t end, size_t* count); + BINARYNINJACOREAPI BNTagReference* BNGetAutoAddressTagsInRange(BNFunction* func, BNArchitecture* arch, uint64_t start, uint64_t end, size_t* count); + BINARYNINJACOREAPI BNTagReference* BNGetUserAddressTagsInRange(BNFunction* func, BNArchitecture* arch, uint64_t start, uint64_t end, size_t* count); BINARYNINJACOREAPI void BNAddAutoAddressTag(BNFunction* func, BNArchitecture* arch, uint64_t addr, BNTag* tag); BINARYNINJACOREAPI void BNRemoveAutoAddressTag(BNFunction* func, BNArchitecture* arch, uint64_t addr, BNTag* tag); + BINARYNINJACOREAPI void BNRemoveAutoAddressTagsOfType(BNFunction* func, BNArchitecture* arch, uint64_t addr, BNTagType* tagType); BINARYNINJACOREAPI void BNAddUserAddressTag(BNFunction* func, BNArchitecture* arch, uint64_t addr, BNTag* tag); BINARYNINJACOREAPI void BNRemoveUserAddressTag(BNFunction* func, BNArchitecture* arch, uint64_t addr, BNTag* tag); + BINARYNINJACOREAPI void BNRemoveUserAddressTagsOfType(BNFunction* func, BNArchitecture* arch, uint64_t addr, BNTagType* tagType); BINARYNINJACOREAPI BNTagReference* BNGetFunctionTagReferences(BNFunction* func, size_t* count); + BINARYNINJACOREAPI BNTagReference* BNGetAutoFunctionTagReferences(BNFunction* func, size_t* count); + BINARYNINJACOREAPI BNTagReference* BNGetUserFunctionTagReferences(BNFunction* func, size_t* count); BINARYNINJACOREAPI BNTag** BNGetFunctionTags(BNFunction* func, size_t* count); + BINARYNINJACOREAPI BNTag** BNGetAutoFunctionTags(BNFunction* func, size_t* count); + BINARYNINJACOREAPI BNTag** BNGetUserFunctionTags(BNFunction* func, size_t* count); BINARYNINJACOREAPI BNTag** BNGetFunctionTagsOfType(BNFunction* func, BNTagType* tagType, size_t* count); + BINARYNINJACOREAPI BNTag** BNGetAutoFunctionTagsOfType(BNFunction* func, BNTagType* tagType, size_t* count); + BINARYNINJACOREAPI BNTag** BNGetUserFunctionTagsOfType(BNFunction* func, BNTagType* tagType, size_t* count); BINARYNINJACOREAPI void BNAddAutoFunctionTag(BNFunction* func, BNTag* tag); BINARYNINJACOREAPI void BNRemoveAutoFunctionTag(BNFunction* func, BNTag* tag); + BINARYNINJACOREAPI void BNRemoveAutoFunctionTagsOfType(BNFunction* func, BNTagType* tagType); BINARYNINJACOREAPI void BNAddUserFunctionTag(BNFunction* func, BNTag* tag); BINARYNINJACOREAPI void BNRemoveUserFunctionTag(BNFunction* func, BNTag* tag); + BINARYNINJACOREAPI void BNRemoveUserFunctionTagsOfType(BNFunction* func, BNTagType* tagType); BINARYNINJACOREAPI BNPerformanceInfo* BNGetFunctionAnalysisPerformanceInfo(BNFunction* func, size_t* count); BINARYNINJACOREAPI void BNFreeAnalysisPerformanceInfo(BNPerformanceInfo* info, size_t count); diff --git a/binaryview.cpp b/binaryview.cpp index 139e319c..dd61f0e7 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -2569,6 +2569,22 @@ std::vector BinaryView::GetDataTagReferences() } +std::vector BinaryView::GetAutoDataTagReferences() +{ + size_t count; + BNTagReference* refs = BNGetAutoDataTagReferences(m_object, &count); + return TagReference::ConvertAndFreeTagReferenceList(refs, count); +} + + +std::vector BinaryView::GetUserDataTagReferences() +{ + size_t count; + BNTagReference* refs = BNGetUserDataTagReferences(m_object, &count); + return TagReference::ConvertAndFreeTagReferenceList(refs, count); +} + + std::vector> BinaryView::GetDataTags(uint64_t addr) { size_t count; @@ -2577,6 +2593,22 @@ std::vector> BinaryView::GetDataTags(uint64_t addr) } +std::vector> BinaryView::GetAutoDataTags(uint64_t addr) +{ + size_t count; + BNTag** tags = BNGetAutoDataTags(m_object, addr, &count); + return Tag::ConvertAndFreeTagList(tags, count); +} + + +std::vector> BinaryView::GetUserDataTags(uint64_t addr) +{ + size_t count; + BNTag** tags = BNGetUserDataTags(m_object, addr, &count); + return Tag::ConvertAndFreeTagList(tags, count); +} + + std::vector> BinaryView::GetDataTagsOfType(uint64_t addr, Ref tagType) { size_t count; @@ -2585,14 +2617,46 @@ std::vector> BinaryView::GetDataTagsOfType(uint64_t addr, Ref } -std::vector> BinaryView::GetDataTagsInRange(uint64_t start, uint64_t end) +std::vector> BinaryView::GetAutoDataTagsOfType(uint64_t addr, Ref tagType) +{ + size_t count; + BNTag** tags = BNGetAutoDataTagsOfType(m_object, addr, tagType->GetObject(), &count); + return Tag::ConvertAndFreeTagList(tags, count); +} + + +std::vector> BinaryView::GetUserDataTagsOfType(uint64_t addr, Ref tagType) { size_t count; - BNTag** tags = BNGetDataTagsInRange(m_object, start, end, &count); + BNTag** tags = BNGetUserDataTagsOfType(m_object, addr, tagType->GetObject(), &count); return Tag::ConvertAndFreeTagList(tags, count); } +std::vector BinaryView::GetDataTagsInRange(uint64_t start, uint64_t end) +{ + size_t count; + BNTagReference* refs = BNGetDataTagsInRange(m_object, start, end, &count); + return TagReference::ConvertAndFreeTagReferenceList(refs, count); +} + + +std::vector BinaryView::GetAutoDataTagsInRange(uint64_t start, uint64_t end) +{ + size_t count; + BNTagReference* refs = BNGetAutoDataTagsInRange(m_object, start, end, &count); + return TagReference::ConvertAndFreeTagReferenceList(refs, count); +} + + +std::vector BinaryView::GetUserDataTagsInRange(uint64_t start, uint64_t end) +{ + size_t count; + BNTagReference* refs = BNGetUserDataTagsInRange(m_object, start, end, &count); + return TagReference::ConvertAndFreeTagReferenceList(refs, count); +} + + void BinaryView::AddAutoDataTag(uint64_t addr, Ref tag) { BNAddAutoDataTag(m_object, addr, tag->GetObject()); @@ -2605,6 +2669,12 @@ void BinaryView::RemoveAutoDataTag(uint64_t addr, Ref tag) } +void BinaryView::RemoveAutoDataTagsOfType(uint64_t addr, Ref tagType) +{ + BNRemoveAutoDataTagsOfType(m_object, addr, tagType->GetObject()); +} + + void BinaryView::AddUserDataTag(uint64_t addr, Ref tag) { BNAddUserDataTag(m_object, addr, tag->GetObject()); @@ -2617,6 +2687,12 @@ void BinaryView::RemoveUserDataTag(uint64_t addr, Ref tag) } +void BinaryView::RemoveUserDataTagsOfType(uint64_t addr, Ref tagType) +{ + BNRemoveUserDataTagsOfType(m_object, addr, tagType->GetObject()); +} + + void BinaryView::RemoveTagReference(const TagReference& ref) { BNRemoveTagReference(m_object, (BNTagReference)ref); diff --git a/function.cpp b/function.cpp index 36d5a313..70985d64 100644 --- a/function.cpp +++ b/function.cpp @@ -1557,6 +1557,22 @@ std::vector Function::GetAddressTagReferences() } +std::vector Function::GetAutoAddressTagReferences() +{ + size_t count; + BNTagReference* refs = BNGetAutoAddressTagReferences(m_object, &count); + return TagReference::ConvertAndFreeTagReferenceList(refs, count); +} + + +std::vector Function::GetUserAddressTagReferences() +{ + size_t count; + BNTagReference* refs = BNGetUserAddressTagReferences(m_object, &count); + return TagReference::ConvertAndFreeTagReferenceList(refs, count); +} + + std::vector> Function::GetAddressTags(Architecture* arch, uint64_t addr) { size_t count; @@ -1565,6 +1581,22 @@ std::vector> Function::GetAddressTags(Architecture* arch, uint64_t addr } +std::vector> Function::GetAutoAddressTags(Architecture* arch, uint64_t addr) +{ + size_t count; + BNTag** tags = BNGetAutoAddressTags(m_object, arch->GetObject(), addr, &count); + return Tag::ConvertAndFreeTagList(tags, count); +} + + +std::vector> Function::GetUserAddressTags(Architecture* arch, uint64_t addr) +{ + size_t count; + BNTag** tags = BNGetUserAddressTags(m_object, arch->GetObject(), addr, &count); + return Tag::ConvertAndFreeTagList(tags, count); +} + + std::vector> Function::GetAddressTagsOfType(Architecture* arch, uint64_t addr, Ref tagType) { size_t count; @@ -1573,6 +1605,46 @@ std::vector> Function::GetAddressTagsOfType(Architecture* arch, uint64_ } +std::vector> Function::GetAutoAddressTagsOfType(Architecture* arch, uint64_t addr, Ref tagType) +{ + size_t count; + BNTag** tags = BNGetAutoAddressTagsOfType(m_object, arch->GetObject(), addr, tagType->GetObject(), &count); + return Tag::ConvertAndFreeTagList(tags, count); +} + + +std::vector> Function::GetUserAddressTagsOfType(Architecture* arch, uint64_t addr, Ref tagType) +{ + size_t count; + BNTag** tags = BNGetUserAddressTagsOfType(m_object, arch->GetObject(), addr, tagType->GetObject(), &count); + return Tag::ConvertAndFreeTagList(tags, count); +} + + +std::vector Function::GetAddressTagsInRange(Architecture* arch, uint64_t start, uint64_t end) +{ + size_t count; + BNTagReference* refs = BNGetAddressTagsInRange(m_object, arch->GetObject(), start, end, &count); + return TagReference::ConvertAndFreeTagReferenceList(refs, count); +} + + +std::vector Function::GetAutoAddressTagsInRange(Architecture* arch, uint64_t start, uint64_t end) +{ + size_t count; + BNTagReference* refs = BNGetAutoAddressTagsInRange(m_object, arch->GetObject(), start, end, &count); + return TagReference::ConvertAndFreeTagReferenceList(refs, count); +} + + +std::vector Function::GetUserAddressTagsInRange(Architecture* arch, uint64_t start, uint64_t end) +{ + size_t count; + BNTagReference* refs = BNGetUserAddressTagsInRange(m_object, arch->GetObject(), start, end, &count); + return TagReference::ConvertAndFreeTagReferenceList(refs, count); +} + + void Function::AddAutoAddressTag(Architecture* arch, uint64_t addr, Ref tag) { BNAddAutoAddressTag(m_object, arch->GetObject(), addr, tag->GetObject()); @@ -1585,6 +1657,12 @@ void Function::RemoveAutoAddressTag(Architecture* arch, uint64_t addr, Ref } +void Function::RemoveAutoAddressTagsOfType(Architecture* arch, uint64_t addr, Ref tagType) +{ + BNRemoveAutoAddressTagsOfType(m_object, arch->GetObject(), addr, tagType->GetObject()); +} + + void Function::AddUserAddressTag(Architecture* arch, uint64_t addr, Ref tag) { BNAddUserAddressTag(m_object, arch->GetObject(), addr, tag->GetObject()); @@ -1597,6 +1675,12 @@ void Function::RemoveUserAddressTag(Architecture* arch, uint64_t addr, Ref } +void Function::RemoveUserAddressTagsOfType(Architecture* arch, uint64_t addr, Ref tagType) +{ + BNRemoveUserAddressTagsOfType(m_object, arch->GetObject(), addr, tagType->GetObject()); +} + + std::vector Function::GetFunctionTagReferences() { size_t count; @@ -1605,6 +1689,22 @@ std::vector Function::GetFunctionTagReferences() } +std::vector Function::GetAutoFunctionTagReferences() +{ + size_t count; + BNTagReference* refs = BNGetAutoFunctionTagReferences(m_object, &count); + return TagReference::ConvertAndFreeTagReferenceList(refs, count); +} + + +std::vector Function::GetUserFunctionTagReferences() +{ + size_t count; + BNTagReference* refs = BNGetUserFunctionTagReferences(m_object, &count); + return TagReference::ConvertAndFreeTagReferenceList(refs, count); +} + + std::vector> Function::GetFunctionTags() { size_t count; @@ -1613,6 +1713,22 @@ std::vector> Function::GetFunctionTags() } +std::vector> Function::GetAutoFunctionTags() +{ + size_t count; + BNTag** tags = BNGetAutoFunctionTags(m_object, &count); + return Tag::ConvertAndFreeTagList(tags, count); +} + + +std::vector> Function::GetUserFunctionTags() +{ + size_t count; + BNTag** tags = BNGetUserFunctionTags(m_object, &count); + return Tag::ConvertAndFreeTagList(tags, count); +} + + std::vector> Function::GetFunctionTagsOfType(Ref tagType) { size_t count; @@ -1621,6 +1737,22 @@ std::vector> Function::GetFunctionTagsOfType(Ref tagType) } +std::vector> Function::GetAutoFunctionTagsOfType(Ref tagType) +{ + size_t count; + BNTag** tags = BNGetAutoFunctionTagsOfType(m_object, tagType->GetObject(), &count); + return Tag::ConvertAndFreeTagList(tags, count); +} + + +std::vector> Function::GetUserFunctionTagsOfType(Ref tagType) +{ + size_t count; + BNTag** tags = BNGetUserFunctionTagsOfType(m_object, tagType->GetObject(), &count); + return Tag::ConvertAndFreeTagList(tags, count); +} + + void Function::AddAutoFunctionTag(Ref tag) { BNAddAutoFunctionTag(m_object, tag->GetObject()); @@ -1633,6 +1765,12 @@ void Function::RemoveAutoFunctionTag(Ref tag) } +void Function::RemoveAutoFunctionTagsOfType(Ref tagType) +{ + BNRemoveAutoFunctionTagsOfType(m_object, tagType->GetObject()); +} + + void Function::AddUserFunctionTag(Ref tag) { BNAddUserFunctionTag(m_object, tag->GetObject()); @@ -1645,6 +1783,12 @@ void Function::RemoveUserFunctionTag(Ref tag) } +void Function::RemoveUserFunctionTagsOfType(Ref tagType) +{ + BNRemoveUserFunctionTagsOfType(m_object, tagType->GetObject()); +} + + Ref Function::CreateAutoAddressTag(Architecture* arch, uint64_t addr, const std::string& tagTypeName, const std::string& data, bool unique) { Ref tagType = GetView()->GetTagTypeByName(tagTypeName); diff --git a/python/binaryview.py b/python/binaryview.py index ae88b4c0..a4b36f43 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -4325,12 +4325,46 @@ class BinaryView(object): :type: list(int, Tag) """ count = ctypes.c_ulonglong() - tags = core.BNGetDataTagReferences(self.handle, count) + refs = core.BNGetDataTagReferences(self.handle, count) result = [] for i in range(0, count.value): - tag = Tag(core.BNNewTagReference(tags[i].tag)) - result.append((tags[i].addr, tag)) - core.BNFreeTagReferences(tags, count.value) + tag = Tag(core.BNNewTagReference(refs[i].tag)) + result.append((refs[i].addr, tag)) + core.BNFreeTagReferences(refs, count.value) + return result + + @property + def auto_data_tags(self): + """ + ``auto_data_tags`` gets a list of all auto-defined data Tags in the view. + Tags are returned as a list of (address, Tag) pairs. + + :type: list(int, Tag) + """ + count = ctypes.c_ulonglong() + refs = core.BNGetAutoDataTagReferences(self.handle, count) + result = [] + for i in range(0, count.value): + tag = Tag(core.BNNewTagReference(refs[i].tag)) + result.append((refs[i].addr, tag)) + core.BNFreeTagReferences(refs, count.value) + return result + + @property + def user_data_tags(self): + """ + ``user_data_tags`` gets a list of all user data Tags in the view. + Tags are returned as a list of (address, Tag) pairs. + + :type: list(int, Tag) + """ + count = ctypes.c_ulonglong() + refs = core.BNGetUserDataTagReferences(self.handle, count) + result = [] + for i in range(0, count.value): + tag = Tag(core.BNNewTagReference(refs[i].tag)) + result.append((refs[i].addr, tag)) + core.BNFreeTagReferences(refs, count.value) return result def get_data_tags_at(self, addr): @@ -4349,27 +4383,149 @@ class BinaryView(object): core.BNFreeTagList(tags, count.value) return result - def get_data_tags_in_range(self, address_range): + def get_auto_data_tags_at(self, addr): """ - ``get_data_tags_in_range`` gets a list of all data Tags in a given range. - Range is inclusive at the start, exclusive at the end. + ``get_auto_data_tags_at`` gets a list of all auto-defined Tags for a data address. - :param AddressRange address_range: Address range from which to get tags + :param int addr: Address to get tags at :return: A list of data Tags :rtype: list(Tag) """ count = ctypes.c_ulonglong() - tags = core.BNGetDataTagsInRange(self.handle, address_range.start, address_range.end, count) + tags = core.BNGetAutoDataTags(self.handle, addr, count) result = [] for i in range(0, count.value): result.append(Tag(core.BNNewTagReference(tags[i]))) core.BNFreeTagList(tags, count.value) return result + def get_user_data_tags_at(self, addr): + """ + ``get_user_data_tags_at`` gets a list of all user Tags for a data address. + + :param int addr: Address to get tags at + :return: A list of data Tags + :rtype: list(Tag) + """ + count = ctypes.c_ulonglong() + tags = core.BNGetUserDataTags(self.handle, addr, count) + result = [] + for i in range(0, count.value): + result.append(Tag(core.BNNewTagReference(tags[i]))) + core.BNFreeTagList(tags, count.value) + return result + + def get_data_tags_of_type(self, addr, tag_type): + """ + ``get_data_tags_of_type`` gets a list of all Tags for a data address of a given type. + + :param int addr: Address to get tags at + :param TagType tag_type: TagType object to match in searching + :return: A list of data Tags + :rtype: list(Tag) + """ + count = ctypes.c_ulonglong() + tags = core.BNGetDataTagsOfType(self.handle, addr, tag_type.handle, count) + result = [] + for i in range(0, count.value): + result.append(Tag(core.BNNewTagReference(tags[i]))) + core.BNFreeTagList(tags, count.value) + return result + + def get_auto_data_tags_of_type(self, addr, tag_type): + """ + ``get_auto_data_tags_of_type`` gets a list of all auto-defined Tags for a data address of a given type. + + :param int addr: Address to get tags at + :param TagType tag_type: TagType object to match in searching + :return: A list of data Tags + :rtype: list(Tag) + """ + count = ctypes.c_ulonglong() + tags = core.BNGetAutoDataTagsOfType(self.handle, addr, tag_type.handle, count) + result = [] + for i in range(0, count.value): + result.append(Tag(core.BNNewTagReference(tags[i]))) + core.BNFreeTagList(tags, count.value) + return result + + def get_user_data_tags_of_type(self, addr, tag_type): + """ + ``get_user_data_tags_of_type`` gets a list of all user Tags for a data address of a given type. + + :param int addr: Address to get tags at + :param TagType tag_type: TagType object to match in searching + :return: A list of data Tags + :rtype: list(Tag) + """ + count = ctypes.c_ulonglong() + tags = core.BNGetUserDataTagsOfType(self.handle, addr, tag_type.handle, count) + result = [] + for i in range(0, count.value): + result.append(Tag(core.BNNewTagReference(tags[i]))) + core.BNFreeTagList(tags, count.value) + return result + + def get_data_tags_in_range(self, address_range): + """ + ``get_data_tags_in_range`` gets a list of all data Tags in a given range. + Range is inclusive at the start, exclusive at the end. + + :param AddressRange address_range: Address range from which to get tags + :return: A list of (address, data tag) tuples + :rtype: list((int, Tag)) + """ + count = ctypes.c_ulonglong() + refs = core.BNGetDataTagsInRange(self.handle, address_range.start, address_range.end, count) + result = [] + for i in range(0, count.value): + tag = Tag(core.BNNewTagReference(refs[i].tag)) + result.append((refs[i].addr, tag)) + core.BNFreeTagReferences(refs, count.value) + return result + + def get_auto_data_tags_in_range(self, address_range): + """ + ``get_auto_data_tags_in_range`` gets a list of all auto-defined data Tags in a given range. + Range is inclusive at the start, exclusive at the end. + + :param AddressRange address_range: Address range from which to get tags + :return: A list of (address, data tag) tuples + :rtype: list((int, Tag)) + """ + count = ctypes.c_ulonglong() + refs = core.BNGetAutoDataTagsInRange(self.handle, address_range.start, address_range.end, count) + result = [] + for i in range(0, count.value): + tag = Tag(core.BNNewTagReference(refs[i].tag)) + result.append((refs[i].addr, tag)) + core.BNFreeTagReferences(refs, count.value) + return result + + def get_user_data_tags_in_range(self, address_range): + """ + ``get_user_data_tags_in_range`` gets a list of all user data Tags in a given range. + Range is inclusive at the start, exclusive at the end. + + :param AddressRange address_range: Address range from which to get tags + :return: A list of (address, data tag) tuples + :rtype: list((int, Tag)) + """ + count = ctypes.c_ulonglong() + refs = core.BNGetUserDataTagsInRange(self.handle, address_range.start, address_range.end, count) + result = [] + for i in range(0, count.value): + tag = Tag(core.BNNewTagReference(refs[i].tag)) + result.append((refs[i].addr, tag)) + core.BNFreeTagReferences(refs, count.value) + return result + def add_user_data_tag(self, addr, tag): """ ``add_user_data_tag`` adds an already-created Tag object at a data address. Since this adds a user tag, it will be added to the current undo buffer. + If you want want to create the tag as well, consider using + :meth:`create_user_data_tag ` :param int addr: Address at which to add the tag :param Tag tag: Tag object to be added @@ -4414,15 +4570,28 @@ class BinaryView(object): ``remove_user_data_tag`` removes a Tag object at a data address. Since this removes a user tag, it will be added to the current undo buffer. - :param int addr: Address at which to add the tag - :param Tag tag: Tag object to be added + :param int addr: Address at which to remove the tag + :param Tag tag: Tag object to be removed :rtype: None """ core.BNRemoveUserDataTag(self.handle, addr, tag.handle) + def remove_user_data_tags_of_type(self, addr, tag_type): + """ + ``remove_user_data_tags_of_type`` removes all data tags at the given address of the given type. + Since this removes user tags, it will be added to the current undo buffer. + + :param int addr: Address at which to add the tags + :param TagType tag_type: TagType object to match for removing + :rtype: None + """ + core.BNRemoveUserDataTagsOfType(self.handle, addr, tag_type.handle) + def add_auto_data_tag(self, addr, tag): """ ``add_auto_data_tag`` adds an already-created Tag object at a data address. + If you want want to create the tag as well, consider using + :meth:`create_auto_data_tag ` :param int addr: Address at which to add the tag :param Tag tag: Tag object to be added @@ -4456,12 +4625,23 @@ class BinaryView(object): ``remove_auto_data_tag`` removes a Tag object at a data address. Since this removes a user tag, it will be added to the current undo buffer. - :param int addr: Address at which to add the tag - :param Tag tag: Tag object to be added + :param int addr: Address at which to remove the tag + :param Tag tag: Tag object to be removed :rtype: None """ core.BNRemoveAutoDataTag(self.handle, addr, tag.handle) + def remove_auto_data_tags_of_type(self, addr, tag_type): + """ + ``remove_auto_data_tags_of_type`` removes all data tags at the given address of the given type. + Since this removes user tags, it will be added to the current undo buffer. + + :param int addr: Address at which to add the tags + :param TagType tag_type: TagType object to match for removing + :rtype: None + """ + core.BNRemoveAutoDataTagsOfType(self.handle, addr, tag_type.handle) + def can_assemble(self, arch=None): """ ``can_assemble`` queries the architecture plugin to determine if the architecture can assemble instructions. diff --git a/python/function.py b/python/function.py index b350046f..64aacb05 100644 --- a/python/function.py +++ b/python/function.py @@ -1614,12 +1614,48 @@ class Function(object): core.BNFreeTagReferences(tags, count.value) return result + @property + def auto_address_tags(self): + """ + ``auto_address_tags`` gets a list of all auto-defined address Tags in the function. + Tags are returned as a list of (arch, address, Tag) tuples. + + :rtype: list((Architecture, int, Tag)) + """ + count = ctypes.c_ulonglong() + tags = core.BNGetAutoAddressTagReferences(self.handle, count) + result = [] + for i in range(0, count.value): + arch = binaryninja.architecture.CoreArchitecture._from_cache(tags[i].arch) + tag = binaryninja.binaryview.Tag(core.BNNewTagReference(tags[i].tag)) + result.append((arch, tags[i].addr, tag)) + core.BNFreeTagReferences(tags, count.value) + return result + + @property + def user_address_tags(self): + """ + ``user_address_tags`` gets a list of all user address Tags in the function. + Tags are returned as a list of (arch, address, Tag) tuples. + + :rtype: list((Architecture, int, Tag)) + """ + count = ctypes.c_ulonglong() + tags = core.BNGetUserAddressTagReferences(self.handle, count) + result = [] + for i in range(0, count.value): + arch = binaryninja.architecture.CoreArchitecture._from_cache(tags[i].arch) + tag = binaryninja.binaryview.Tag(core.BNNewTagReference(tags[i].tag)) + result.append((arch, tags[i].addr, tag)) + core.BNFreeTagReferences(tags, count.value) + return result + def get_address_tags_at(self, addr, arch=None): """ ``get_address_tags_at`` gets a list of all Tags in the function at a given address. :param int addr: Address to get tags at - :param Architecture arch: Architecture for the block in which the Tag is added (optional) + :param Architecture arch: Architecture for the block in which the Tag is located (optional) :return: A list of Tags :rtype: list(Tag) """ @@ -1633,10 +1669,173 @@ class Function(object): core.BNFreeTagList(tags, count.value) return result + def get_auto_address_tags_at(self, addr, arch=None): + """ + ``get_auto_address_tags_at`` gets a list of all auto-defined Tags in the function at a given address. + + :param int addr: Address to get tags at + :param Architecture arch: Architecture for the block in which the Tag is located (optional) + :return: A list of Tags + :rtype: list(Tag) + """ + if arch is None: + arch = self.arch + count = ctypes.c_ulonglong() + tags = core.BNGetAutoAddressTags(self.handle, arch.handle, addr, count) + result = [] + for i in range(0, count.value): + result.append(binaryninja.binaryview.Tag(core.BNNewTagReference(tags[i]))) + core.BNFreeTagList(tags, count.value) + return result + + def get_user_address_tags_at(self, addr, arch=None): + """ + ``get_user_address_tags_at`` gets a list of all user Tags in the function at a given address. + + :param int addr: Address to get tags at + :param Architecture arch: Architecture for the block in which the Tag is located (optional) + :return: A list of Tags + :rtype: list(Tag) + """ + if arch is None: + arch = self.arch + count = ctypes.c_ulonglong() + tags = core.BNGetUserAddressTags(self.handle, arch.handle, addr, count) + result = [] + for i in range(0, count.value): + result.append(binaryninja.binaryview.Tag(core.BNNewTagReference(tags[i]))) + core.BNFreeTagList(tags, count.value) + return result + + def get_address_tags_of_type(self, addr, tag_type, arch=None): + """ + ``get_address_tags_of_type`` gets a list of all Tags in the function at a given address with a given type. + + :param int addr: Address to get tags at + :param TagType tag_type: TagType object to match in searching + :param Architecture arch: Architecture for the block in which the Tags are located (optional) + :return: A list of data Tags + :rtype: list(Tag) + """ + if arch is None: + arch = self.arch + count = ctypes.c_ulonglong() + tags = core.BNGetAddressTagsOfType(self.handle, arch.handle, addr, tag_type.handle, count) + result = [] + for i in range(0, count.value): + result.append(binaryninja.binaryview.Tag(core.BNNewTagReference(tags[i]))) + core.BNFreeTagList(tags, count.value) + return result + + def get_auto_address_tags_of_type(self, addr, tag_type, arch=None): + """ + ``get_auto_address_tags_of_type`` gets a list of all auto-defined Tags in the function at a given address with a given type. + + :param int addr: Address to get tags at + :param TagType tag_type: TagType object to match in searching + :param Architecture arch: Architecture for the block in which the Tags are located (optional) + :return: A list of data Tags + :rtype: list(Tag) + """ + if arch is None: + arch = self.arch + count = ctypes.c_ulonglong() + tags = core.BNGetAutoAddressTagsOfType(self.handle, arch.handle, addr, tag_type.handle, count) + result = [] + for i in range(0, count.value): + result.append(binaryninja.binaryview.Tag(core.BNNewTagReference(tags[i]))) + core.BNFreeTagList(tags, count.value) + return result + + def get_user_address_tags_of_type(self, addr, tag_type, arch=None): + """ + ``get_user_address_tags_of_type`` gets a list of all user Tags in the function at a given address with a given type. + + :param int addr: Address to get tags at + :param TagType tag_type: TagType object to match in searching + :param Architecture arch: Architecture for the block in which the Tags are located (optional) + :return: A list of data Tags + :rtype: list(Tag) + """ + if arch is None: + arch = self.arch + count = ctypes.c_ulonglong() + tags = core.BNGetUserAddressTagsOfType(self.handle, arch.handle, addr, tag_type.handle, count) + result = [] + for i in range(0, count.value): + result.append(binaryninja.binaryview.Tag(core.BNNewTagReference(tags[i]))) + core.BNFreeTagList(tags, count.value) + return result + + def get_address_tags_in_range(self, address_range, arch=None): + """ + ``get_address_tags_in_range`` gets a list of all Tags in the function at a given address. + Range is inclusive at the start, exclusive at the end. + + :param AddressRange address_range: Address range from which to get tags + :param Architecture arch: Architecture for the block in which the Tag is located (optional) + :return: A list of (arch, address, Tag) tuples + :rtype: list((Architecture, int, Tag)) + """ + if arch is None: + arch = self.arch + count = ctypes.c_ulonglong() + refs = core.BNGetAddressTagsInRange(self.handle, arch.handle, address_range.start, address_range.end, count) + result = [] + for i in range(0, count.value): + tag = binaryninja.binaryview.Tag(core.BNNewTagReference(refs[i].tag)) + result.append((arch, refs[i].addr, tag)) + core.BNFreeTagReferences(refs, count.value) + return result + + def get_auto_address_tags_in_range(self, address_range, arch=None): + """ + ``get_auto_address_tags_in_range`` gets a list of all auto-defined Tags in the function at a given address. + Range is inclusive at the start, exclusive at the end. + + :param AddressRange address_range: Address range from which to get tags + :param Architecture arch: Architecture for the block in which the Tag is located (optional) + :return: A list of (arch, address, Tag) tuples + :rtype: list((Architecture, int, Tag)) + """ + if arch is None: + arch = self.arch + count = ctypes.c_ulonglong() + refs = core.BNGetAutoAddressTagsInRange(self.handle, arch.handle, address_range.start, address_range.end, count) + result = [] + for i in range(0, count.value): + tag = binaryninja.binaryview.Tag(core.BNNewTagReference(refs[i].tag)) + result.append((arch, refs[i].addr, tag)) + core.BNFreeTagReferences(refs, count.value) + return result + + def get_user_address_tags_in_range(self, address_range, arch=None): + """ + ``get_user_address_tags_in_range`` gets a list of all user Tags in the function at a given address. + Range is inclusive at the start, exclusive at the end. + + :param AddressRange address_range: Address range from which to get tags + :param Architecture arch: Architecture for the block in which the Tag is located (optional) + :return: A list of (arch, address, Tag) tuples + :rtype: list((Architecture, int, Tag)) + """ + if arch is None: + arch = self.arch + count = ctypes.c_ulonglong() + refs = core.BNGetUserAddressTagsInRange(self.handle, arch.handle, address_range.start, address_range.end, count) + result = [] + for i in range(0, count.value): + tag = binaryninja.binaryview.Tag(core.BNNewTagReference(refs[i].tag)) + result.append((arch, refs[i].addr, tag)) + core.BNFreeTagReferences(refs, count.value) + return result + def add_user_address_tag(self, addr, tag, arch=None): """ ``add_user_address_tag`` adds an already-created Tag object at a given address. Since this adds a user tag, it will be added to the current undo buffer. + If you want want to create the tag as well, consider using + :meth:`create_user_address_tag ` :param int addr: Address at which to add the tag :param Tag tag: Tag object to be added @@ -1679,18 +1878,34 @@ class Function(object): ``remove_user_address_tag`` removes a Tag object at a given address. Since this removes a user tag, it will be added to the current undo buffer. - :param int addr: Address at which to add the tag - :param Tag tag: Tag object to be added - :param Architecture arch: Architecture for the block in which the Tag is added (optional) + :param int addr: Address at which to remove the tag + :param Tag tag: Tag object to be removed + :param Architecture arch: Architecture for the block in which the Tag is located (optional) :rtype: None """ if arch is None: arch = self.arch core.BNRemoveUserAddressTag(self.handle, arch.handle, addr, tag.handle) + def remove_user_address_tags_of_type(self, addr, tag_type, arch=None): + """ + ``remove_user_address_tags_of_type`` removes all tags at the given address of the given type. + Since this removes user tags, it will be added to the current undo buffer. + + :param int addr: Address at which to remove the tag + :param Tag tag_type: TagType object to match for removing + :param Architecture arch: Architecture for the block in which the Tags is located (optional) + :rtype: None + """ + if arch is None: + arch = self.arch + core.BNRemoveUserAddressTagsOfType(self.handle, arch.handle, addr, tag_type.handle) + def add_auto_address_tag(self, addr, tag, arch=None): """ ``add_auto_address_tag`` adds an already-created Tag object at a given address. + If you want want to create the tag as well, consider using + :meth:`create_auto_address_tag ` :param int addr: Address at which to add the tag :param Tag tag: Tag object to be added @@ -1729,15 +1944,28 @@ class Function(object): """ ``remove_auto_address_tag`` removes a Tag object at a given address. - :param int addr: Address at which to add the tag + :param int addr: Address at which to remove the tag :param Tag tag: Tag object to be added - :param Architecture arch: Architecture for the block in which the Tag is added (optional) + :param Architecture arch: Architecture for the block in which the Tag is located (optional) :rtype: None """ if arch is None: arch = self.arch core.BNRemoveAutoAddressTag(self.handle, arch.handle, addr, tag.handle) + def remove_auto_address_tags_of_type(self, addr, tag_type, arch=None): + """ + ``remove_auto_address_tags_of_type`` removes all tags at the given address of the given type. + + :param int addr: Address at which to remove the tags + :param Tag tag_type: TagType object to match for removing + :param Architecture arch: Architecture for the block in which the Tags is located (optional) + :rtype: None + """ + if arch is None: + arch = self.arch + core.BNRemoveAutoAddressTagsOfType(self.handle, arch.handle, addr, tag_type.handle) + @property def function_tags(self): """ @@ -1753,10 +1981,90 @@ class Function(object): core.BNFreeTagList(tags, count.value) return result + @property + def auto_function_tags(self): + """ + ``auto_function_tags`` gets a list of all auto-defined function Tags for the function. + + :rtype: list(Tag) + """ + count = ctypes.c_ulonglong() + tags = core.BNGetAutoFunctionTags(self.handle, count) + result = [] + for i in range(0, count.value): + result.append(binaryninja.binaryview.Tag(core.BNNewTagReference(tags[i]))) + core.BNFreeTagList(tags, count.value) + return result + + @property + def user_function_tags(self): + """ + ``user_function_tags`` gets a list of all user function Tags for the function. + + :rtype: list(Tag) + """ + count = ctypes.c_ulonglong() + tags = core.BNGetUserFunctionTags(self.handle, count) + result = [] + for i in range(0, count.value): + result.append(binaryninja.binaryview.Tag(core.BNNewTagReference(tags[i]))) + core.BNFreeTagList(tags, count.value) + return result + + def get_function_tags_of_type(self, tag_type): + """ + ``get_function_tags_of_type`` gets a list of all function Tags with a given type. + + :param TagType tag_type: TagType object to match in searching + :return: A list of data Tags + :rtype: list(Tag) + """ + count = ctypes.c_ulonglong() + tags = core.BNGetFunctionTagsOfType(self.handle, tag_type.handle, count) + result = [] + for i in range(0, count.value): + result.append(binaryninja.binaryview.Tag(core.BNNewTagReference(tags[i]))) + core.BNFreeTagList(tags, count.value) + return result + + def get_auto_function_tags_of_type(self, tag_type): + """ + ``get_auto_function_tags_of_type`` gets a list of all auto-defined function Tags with a given type. + + :param TagType tag_type: TagType object to match in searching + :return: A list of data Tags + :rtype: list(Tag) + """ + count = ctypes.c_ulonglong() + tags = core.BNGetAutoFunctionTagsOfType(self.handle, tag_type.handle, count) + result = [] + for i in range(0, count.value): + result.append(binaryninja.binaryview.Tag(core.BNNewTagReference(tags[i]))) + core.BNFreeTagList(tags, count.value) + return result + + def get_user_function_tags_of_type(self, tag_type): + """ + ``get_user_function_tags_of_type`` gets a list of all user function Tags with a given type. + + :param TagType tag_type: TagType object to match in searching + :return: A list of data Tags + :rtype: list(Tag) + """ + count = ctypes.c_ulonglong() + tags = core.BNGetUserFunctionTagsOfType(self.handle, tag_type.handle, count) + result = [] + for i in range(0, count.value): + result.append(binaryninja.binaryview.Tag(core.BNNewTagReference(tags[i]))) + core.BNFreeTagList(tags, count.value) + return result + def add_user_function_tag(self, tag): """ ``add_user_function_tag`` adds an already-created Tag object as a function tag. Since this adds a user tag, it will be added to the current undo buffer. + If you want want to create the tag as well, consider using + :meth:`create_user_function_tag ` :param Tag tag: Tag object to be added :rtype: None @@ -1788,14 +2096,26 @@ class Function(object): ``remove_user_function_tag`` removes a Tag object as a function tag. Since this removes a user tag, it will be added to the current undo buffer. - :param Tag tag: Tag object to be added + :param Tag tag: Tag object to be removed :rtype: None """ core.BNRemoveUserFunctionTag(self.handle, tag.handle) + def remove_user_function_tags_of_type(self, tag_type): + """ + ``remove_user_function_tags_of_type`` removes all function Tag objects on a function of a given type + Since this removes user tags, it will be added to the current undo buffer. + + :param TagType tag_type: TagType object to match for removing + :rtype: None + """ + core.BNRemoveUserFunctionTagsOfType(self.handle, tag_type.handle) + def add_auto_function_tag(self, tag): """ ``add_user_function_tag`` adds an already-created Tag object as a function tag. + If you want want to create the tag as well, consider using + :meth:`create_auto_function_tag ` :param Tag tag: Tag object to be added :rtype: None @@ -1825,11 +2145,20 @@ class Function(object): """ ``remove_user_function_tag`` removes a Tag object as a function tag. - :param Tag tag: Tag object to be added + :param Tag tag: Tag object to be removed :rtype: None """ core.BNRemoveAutoFunctionTag(self.handle, tag.handle) + def remove_auto_function_tags_of_type(self, tag_type): + """ + ``remove_user_function_tags_of_type`` removes all function Tag objects on a function of a given type + + :param TagType tag_type: TagType object to match for removing + :rtype: None + """ + core.BNRemoveAutoFunctionTagsOfType(self.handle, tag_type.handle) + @property def low_level_il(self): """Deprecated property provided for compatibility. Use llil instead.""" diff --git a/ui/linearview.h b/ui/linearview.h index 74bc6b7a..60df5c93 100644 --- a/ui/linearview.h +++ b/ui/linearview.h @@ -140,6 +140,7 @@ class BINARYNINJAUIAPI LinearView: public QAbstractScrollArea, public View, publ SettingsRef m_settings; DisassemblySettingsRef m_options; BNFunctionGraphType m_ilViewType; + HexEditorHighlightState m_highlightState; InstructionEdit* m_instrEdit; @@ -334,7 +335,9 @@ public: virtual void OnDataVariableRemoved(BinaryNinja::BinaryView* view, const BinaryNinja::DataVariable& var) override; virtual void OnDataVariableUpdated(BinaryNinja::BinaryView* view, const BinaryNinja::DataVariable& var) override; virtual void OnDataMetadataUpdated(BinaryNinja::BinaryView* view, uint64_t offset) override; + virtual void OnTagAdded(BinaryNinja::BinaryView* data, const BinaryNinja::TagReference& tagRef) override; virtual void OnTagUpdated(BinaryNinja::BinaryView* data, const BinaryNinja::TagReference& tagRef) override; + virtual void OnTagRemoved(BinaryNinja::BinaryView* data, const BinaryNinja::TagReference& tagRef) override; virtual void updateFonts() override; @@ -352,6 +355,10 @@ public: virtual BNFunctionGraphType getILViewType() override { return m_ilViewType; }; virtual void setILViewType(BNFunctionGraphType ilViewType) override; + void setHighlightMode(HexEditorHighlightMode mode); + void setColorMode(HexEditorColorMode mode); + void setContrast(HexEditorHighlightContrast mode); + void toggleOption(BNDisassemblyOption option); virtual bool goToReference(FunctionRef func, uint64_t source, uint64_t target) override; diff --git a/ui/uicomment.h b/ui/uicomment.h index 6fd74917..1ed71af7 100644 --- a/ui/uicomment.h +++ b/ui/uicomment.h @@ -4,43 +4,47 @@ #include "uicontext.h" // these are only intended to be used for the ui -typedef enum +typedef enum { FunctionComment, - AddressComment -}UICommentType; + AddressComment, + DataComment +} UICommentType; class UIComment { - public: - UICommentType type; - FunctionRef func; - BinaryViewRef data; - uint64_t address; - QString content; - - UIComment( UICommentType type, - FunctionRef func, - uint64_t address, - QString content): - type(type), func(func), - address(address), content(content) - {} - - UIComment( UICommentType type, - BinaryViewRef data, - uint64_t address, - QString content): - type(type), data(data), - address(address), content(content) - {} - - UIComment(const UIComment& rhs) - { - type = rhs.type; - func = rhs.func; - data = rhs.data; - address = rhs.address; - content = rhs.content; - } +public: + UICommentType type; + FunctionRef func; + BinaryViewRef data; + uint64_t address; + QString content; + + + UIComment(UICommentType type, + FunctionRef func, + uint64_t address, + QString content): + type(type), func(func), + address(address), content(content) + {} + + + UIComment(UICommentType type, + BinaryViewRef data, + uint64_t address, + QString content): + type(type), data(data), + address(address), content(content) + {} + + + UIComment(const UIComment& rhs) + { + type = rhs.type; + func = rhs.func; + data = rhs.data; + address = rhs.address; + content = rhs.content; + } }; \ No newline at end of file -- cgit v1.3.1