diff options
| author | Mason Reed <mason@vector35.com> | 2026-02-22 17:08:21 -0800 |
|---|---|---|
| committer | Mason Reed <35282038+emesare@users.noreply.github.com> | 2026-02-23 00:09:44 -0800 |
| commit | b18bdad6c94a8e234108d531f0c480c7104abebe (patch) | |
| tree | b0edb86cfae52c37635ef0b5cac491220bc3ef24 /rust/src/workflow.rs | |
| parent | dbd54d67a6d523f64615f653d82d8224cd09870a (diff) | |
[Rust] Misc documentation and cleanup
Diffstat (limited to 'rust/src/workflow.rs')
| -rw-r--r-- | rust/src/workflow.rs | 227 |
1 files changed, 1 insertions, 226 deletions
diff --git a/rust/src/workflow.rs b/rust/src/workflow.rs index d06890f1..e53e0001 100644 --- a/rust/src/workflow.rs +++ b/rust/src/workflow.rs @@ -5,15 +5,13 @@ use binaryninjacore_sys::*; use crate::binary_view::{memory_map::MemoryMap, BinaryViewBase, BinaryViewExt}; use crate::basic_block::BasicBlock; -use crate::binary_view::{AddressRange, BinaryView}; +use crate::binary_view::BinaryView; use crate::flowgraph::FlowGraph; use crate::function::{Function, NativeBlock}; use crate::high_level_il::HighLevelILFunction; use crate::low_level_il::{LowLevelILMutableFunction, LowLevelILRegularFunction}; use crate::medium_level_il::MediumLevelILFunction; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::section::Section; -use crate::segment::{Segment, SegmentFlags}; use crate::string::{BnString, IntoCStr}; use std::ffi::c_char; use std::ptr; @@ -131,229 +129,6 @@ impl AnalysisContext { blocks.iter().map(|block| block.handle).collect(); unsafe { BNSetBasicBlockList(self.handle.as_ptr(), blocks_raw.as_mut_ptr(), blocks.len()) } } - - // Settings cache access - lock-free access to cached settings - - /// Get a boolean setting from the cached settings - pub fn get_setting_bool(&self, key: &str) -> bool { - let key = key.to_cstr(); - unsafe { BNAnalysisContextGetSettingBool(self.handle.as_ptr(), key.as_ptr()) } - } - - /// Get a double setting from the cached settings - pub fn get_setting_double(&self, key: &str) -> f64 { - let key = key.to_cstr(); - unsafe { BNAnalysisContextGetSettingDouble(self.handle.as_ptr(), key.as_ptr()) } - } - - /// Get a signed 64-bit integer setting from the cached settings - pub fn get_setting_int64(&self, key: &str) -> i64 { - let key = key.to_cstr(); - unsafe { BNAnalysisContextGetSettingInt64(self.handle.as_ptr(), key.as_ptr()) } - } - - /// Get an unsigned 64-bit integer setting from the cached settings - pub fn get_setting_uint64(&self, key: &str) -> u64 { - let key = key.to_cstr(); - unsafe { BNAnalysisContextGetSettingUInt64(self.handle.as_ptr(), key.as_ptr()) } - } - - /// Get a string setting from the cached settings - pub fn get_setting_string(&self, key: &str) -> BnString { - let key = key.to_cstr(); - unsafe { - let result = BNAnalysisContextGetSettingString(self.handle.as_ptr(), key.as_ptr()); - BnString::from_raw(result) - } - } - - /// Get a string list setting from the cached settings - pub fn get_setting_string_list(&self, key: &str) -> Array<BnString> { - let key = key.to_cstr(); - unsafe { - let mut count = 0; - let result = BNAnalysisContextGetSettingStringList( - self.handle.as_ptr(), - key.as_ptr(), - &mut count, - ); - Array::new(result, count, ()) - } - } - - /// Check if an offset is mapped in the cached [`MemoryMap`]. - /// - /// NOTE: This is a lock-free alternative to [`BinaryView::offset_valid`]. - pub fn is_offset_valid(&self, offset: u64) -> bool { - unsafe { BNAnalysisContextIsValidOffset(self.handle.as_ptr(), offset) } - } - - /// Check if an offset is readable in the cached [`MemoryMap`]. - /// - /// NOTE: This is a lock-free alternative to [`BinaryView::offset_readable`]. - pub fn is_offset_readable(&self, offset: u64) -> bool { - unsafe { BNAnalysisContextIsOffsetReadable(self.handle.as_ptr(), offset) } - } - - /// Check if an offset is writable in the cached [`MemoryMap`]. - /// - /// NOTE: This is a lock-free alternative to [`BinaryView::offset_writable`]. - pub fn is_offset_writable(&self, offset: u64) -> bool { - unsafe { BNAnalysisContextIsOffsetWritable(self.handle.as_ptr(), offset) } - } - - /// Check if an offset is executable in the cached [`MemoryMap`]. - /// - /// NOTE: This is a lock-free alternative to [`BinaryView::offset_executable`]. - pub fn is_offset_executable(&self, offset: u64) -> bool { - unsafe { BNAnalysisContextIsOffsetExecutable(self.handle.as_ptr(), offset) } - } - - /// Check if an offset is backed by file in the cached [`MemoryMap`]. - /// - /// NOTE: This is a lock-free alternative to [`BinaryView::offset_backed_by_file`]. - pub fn is_offset_backed_by_file(&self, offset: u64) -> bool { - unsafe { BNAnalysisContextIsOffsetBackedByFile(self.handle.as_ptr(), offset) } - } - - /// Check if an offset has code semantics in the cached section map. - /// - /// NOTE: This is a lock-free alternative to [`BinaryViewExt::offset_has_code_semantics`]. - pub fn is_offset_code_semantics(&self, offset: u64) -> bool { - unsafe { BNAnalysisContextIsOffsetCodeSemantics(self.handle.as_ptr(), offset) } - } - - /// Check if an offset has external semantics in the cached section map. - /// - /// NOTE: This is a lock-free alternative to [`BinaryViewExt::offset_has_extern_semantics`]. - pub fn is_offset_extern_semantics(&self, offset: u64) -> bool { - unsafe { BNAnalysisContextIsOffsetExternSemantics(self.handle.as_ptr(), offset) } - } - - /// Check if an offset has writable semantics in the cached section map. - /// - /// NOTE: This is a lock-free alternative to [`BinaryViewExt::offset_has_writable_semantics`]. - pub fn is_offset_writable_semantics(&self, offset: u64) -> bool { - unsafe { BNAnalysisContextIsOffsetWritableSemantics(self.handle.as_ptr(), offset) } - } - - /// Check if an offset has read-only semantics in the cached section map. - /// - /// NOTE: This is a lock-free alternative to [`BinaryViewExt::offset_has_read_only_semantics`]. - pub fn is_offset_readonly_semantics(&self, offset: u64) -> bool { - unsafe { BNAnalysisContextIsOffsetReadOnlySemantics(self.handle.as_ptr(), offset) } - } - - /// Get all sections from the cached section map. - /// - /// NOTE: This is a lock-free alternative to [`BinaryViewExt::sections`]. - pub fn sections(&self) -> Array<Section> { - unsafe { - let mut count = 0; - let sections = BNAnalysisContextGetSections(self.handle.as_ptr(), &mut count); - Array::new(sections, count, ()) - } - } - - /// Get a section by name from the cached section map. - /// - /// NOTE: This is a lock-free alternative to [`BinaryViewExt::section_by_name`]. - pub fn section_by_name(&self, name: impl IntoCStr) -> Option<Ref<Section>> { - unsafe { - let raw_name = name.to_cstr(); - let name_ptr = raw_name.as_ptr(); - let raw_section_ptr = BNAnalysisContextGetSectionByName(self.handle.as_ptr(), name_ptr); - match raw_section_ptr.is_null() { - false => Some(Section::ref_from_raw(raw_section_ptr)), - true => None, - } - } - } - - /// Get all sections containing the given address from the cached section map. - /// - /// NOTE: This is a lock-free alternative to [`BinaryViewExt::sections_at`]. - pub fn sections_at(&self, addr: u64) -> Array<Section> { - unsafe { - let mut count = 0; - let sections = BNAnalysisContextGetSectionsAt(self.handle.as_ptr(), addr, &mut count); - Array::new(sections, count, ()) - } - } - - /// Get the start address (the lowest address) from the cached [`MemoryMap`]. - /// - /// NOTE: This is a lock-free alternative to [`BinaryView::start`]. - pub fn start(&self) -> u64 { - unsafe { BNAnalysisContextGetStart(self.handle.as_ptr()) } - } - - /// Get the end address (the highest address) from the cached [`MemoryMap`]. - /// - /// NOTE: This is a lock-free alternative to [`BinaryViewExt::end`]. - pub fn end(&self) -> u64 { - unsafe { BNAnalysisContextGetEnd(self.handle.as_ptr()) } - } - - /// Get the length of the cached [`MemoryMap`]. - /// - /// NOTE: This is a lock-free alternative to [`BinaryViewBase::len`]. - pub fn length(&self) -> u64 { - unsafe { BNAnalysisContextGetLength(self.handle.as_ptr()) } - } - - /// Get the next valid offset after the given offset from the cached [`MemoryMap`]. - /// - /// NOTE: This is a lock-free alternative to [`BinaryView::next_valid_offset_after`]. - pub fn next_valid_offset(&self, offset: u64) -> u64 { - unsafe { BNAnalysisContextGetNextValidOffset(self.handle.as_ptr(), offset) } - } - - /// Get the next mapped address after the given address from the cached [`MemoryMap`]. - pub fn next_mapped_address(&self, addr: u64, flags: &SegmentFlags) -> u64 { - unsafe { - BNAnalysisContextGetNextMappedAddress(self.handle.as_ptr(), addr, flags.into_raw()) - } - } - - /// Get the next backed address after the given address from the cached [`MemoryMap`]. - pub fn next_backed_address(&self, addr: u64, flags: &SegmentFlags) -> u64 { - unsafe { - BNAnalysisContextGetNextBackedAddress(self.handle.as_ptr(), addr, flags.into_raw()) - } - } - - /// Get the segment containing the given address from the cached [`MemoryMap`]. - /// - /// NOTE: This is a lock-free alternative to [`BinaryViewExt::segment_at`]. - pub fn segment_at(&self, addr: u64) -> Option<Ref<Segment>> { - unsafe { - let result = BNAnalysisContextGetSegmentAt(self.handle.as_ptr(), addr); - if result.is_null() { - None - } else { - Some(Segment::ref_from_raw(result)) - } - } - } - - /// Get all mapped address ranges from the cached [`MemoryMap`]. - pub fn mapped_address_ranges(&self) -> Array<AddressRange> { - unsafe { - let mut count = 0; - let ranges = BNAnalysisContextGetMappedAddressRanges(self.handle.as_ptr(), &mut count); - Array::new(ranges, count, ()) - } - } - - /// Get all backed address ranges from the cached [`MemoryMap`]. - pub fn backed_address_ranges(&self) -> Array<AddressRange> { - unsafe { - let mut count = 0; - let ranges = BNAnalysisContextGetBackedAddressRanges(self.handle.as_ptr(), &mut count); - Array::new(ranges, count, ()) - } - } } impl ToOwned for AnalysisContext { |
