@@ -12,7 +12,7 @@ use crate::high_level_il::HighLevelILFunction;
1212use crate :: low_level_il:: { LowLevelILMutableFunction , LowLevelILRegularFunction } ;
1313use crate :: medium_level_il:: MediumLevelILFunction ;
1414use crate :: rc:: { Array , CoreArrayProvider , CoreArrayProviderInner , Guard , Ref , RefCountable } ;
15- use crate :: section:: Section ;
15+ use crate :: section:: SectionMap ;
1616use crate :: segment:: { Segment , SegmentFlags } ;
1717use crate :: string:: { BnString , IntoCStr } ;
1818use std:: ffi:: c_char;
@@ -40,13 +40,20 @@ impl AnalysisContext {
4040 Ref :: new ( Self { handle } )
4141 }
4242
43- /// BinaryView for the current AnalysisContext
43+ /// [` BinaryView`] for the current AnalysisContext
4444 pub fn view ( & self ) -> Ref < BinaryView > {
4545 let result = unsafe { BNAnalysisContextGetBinaryView ( self . handle . as_ptr ( ) ) } ;
4646 assert ! ( !result. is_null( ) ) ;
4747 unsafe { BinaryView :: ref_from_raw ( result) }
4848 }
4949
50+ /// [`SectionMap`] for the current AnalysisContext
51+ pub fn section_map ( & self ) -> Ref < SectionMap > {
52+ let result = unsafe { BNAnalysisContextGetSectionMap ( self . handle . as_ptr ( ) ) } ;
53+ assert ! ( !result. is_null( ) ) ;
54+ unsafe { SectionMap :: ref_from_raw ( result) }
55+ }
56+
5057 /// [`Function`] for the current AnalysisContext
5158 pub fn function ( & self ) -> Ref < Function > {
5259 let result = unsafe { BNAnalysisContextGetFunction ( self . handle . as_ptr ( ) ) } ;
@@ -216,71 +223,6 @@ impl AnalysisContext {
216223 unsafe { BNAnalysisContextIsOffsetBackedByFile ( self . handle . as_ptr ( ) , offset) }
217224 }
218225
219- /// Check if an offset has code semantics in the cached section map.
220- ///
221- /// NOTE: This is a lock-free alternative to [`BinaryViewExt::offset_has_code_semantics`].
222- pub fn is_offset_code_semantics ( & self , offset : u64 ) -> bool {
223- unsafe { BNAnalysisContextIsOffsetCodeSemantics ( self . handle . as_ptr ( ) , offset) }
224- }
225-
226- /// Check if an offset has external semantics in the cached section map.
227- ///
228- /// NOTE: This is a lock-free alternative to [`BinaryViewExt::offset_has_extern_semantics`].
229- pub fn is_offset_extern_semantics ( & self , offset : u64 ) -> bool {
230- unsafe { BNAnalysisContextIsOffsetExternSemantics ( self . handle . as_ptr ( ) , offset) }
231- }
232-
233- /// Check if an offset has writable semantics in the cached section map.
234- ///
235- /// NOTE: This is a lock-free alternative to [`BinaryViewExt::offset_has_writable_semantics`].
236- pub fn is_offset_writable_semantics ( & self , offset : u64 ) -> bool {
237- unsafe { BNAnalysisContextIsOffsetWritableSemantics ( self . handle . as_ptr ( ) , offset) }
238- }
239-
240- /// Check if an offset has read-only semantics in the cached section map.
241- ///
242- /// NOTE: This is a lock-free alternative to [`BinaryViewExt::offset_has_read_only_semantics`].
243- pub fn is_offset_readonly_semantics ( & self , offset : u64 ) -> bool {
244- unsafe { BNAnalysisContextIsOffsetReadOnlySemantics ( self . handle . as_ptr ( ) , offset) }
245- }
246-
247- /// Get all sections from the cached section map.
248- ///
249- /// NOTE: This is a lock-free alternative to [`BinaryViewExt::sections`].
250- pub fn sections ( & self ) -> Array < Section > {
251- unsafe {
252- let mut count = 0 ;
253- let sections = BNAnalysisContextGetSections ( self . handle . as_ptr ( ) , & mut count) ;
254- Array :: new ( sections, count, ( ) )
255- }
256- }
257-
258- /// Get a section by name from the cached section map.
259- ///
260- /// NOTE: This is a lock-free alternative to [`BinaryViewExt::section_by_name`].
261- pub fn section_by_name ( & self , name : impl IntoCStr ) -> Option < Ref < Section > > {
262- unsafe {
263- let raw_name = name. to_cstr ( ) ;
264- let name_ptr = raw_name. as_ptr ( ) ;
265- let raw_section_ptr = BNAnalysisContextGetSectionByName ( self . handle . as_ptr ( ) , name_ptr) ;
266- match raw_section_ptr. is_null ( ) {
267- false => Some ( Section :: ref_from_raw ( raw_section_ptr) ) ,
268- true => None ,
269- }
270- }
271- }
272-
273- /// Get all sections containing the given address from the cached section map.
274- ///
275- /// NOTE: This is a lock-free alternative to [`BinaryViewExt::sections_at`].
276- pub fn sections_at ( & self , addr : u64 ) -> Array < Section > {
277- unsafe {
278- let mut count = 0 ;
279- let sections = BNAnalysisContextGetSectionsAt ( self . handle . as_ptr ( ) , addr, & mut count) ;
280- Array :: new ( sections, count, ( ) )
281- }
282- }
283-
284226 /// Get the start address (the lowest address) from the cached [`MemoryMap`].
285227 ///
286228 /// NOTE: This is a lock-free alternative to [`BinaryView::start`].
0 commit comments