Skip to content

Commit dff081e

Browse files
committed
Remove ActivityContext accessors for SectionMap
1 parent c7ab5d5 commit dff081e

File tree

5 files changed

+32
-210
lines changed

5 files changed

+32
-210
lines changed

binaryninjaapi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11394,6 +11394,8 @@ namespace BinaryNinja {
1139411394
*/
1139511395
Ref<BinaryView> GetBinaryView();
1139611396

11397+
Ref<SectionMap> GetSectionMap();
11398+
1139711399
/*! Get the Function for the current AnalysisContext
1139811400

1139911401
\return The function for the current context

binaryninjacore.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5958,19 +5958,14 @@ extern "C"
59585958
BINARYNINJACOREAPI char* BNAnalysisContextGetSettingString(BNAnalysisContext* analysisContext, const char* key);
59595959
BINARYNINJACOREAPI char** BNAnalysisContextGetSettingStringList(BNAnalysisContext* analysisContext, const char* key, size_t* count);
59605960

5961+
BINARYNINJACOREAPI BNSectionMap* BNAnalysisContextGetSectionMap(BNAnalysisContext* analysisContext);
5962+
59615963
// Memory map access
59625964
BINARYNINJACOREAPI bool BNAnalysisContextIsValidOffset(BNAnalysisContext* analysisContext, uint64_t offset);
59635965
BINARYNINJACOREAPI bool BNAnalysisContextIsOffsetReadable(BNAnalysisContext* analysisContext, uint64_t offset);
59645966
BINARYNINJACOREAPI bool BNAnalysisContextIsOffsetWritable(BNAnalysisContext* analysisContext, uint64_t offset);
59655967
BINARYNINJACOREAPI bool BNAnalysisContextIsOffsetExecutable(BNAnalysisContext* analysisContext, uint64_t offset);
59665968
BINARYNINJACOREAPI bool BNAnalysisContextIsOffsetBackedByFile(BNAnalysisContext* analysisContext, uint64_t offset);
5967-
BINARYNINJACOREAPI bool BNAnalysisContextIsOffsetCodeSemantics(BNAnalysisContext* analysisContext, uint64_t offset);
5968-
BINARYNINJACOREAPI bool BNAnalysisContextIsOffsetExternSemantics(BNAnalysisContext* analysisContext, uint64_t offset);
5969-
BINARYNINJACOREAPI bool BNAnalysisContextIsOffsetWritableSemantics(BNAnalysisContext* analysisContext, uint64_t offset);
5970-
BINARYNINJACOREAPI bool BNAnalysisContextIsOffsetReadOnlySemantics(BNAnalysisContext* analysisContext, uint64_t offset);
5971-
BINARYNINJACOREAPI BNSection** BNAnalysisContextGetSections(BNAnalysisContext* analysisContext, size_t* count);
5972-
BINARYNINJACOREAPI BNSection* BNAnalysisContextGetSectionByName(BNAnalysisContext* analysisContext, const char* name);
5973-
BINARYNINJACOREAPI BNSection** BNAnalysisContextGetSectionsAt(BNAnalysisContext* analysisContext, uint64_t addr, size_t* count);
59745969
BINARYNINJACOREAPI uint64_t BNAnalysisContextGetStart(BNAnalysisContext* analysisContext);
59755970
BINARYNINJACOREAPI uint64_t BNAnalysisContextGetEnd(BNAnalysisContext* analysisContext);
59765971
BINARYNINJACOREAPI uint64_t BNAnalysisContextGetLength(BNAnalysisContext* analysisContext);

python/workflow.py

Lines changed: 10 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ def view(self) -> Optional['binaryview.BinaryView']:
6262
return None
6363
return binaryview.BinaryView(handle=result)
6464

65+
@property
66+
def section_map(self) -> Optional['binaryview.SectionMap']:
67+
"""
68+
SectionMap for the current AnalysisContext (read-only)
69+
"""
70+
result = core.BNAnalysisContextGetSectionMap(self.handle)
71+
if not result:
72+
return None
73+
return binaryview.SectionMap(handle=result)
74+
6575
@property
6676
def function(self) -> Optional['_function.Function']:
6777
"""
@@ -293,83 +303,6 @@ def is_offset_backed_by_file(self, offset: int) -> bool:
293303
"""
294304
return core.BNAnalysisContextIsOffsetBackedByFile(self.handle, offset)
295305

296-
def is_offset_code_semantics(self, offset: int) -> bool:
297-
"""
298-
Check if an offset has code semantics in the cached section map.
299-
300-
:param offset: Offset to check
301-
:return: True if offset has code semantics
302-
"""
303-
return core.BNAnalysisContextIsOffsetCodeSemantics(self.handle, offset)
304-
305-
def is_offset_extern_semantics(self, offset: int) -> bool:
306-
"""
307-
Check if an offset has external semantics in the cached section map.
308-
309-
:param offset: Offset to check
310-
:return: True if offset has external semantics
311-
"""
312-
return core.BNAnalysisContextIsOffsetExternSemantics(self.handle, offset)
313-
314-
def is_offset_writable_semantics(self, offset: int) -> bool:
315-
"""
316-
Check if an offset has writable semantics in the cached section map.
317-
318-
:param offset: Offset to check
319-
:return: True if offset has writable semantics
320-
"""
321-
return core.BNAnalysisContextIsOffsetWritableSemantics(self.handle, offset)
322-
323-
def is_offset_readonly_semantics(self, offset: int) -> bool:
324-
"""
325-
Check if an offset has read-only semantics in the cached section map.
326-
327-
:param offset: Offset to check
328-
:return: True if offset has read-only semantics
329-
"""
330-
return core.BNAnalysisContextIsOffsetReadOnlySemantics(self.handle, offset)
331-
332-
def get_sections(self) -> List['binaryninja.binaryview.Section']:
333-
"""
334-
Get all sections from the cached section map.
335-
336-
:return: List of all sections
337-
"""
338-
count = ctypes.c_ulonglong()
339-
sections = core.BNAnalysisContextGetSections(self.handle, count)
340-
result = []
341-
for i in range(count.value):
342-
result.append(binaryninja.binaryview.Section(core.BNNewSectionReference(sections[i])))
343-
core.BNFreeSectionList(sections, count.value)
344-
return result
345-
346-
def get_section_by_name(self, name: str) -> Optional['binaryninja.binaryview.Section']:
347-
"""
348-
Get a section by name from the cached section map.
349-
350-
:param name: Section name
351-
:return: Section with the given name, or None if not found
352-
"""
353-
section = core.BNAnalysisContextGetSectionByName(self.handle, name)
354-
if not section:
355-
return None
356-
return binaryninja.binaryview.Section(section)
357-
358-
def get_sections_at(self, addr: int) -> List['binaryninja.binaryview.Section']:
359-
"""
360-
Get all sections containing the given address from the cached section map.
361-
362-
:param addr: Address to query
363-
:return: List of sections containing the address
364-
"""
365-
count = ctypes.c_ulonglong()
366-
sections = core.BNAnalysisContextGetSectionsAt(self.handle, addr, count)
367-
result = []
368-
for i in range(count.value):
369-
result.append(binaryninja.binaryview.Section(core.BNNewSectionReference(sections[i])))
370-
core.BNFreeSectionList(sections, count.value)
371-
return result
372-
373306
def get_start(self) -> int:
374307
"""
375308
Get the start address from the cached memory map.

rust/src/workflow.rs

Lines changed: 9 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::high_level_il::HighLevelILFunction;
1212
use crate::low_level_il::{LowLevelILMutableFunction, LowLevelILRegularFunction};
1313
use crate::medium_level_il::MediumLevelILFunction;
1414
use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable};
15-
use crate::section::Section;
15+
use crate::section::SectionMap;
1616
use crate::segment::{Segment, SegmentFlags};
1717
use crate::string::{BnString, IntoCStr};
1818
use 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`].

workflow.cpp

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ Ref<BinaryView> AnalysisContext::GetBinaryView()
2929
}
3030

3131

32+
Ref<SectionMap> AnalysisContext::GetSectionMap()
33+
{
34+
BNSectionMap* sectionMap = BNAnalysisContextGetSectionMap(m_object);
35+
if (!sectionMap)
36+
return nullptr;
37+
return new SectionMap(sectionMap);
38+
}
39+
40+
3241
Ref<Function> AnalysisContext::GetFunction()
3342
{
3443
BNFunction* func = BNAnalysisContextGetFunction(m_object);
@@ -235,65 +244,6 @@ bool AnalysisContext::IsOffsetBackedByFile(uint64_t offset)
235244
}
236245

237246

238-
bool AnalysisContext::IsOffsetCodeSemantics(uint64_t offset)
239-
{
240-
return BNAnalysisContextIsOffsetCodeSemantics(m_object, offset);
241-
}
242-
243-
244-
bool AnalysisContext::IsOffsetExternSemantics(uint64_t offset)
245-
{
246-
return BNAnalysisContextIsOffsetExternSemantics(m_object, offset);
247-
}
248-
249-
250-
bool AnalysisContext::IsOffsetWritableSemantics(uint64_t offset)
251-
{
252-
return BNAnalysisContextIsOffsetWritableSemantics(m_object, offset);
253-
}
254-
255-
256-
bool AnalysisContext::IsOffsetReadOnlySemantics(uint64_t offset)
257-
{
258-
return BNAnalysisContextIsOffsetReadOnlySemantics(m_object, offset);
259-
}
260-
261-
262-
vector<Ref<Section>> AnalysisContext::GetSections()
263-
{
264-
size_t count;
265-
BNSection** sections = BNAnalysisContextGetSections(m_object, &count);
266-
vector<Ref<Section>> result;
267-
result.reserve(count);
268-
for (size_t i = 0; i < count; i++)
269-
result.push_back(new Section(BNNewSectionReference(sections[i])));
270-
BNFreeSectionList(sections, count);
271-
return result;
272-
}
273-
274-
275-
Ref<Section> AnalysisContext::GetSectionByName(const string& name)
276-
{
277-
BNSection* section = BNAnalysisContextGetSectionByName(m_object, name.c_str());
278-
if (!section)
279-
return nullptr;
280-
return new Section(section);
281-
}
282-
283-
284-
vector<Ref<Section>> AnalysisContext::GetSectionsAt(uint64_t addr)
285-
{
286-
size_t count;
287-
BNSection** sections = BNAnalysisContextGetSectionsAt(m_object, addr, &count);
288-
vector<Ref<Section>> result;
289-
result.reserve(count);
290-
for (size_t i = 0; i < count; i++)
291-
result.push_back(new Section(BNNewSectionReference(sections[i])));
292-
BNFreeSectionList(sections, count);
293-
return result;
294-
}
295-
296-
297247
uint64_t AnalysisContext::GetStart()
298248
{
299249
return BNAnalysisContextGetStart(m_object);

0 commit comments

Comments
 (0)