diff options
| author | Josh Ferrell <josh@vector35.com> | 2026-01-13 12:54:06 -0500 |
|---|---|---|
| committer | Josh Ferrell <josh@vector35.com> | 2026-01-13 12:54:38 -0500 |
| commit | c68f8d48afb9b3e6cdac363c8a578a051ad6e21d (patch) | |
| tree | 33938d0c6c634426a177c5987c3e861d2237242e /rust/src | |
| parent | 56b23981c1149a2b2dece05a2eaefb0787f34e15 (diff) | |
[Rust API] Add BinaryViewExt::{tags_all_scopes, tag_types, tags_by_type}
Diffstat (limited to 'rust/src')
| -rw-r--r-- | rust/src/binary_view.rs | 30 | ||||
| -rw-r--r-- | rust/src/tags.rs | 21 |
2 files changed, 50 insertions, 1 deletions
diff --git a/rust/src/binary_view.rs b/rust/src/binary_view.rs index 30733516..8309d15d 100644 --- a/rust/src/binary_view.rs +++ b/rust/src/binary_view.rs @@ -54,7 +54,7 @@ use crate::segment::{Segment, SegmentBuilder}; use crate::settings::Settings; use crate::string::*; use crate::symbol::{Symbol, SymbolType}; -use crate::tags::{Tag, TagType}; +use crate::tags::{Tag, TagReference, TagType}; use crate::types::{ NamedTypeReference, QualifiedName, QualifiedNameAndType, QualifiedNameTypeAndId, Type, TypeArchive, TypeArchiveId, TypeContainer, TypeLibrary, @@ -1646,6 +1646,34 @@ pub trait BinaryViewExt: BinaryViewBase { } } + /// Get all tags in all scopes + fn tags_all_scopes(&self) -> Array<TagReference> { + let mut count = 0; + unsafe { + let tag_references = BNGetAllTagReferences(self.as_ref().handle, &mut count); + Array::new(tag_references, count, ()) + } + } + + /// Get all tag types present for the view + fn tag_types(&self) -> Array<TagType> { + let mut count = 0; + unsafe { + let tag_types_raw = BNGetTagTypes(self.as_ref().handle, &mut count); + Array::new(tag_types_raw, count, ()) + } + } + + // Get all tags of a specific type + fn tags_by_type(&self, tag_type: &TagType) -> Array<TagReference> { + let mut count = 0; + unsafe { + let tag_references = + BNGetAllTagReferencesOfType(self.as_ref().handle, tag_type.handle, &mut count); + Array::new(tag_references, count, ()) + } + } + /// Get a tag by its id. /// /// Note this does not tell you anything about where it is used. diff --git a/rust/src/tags.rs b/rust/src/tags.rs index 2af0be89..49dfae4a 100644 --- a/rust/src/tags.rs +++ b/rust/src/tags.rs @@ -128,7 +128,28 @@ pub struct TagType { pub(crate) handle: *mut BNTagType, } +impl CoreArrayProvider for TagType { + type Raw = *mut BNTagType; + type Context = (); + type Wrapped<'a> = Guard<'a, Self>; +} + +unsafe impl CoreArrayProviderInner for TagType { + unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) { + BNFreeTagTypeList(raw, count) + } + + unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped<'a> { + Guard::new(Self::from_raw(*raw), context) + } +} + impl TagType { + pub(crate) unsafe fn from_raw(handle: *mut BNTagType) -> Self { + debug_assert!(!handle.is_null()); + Self { handle } + } + pub(crate) unsafe fn ref_from_raw(handle: *mut BNTagType) -> Ref<Self> { debug_assert!(!handle.is_null()); Ref::new(Self { handle }) |
