diff options
| author | Glenn Smith <glenn@vector35.com> | 2021-07-03 01:08:47 -0400 |
|---|---|---|
| committer | Glenn Smith <glenn@vector35.com> | 2021-07-09 16:39:09 -0400 |
| commit | 3808f91664f9632eb9d754a1ff99447b50468b36 (patch) | |
| tree | 44f0dbf857de5aeeb03fe27fb2c11aa136074682 | |
| parent | d19f5e85ee26c3d6604798d30ab821d15731cada (diff) | |
Cleanup tags and comments in many places
Fixes #1926 #2374 #2325 #2204 #1652 and possibly others
| -rw-r--r-- | binaryninjaapi.h | 33 | ||||
| -rw-r--r-- | binaryninjacore.h | 38 | ||||
| -rw-r--r-- | binaryview.cpp | 80 | ||||
| -rw-r--r-- | function.cpp | 144 | ||||
| -rw-r--r-- | python/binaryview.py | 206 | ||||
| -rw-r--r-- | python/function.py | 345 | ||||
| -rw-r--r-- | ui/linearview.h | 7 | ||||
| -rw-r--r-- | ui/uicomment.h | 68 |
8 files changed, 860 insertions, 61 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<TagReference> GetAllAddressTagReferences(); std::vector<TagReference> GetAllFunctionTagReferences(); std::vector<TagReference> GetAllTagReferencesOfType(Ref<TagType> tagType); - std::vector<TagReference> GetTagReferencesOfType(Ref<TagType> tagType); + std::vector<TagReference> GetTagReferencesOfType(Ref<TagType> tagType); size_t GetTagReferencesOfTypeCount(Ref<TagType> tagType); size_t GetAllTagReferencesOfTypeCount(Ref<TagType> tagType); std::map<Ref<TagType>, size_t> GetAllTagReferenceTypeCounts(); std::vector<TagReference> GetDataTagReferences(); + std::vector<TagReference> GetAutoDataTagReferences(); + std::vector<TagReference> GetUserDataTagReferences(); std::vector<Ref<Tag>> GetDataTags(uint64_t addr); + std::vector<Ref<Tag>> GetAutoDataTags(uint64_t addr); + std::vector<Ref<Tag>> GetUserDataTags(uint64_t addr); std::vector<Ref<Tag>> GetDataTagsOfType(uint64_t addr, Ref<TagType> tagType); - std::vector<Ref<Tag>> GetDataTagsInRange(uint64_t start, uint64_t end); + std::vector<Ref<Tag>> GetAutoDataTagsOfType(uint64_t addr, Ref<TagType> tagType); + std::vector<Ref<Tag>> GetUserDataTagsOfType(uint64_t addr, Ref<TagType> tagType); + std::vector<TagReference> GetDataTagsInRange(uint64_t start, uint64_t end); + std::vector<TagReference> GetAutoDataTagsInRange(uint64_t start, uint64_t end); + std::vector<TagReference> GetUserDataTagsInRange(uint64_t start, uint64_t end); void AddAutoDataTag(uint64_t addr, Ref<Tag> tag); void RemoveAutoDataTag(uint64_t addr, Ref<Tag> tag); + void RemoveAutoDataTagsOfType(uint64_t addr, Ref<TagType> tagType); void AddUserDataTag(uint64_t addr, Ref<Tag> tag); void RemoveUserDataTag(uint64_t addr, Ref<Tag> tag); + void RemoveUserDataTagsOfType(uint64_t addr, Ref<TagType> tagType); void RemoveTagReference(const TagReference& ref); Ref<Tag> 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<TagReference> GetTagReferencesOfType(Ref<TagType> tagType); std::vector<TagReference> GetAddressTagReferences(); + std::vector<TagReference> GetAutoAddressTagReferences(); + std::vector<TagReference> GetUserAddressTagReferences(); std::vector<Ref<Tag>> GetAddressTags(Architecture* arch, uint64_t addr); + std::vector<Ref<Tag>> GetAutoAddressTags(Architecture* arch, uint64_t addr); + std::vector<Ref<Tag>> GetUserAddressTags(Architecture* arch, uint64_t addr); std::vector<Ref<Tag>> GetAddressTagsOfType(Architecture* arch, uint64_t addr, Ref<TagType> tagType); + std::vector<Ref<Tag>> GetAutoAddressTagsOfType(Architecture* arch, uint64_t addr, Ref<TagType> tagType); + std::vector<Ref<Tag>> GetUserAddressTagsOfType(Architecture* arch, uint64_t addr, Ref<TagType> tagType); + std::vector<TagReference> GetAddressTagsInRange(Architecture* arch, uint64_t start, uint64_t end); + std::vector<TagReference> GetAutoAddressTagsInRange(Architecture* arch, uint64_t start, uint64_t end); + std::vector<TagReference> GetUserAddressTagsInRange(Architecture* arch, uint64_t start, uint64_t end); void AddAutoAddressTag(Architecture* arch, uint64_t addr, Ref<Tag> tag); void RemoveAutoAddressTag(Architecture* arch, uint64_t addr, Ref<Tag> tag); + void RemoveAutoAddressTagsOfType(Architecture* arch, uint64_t addr, Ref<TagType> tagType); void AddUserAddressTag(Architecture* arch, uint64_t addr, Ref<Tag> tag); void RemoveUserAddressTag(Architecture* arch, uint64_t addr, Ref<Tag> tag); + void RemoveUserAddressTagsOfType(Architecture* arch, uint64_t addr, Ref<TagType> tagType); std::vector<TagReference> GetFunctionTagReferences(); + std::vector<TagReference> GetAutoFunctionTagReferences(); + std::vector<TagReference> GetUserFunctionTagReferences(); std::vector<Ref<Tag>> GetFunctionTags(); + std::vector<Ref<Tag>> GetAutoFunctionTags(); + std::vector<Ref<Tag>> GetUserFunctionTags(); std::vector<Ref<Tag>> GetFunctionTagsOfType(Ref<TagType> tagType); + std::vector<Ref<Tag>> GetAutoFunctionTagsOfType(Ref<TagType> tagType); + std::vector<Ref<Tag>> GetUserFunctionTagsOfType(Ref<TagType> tagType); void AddAutoFunctionTag(Ref<Tag> tag); void RemoveAutoFunctionTag(Ref<Tag> tag); + void RemoveAutoFunctionTagsOfType(Ref<TagType> tagType); void AddUserFunctionTag(Ref<Tag> tag); void RemoveUserFunctionTag(Ref<Tag> tag); + void RemoveUserFunctionTagsOfType(Ref<TagType> tagType); Ref<Tag> CreateAutoAddressTag(Architecture* arch, uint64_t addr, const std::string& tagTypeName, const std::string& data, bool unique = false); Ref<Tag> 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<TagReference> BinaryView::GetDataTagReferences() } +std::vector<TagReference> BinaryView::GetAutoDataTagReferences() +{ + size_t count; + BNTagReference* refs = BNGetAutoDataTagReferences(m_object, &count); + return TagReference::ConvertAndFreeTagReferenceList(refs, count); +} + + +std::vector<TagReference> BinaryView::GetUserDataTagReferences() +{ + size_t count; + BNTagReference* refs = BNGetUserDataTagReferences(m_object, &count); + return TagReference::ConvertAndFreeTagReferenceList(refs, count); +} + + std::vector<Ref<Tag>> BinaryView::GetDataTags(uint64_t addr) { size_t count; @@ -2577,6 +2593,22 @@ std::vector<Ref<Tag>> BinaryView::GetDataTags(uint64_t addr) } +std::vector<Ref<Tag>> BinaryView::GetAutoDataTags(uint64_t addr) +{ + size_t count; + BNTag** tags = BNGetAutoDataTags(m_object, addr, &count); + return Tag::ConvertAndFreeTagList(tags, count); +} + + +std::vector<Ref<Tag>> BinaryView::GetUserDataTags(uint64_t addr) +{ + size_t count; + BNTag** tags = BNGetUserDataTags(m_object, addr, &count); + return Tag::ConvertAndFreeTagList(tags, count); +} + + std::vector<Ref<Tag>> BinaryView::GetDataTagsOfType(uint64_t addr, Ref<TagType> tagType) { size_t count; @@ -2585,14 +2617,46 @@ std::vector<Ref<Tag>> BinaryView::GetDataTagsOfType(uint64_t addr, Ref<TagType> } -std::vector<Ref<Tag>> BinaryView::GetDataTagsInRange(uint64_t start, uint64_t end) +std::vector<Ref<Tag>> BinaryView::GetAutoDataTagsOfType(uint64_t addr, Ref<TagType> tagType) +{ + size_t count; + BNTag** tags = BNGetAutoDataTagsOfType(m_object, addr, tagType->GetObject(), &count); + return Tag::ConvertAndFreeTagList(tags, count); +} + + +std::vector<Ref<Tag>> BinaryView::GetUserDataTagsOfType(uint64_t addr, Ref<TagType> 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<TagReference> 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<TagReference> 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<TagReference> 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> tag) { BNAddAutoDataTag(m_object, addr, tag->GetObject()); @@ -2605,6 +2669,12 @@ void BinaryView::RemoveAutoDataTag(uint64_t addr, Ref<Tag> tag) } +void BinaryView::RemoveAutoDataTagsOfType(uint64_t addr, Ref<TagType> tagType) +{ + BNRemoveAutoDataTagsOfType(m_object, addr, tagType->GetObject()); +} + + void BinaryView::AddUserDataTag(uint64_t addr, Ref<Tag> tag) { BNAddUserDataTag(m_object, addr, tag->GetObject()); @@ -2617,6 +2687,12 @@ void BinaryView::RemoveUserDataTag(uint64_t addr, Ref<Tag> tag) } +void BinaryView::RemoveUserDataTagsOfType(uint64_t addr, Ref<TagType> 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<TagReference> Function::GetAddressTagReferences() } +std::vector<TagReference> Function::GetAutoAddressTagReferences() +{ + size_t count; + BNTagReference* refs = BNGetAutoAddressTagReferences(m_object, &count); + return TagReference::ConvertAndFreeTagReferenceList(refs, count); +} + + +std::vector<TagReference> Function::GetUserAddressTagReferences() +{ + size_t count; + BNTagReference* refs = BNGetUserAddressTagReferences(m_object, &count); + return TagReference::ConvertAndFreeTagReferenceList(refs, count); +} + + std::vector<Ref<Tag>> Function::GetAddressTags(Architecture* arch, uint64_t addr) { size_t count; @@ -1565,6 +1581,22 @@ std::vector<Ref<Tag>> Function::GetAddressTags(Architecture* arch, uint64_t addr } +std::vector<Ref<Tag>> 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<Ref<Tag>> 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<Ref<Tag>> Function::GetAddressTagsOfType(Architecture* arch, uint64_t addr, Ref<TagType> tagType) { size_t count; @@ -1573,6 +1605,46 @@ std::vector<Ref<Tag>> Function::GetAddressTagsOfType(Architecture* arch, uint64_ } +std::vector<Ref<Tag>> Function::GetAutoAddressTagsOfType(Architecture* arch, uint64_t addr, Ref<TagType> tagType) +{ + size_t count; + BNTag** tags = BNGetAutoAddressTagsOfType(m_object, arch->GetObject(), addr, tagType->GetObject(), &count); + return Tag::ConvertAndFreeTagList(tags, count); +} + + +std::vector<Ref<Tag>> Function::GetUserAddressTagsOfType(Architecture* arch, uint64_t addr, Ref<TagType> tagType) +{ + size_t count; + BNTag** tags = BNGetUserAddressTagsOfType(m_object, arch->GetObject(), addr, tagType->GetObject(), &count); + return Tag::ConvertAndFreeTagList(tags, count); +} + + +std::vector<TagReference> 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<TagReference> 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<TagReference> 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> tag) { BNAddAutoAddressTag(m_object, arch->GetObject(), addr, tag->GetObject()); @@ -1585,6 +1657,12 @@ void Function::RemoveAutoAddressTag(Architecture* arch, uint64_t addr, Ref<Tag> } +void Function::RemoveAutoAddressTagsOfType(Architecture* arch, uint64_t addr, Ref<TagType> tagType) +{ + BNRemoveAutoAddressTagsOfType(m_object, arch->GetObject(), addr, tagType->GetObject()); +} + + void Function::AddUserAddressTag(Architecture* arch, uint64_t addr, Ref<Tag> tag) { BNAddUserAddressTag(m_object, arch->GetObject(), addr, tag->GetObject()); @@ -1597,6 +1675,12 @@ void Function::RemoveUserAddressTag(Architecture* arch, uint64_t addr, Ref<Tag> } +void Function::RemoveUserAddressTagsOfType(Architecture* arch, uint64_t addr, Ref<TagType> tagType) +{ + BNRemoveUserAddressTagsOfType(m_object, arch->GetObject(), addr, tagType->GetObject()); +} + + std::vector<TagReference> Function::GetFunctionTagReferences() { size_t count; @@ -1605,6 +1689,22 @@ std::vector<TagReference> Function::GetFunctionTagReferences() } +std::vector<TagReference> Function::GetAutoFunctionTagReferences() +{ + size_t count; + BNTagReference* refs = BNGetAutoFunctionTagReferences(m_object, &count); + return TagReference::ConvertAndFreeTagReferenceList(refs, count); +} + + +std::vector<TagReference> Function::GetUserFunctionTagReferences() +{ + size_t count; + BNTagReference* refs = BNGetUserFunctionTagReferences(m_object, &count); + return TagReference::ConvertAndFreeTagReferenceList(refs, count); +} + + std::vector<Ref<Tag>> Function::GetFunctionTags() { size_t count; @@ -1613,6 +1713,22 @@ std::vector<Ref<Tag>> Function::GetFunctionTags() } +std::vector<Ref<Tag>> Function::GetAutoFunctionTags() +{ + size_t count; + BNTag** tags = BNGetAutoFunctionTags(m_object, &count); + return Tag::ConvertAndFreeTagList(tags, count); +} + + +std::vector<Ref<Tag>> Function::GetUserFunctionTags() +{ + size_t count; + BNTag** tags = BNGetUserFunctionTags(m_object, &count); + return Tag::ConvertAndFreeTagList(tags, count); +} + + std::vector<Ref<Tag>> Function::GetFunctionTagsOfType(Ref<TagType> tagType) { size_t count; @@ -1621,6 +1737,22 @@ std::vector<Ref<Tag>> Function::GetFunctionTagsOfType(Ref<TagType> tagType) } +std::vector<Ref<Tag>> Function::GetAutoFunctionTagsOfType(Ref<TagType> tagType) +{ + size_t count; + BNTag** tags = BNGetAutoFunctionTagsOfType(m_object, tagType->GetObject(), &count); + return Tag::ConvertAndFreeTagList(tags, count); +} + + +std::vector<Ref<Tag>> Function::GetUserFunctionTagsOfType(Ref<TagType> tagType) +{ + size_t count; + BNTag** tags = BNGetUserFunctionTagsOfType(m_object, tagType->GetObject(), &count); + return Tag::ConvertAndFreeTagList(tags, count); +} + + void Function::AddAutoFunctionTag(Ref<Tag> tag) { BNAddAutoFunctionTag(m_object, tag->GetObject()); @@ -1633,6 +1765,12 @@ void Function::RemoveAutoFunctionTag(Ref<Tag> tag) } +void Function::RemoveAutoFunctionTagsOfType(Ref<TagType> tagType) +{ + BNRemoveAutoFunctionTagsOfType(m_object, tagType->GetObject()); +} + + void Function::AddUserFunctionTag(Ref<Tag> tag) { BNAddUserFunctionTag(m_object, tag->GetObject()); @@ -1645,6 +1783,12 @@ void Function::RemoveUserFunctionTag(Ref<Tag> tag) } +void Function::RemoveUserFunctionTagsOfType(Ref<TagType> tagType) +{ + BNRemoveUserFunctionTagsOfType(m_object, tagType->GetObject()); +} + + Ref<Tag> Function::CreateAutoAddressTag(Architecture* arch, uint64_t addr, const std::string& tagTypeName, const std::string& data, bool unique) { Ref<TagType> 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 <binaryninja.binaryview.BinaryView.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 <binaryninja.binaryview.BinaryView.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 <binaryninja.function.Function.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 <binaryninja.function.Function.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 <binaryninja.function.Function.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 <binaryninja.function.Function.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; +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; - } + 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 |
