@@ -12,6 +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 ;
1516use crate :: segment:: { Segment , SegmentFlags } ;
1617use crate :: string:: { BnString , IntoCStr } ;
1718use std:: ffi:: c_char;
@@ -215,6 +216,71 @@ impl AnalysisContext {
215216 unsafe { BNAnalysisContextIsOffsetBackedByFile ( self . handle . as_ptr ( ) , offset) }
216217 }
217218
219+ /// Check if an offset has code semantics in the cached section map.
220+ ///
221+ /// NOTE: This is a lock-free alternative to [`BinaryView::is_offset_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 [`BinaryView::is_offset_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 [`BinaryView::is_offset_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 [`BinaryView::is_offset_readonly_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 [`BinaryView::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 [`BinaryView::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 [`BinaryView::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+
218284 /// Get the start address (the lowest address) from the cached [`MemoryMap`].
219285 ///
220286 /// NOTE: This is a lock-free alternative to [`BinaryView::start`].
0 commit comments