11use binaryninjacore_sys:: * ;
22
3+ // Needed for documentation.
4+ #[ allow( unused) ]
5+ use crate :: binary_view:: { memory_map:: MemoryMap , BinaryViewBase , BinaryViewExt } ;
6+
37use crate :: basic_block:: BasicBlock ;
4- use crate :: binary_view:: BinaryView ;
8+ use crate :: binary_view:: { AddressRange , BinaryView } ;
59use crate :: flowgraph:: FlowGraph ;
610use crate :: function:: { Function , NativeBlock } ;
711use crate :: high_level_il:: HighLevelILFunction ;
812use crate :: low_level_il:: { LowLevelILMutableFunction , LowLevelILRegularFunction } ;
913use crate :: medium_level_il:: MediumLevelILFunction ;
1014use crate :: rc:: { Array , CoreArrayProvider , CoreArrayProviderInner , Guard , Ref , RefCountable } ;
11- use crate :: segment:: Segment ;
15+ use crate :: segment:: { Segment , SegmentFlags } ;
1216use crate :: string:: { BnString , IntoCStr } ;
1317use std:: ffi:: c_char;
1418use std:: ptr;
@@ -176,65 +180,87 @@ impl AnalysisContext {
176180 }
177181 }
178182
179- // Memory map access - lock-free access to cached MemoryMap
180-
181- /// Check if an offset is mapped in the cached memory map
182- pub fn is_valid_offset ( & self , offset : u64 ) -> bool {
183+ /// Check if an offset is mapped in the cached [` MemoryMap`].
184+ ///
185+ /// NOTE: This is a lock-free alternative to [`BinaryView::offset_valid`].
186+ pub fn is_offset_valid ( & self , offset : u64 ) -> bool {
183187 unsafe { BNAnalysisContextIsValidOffset ( self . handle . as_ptr ( ) , offset) }
184188 }
185189
186- /// Check if an offset is readable in the cached memory map
190+ /// Check if an offset is readable in the cached [`MemoryMap`].
191+ ///
192+ /// NOTE: This is a lock-free alternative to [`BinaryView::offset_readable`].
187193 pub fn is_offset_readable ( & self , offset : u64 ) -> bool {
188194 unsafe { BNAnalysisContextIsOffsetReadable ( self . handle . as_ptr ( ) , offset) }
189195 }
190196
191- /// Check if an offset is writable in the cached memory map
197+ /// Check if an offset is writable in the cached [`MemoryMap`].
198+ ///
199+ /// NOTE: This is a lock-free alternative to [`BinaryView::offset_writable`].
192200 pub fn is_offset_writable ( & self , offset : u64 ) -> bool {
193201 unsafe { BNAnalysisContextIsOffsetWritable ( self . handle . as_ptr ( ) , offset) }
194202 }
195203
196- /// Check if an offset is executable in the cached memory map
204+ /// Check if an offset is executable in the cached [`MemoryMap`].
205+ ///
206+ /// NOTE: This is a lock-free alternative to [`BinaryView::offset_executable`].
197207 pub fn is_offset_executable ( & self , offset : u64 ) -> bool {
198208 unsafe { BNAnalysisContextIsOffsetExecutable ( self . handle . as_ptr ( ) , offset) }
199209 }
200210
201- /// Check if an offset is backed by file in the cached memory map
211+ /// Check if an offset is backed by file in the cached [`MemoryMap`].
212+ ///
213+ /// NOTE: This is a lock-free alternative to [`BinaryView::offset_backed_by_file`].
202214 pub fn is_offset_backed_by_file ( & self , offset : u64 ) -> bool {
203215 unsafe { BNAnalysisContextIsOffsetBackedByFile ( self . handle . as_ptr ( ) , offset) }
204216 }
205217
206- /// Get the start address from the cached memory map
207- pub fn get_start ( & self ) -> u64 {
218+ /// Get the start address (the lowest address) from the cached [`MemoryMap`].
219+ ///
220+ /// NOTE: This is a lock-free alternative to [`BinaryView::start`].
221+ pub fn start ( & self ) -> u64 {
208222 unsafe { BNAnalysisContextGetStart ( self . handle . as_ptr ( ) ) }
209223 }
210224
211- /// Get the end address from the cached memory map
212- pub fn get_end ( & self ) -> u64 {
225+ /// Get the end address (the highest address) from the cached [`MemoryMap`].
226+ ///
227+ /// NOTE: This is a lock-free alternative to [`BinaryViewBase::end`].
228+ pub fn end ( & self ) -> u64 {
213229 unsafe { BNAnalysisContextGetEnd ( self . handle . as_ptr ( ) ) }
214230 }
215231
216- /// Get the length of the cached memory map
217- pub fn get_length ( & self ) -> u64 {
232+ /// Get the length of the cached [`MemoryMap`].
233+ ///
234+ /// NOTE: This is a lock-free alternative to [`BinaryViewBase::len`].
235+ pub fn length ( & self ) -> u64 {
218236 unsafe { BNAnalysisContextGetLength ( self . handle . as_ptr ( ) ) }
219237 }
220238
221- /// Get the next valid offset after the given offset from the cached memory map
222- pub fn get_next_valid_offset ( & self , offset : u64 ) -> u64 {
239+ /// Get the next valid offset after the given offset from the cached [`MemoryMap`].
240+ ///
241+ /// NOTE: This is a lock-free alternative to [`BinaryView::next_valid_offset_after`].
242+ pub fn next_valid_offset ( & self , offset : u64 ) -> u64 {
223243 unsafe { BNAnalysisContextGetNextValidOffset ( self . handle . as_ptr ( ) , offset) }
224244 }
225245
226- /// Get the next mapped address after the given address from the cached memory map
227- pub fn get_next_mapped_address ( & self , addr : u64 , flags : u32 ) -> u64 {
228- unsafe { BNAnalysisContextGetNextMappedAddress ( self . handle . as_ptr ( ) , addr, flags) }
246+ /// Get the next mapped address after the given address from the cached [`MemoryMap`].
247+ pub fn next_mapped_address ( & self , addr : u64 , flags : & SegmentFlags ) -> u64 {
248+ unsafe {
249+ BNAnalysisContextGetNextMappedAddress ( self . handle . as_ptr ( ) , addr, flags. into_raw ( ) )
250+ }
229251 }
230252
231- /// Get the next backed address after the given address from the cached memory map
232- pub fn get_next_backed_address ( & self , addr : u64 , flags : u32 ) -> u64 {
233- unsafe { BNAnalysisContextGetNextBackedAddress ( self . handle . as_ptr ( ) , addr, flags) }
253+ /// Get the next backed address after the given address from the cached [`MemoryMap`].
254+ pub fn next_backed_address ( & self , addr : u64 , flags : & SegmentFlags ) -> u64 {
255+ unsafe {
256+ BNAnalysisContextGetNextBackedAddress ( self . handle . as_ptr ( ) , addr, flags. into_raw ( ) )
257+ }
234258 }
235259
236- /// Get the segment containing the given address from the cached memory map
237- pub fn get_segment_at ( & self , addr : u64 ) -> Option < Ref < Segment > > {
260+ /// Get the segment containing the given address from the cached [`MemoryMap`].
261+ ///
262+ /// NOTE: This is a lock-free alternative to [`BinaryView::segment_at`].
263+ pub fn segment_at ( & self , addr : u64 ) -> Option < Ref < Segment > > {
238264 unsafe {
239265 let result = BNAnalysisContextGetSegmentAt ( self . handle . as_ptr ( ) , addr) ;
240266 if result. is_null ( ) {
@@ -245,35 +271,21 @@ impl AnalysisContext {
245271 }
246272 }
247273
248- /// Get all mapped address ranges from the cached memory map
249- pub fn get_mapped_address_ranges ( & self ) -> Vec < ( u64 , u64 ) > {
274+ /// Get all mapped address ranges from the cached [`MemoryMap`].
275+ pub fn mapped_address_ranges ( & self ) -> Array < AddressRange > {
250276 unsafe {
251277 let mut count = 0 ;
252278 let ranges = BNAnalysisContextGetMappedAddressRanges ( self . handle . as_ptr ( ) , & mut count) ;
253- let result = ( 0 ..count)
254- . map ( |i| {
255- let range = * ranges. add ( i) ;
256- ( range. start , range. end )
257- } )
258- . collect ( ) ;
259- BNFreeAddressRanges ( ranges) ;
260- result
279+ Array :: new ( ranges, count, ( ) )
261280 }
262281 }
263282
264- /// Get all backed address ranges from the cached memory map
265- pub fn get_backed_address_ranges ( & self ) -> Vec < ( u64 , u64 ) > {
283+ /// Get all backed address ranges from the cached [`MemoryMap`].
284+ pub fn backed_address_ranges ( & self ) -> Array < AddressRange > {
266285 unsafe {
267286 let mut count = 0 ;
268287 let ranges = BNAnalysisContextGetBackedAddressRanges ( self . handle . as_ptr ( ) , & mut count) ;
269- let result = ( 0 ..count)
270- . map ( |i| {
271- let range = * ranges. add ( i) ;
272- ( range. start , range. end )
273- } )
274- . collect ( ) ;
275- BNFreeAddressRanges ( ranges) ;
276- result
288+ Array :: new ( ranges, count, ( ) )
277289 }
278290 }
279291}
0 commit comments