From b4d77d5b44dd322042f90b5a4a4da9075d05b644 Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Mon, 24 Nov 2025 15:35:58 -0500 Subject: Add AnalysisContext FFI for SectionMap queries. --- python/workflow.py | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'python/workflow.py') diff --git a/python/workflow.py b/python/workflow.py index ed6bc876..61827b55 100644 --- a/python/workflow.py +++ b/python/workflow.py @@ -293,6 +293,83 @@ class AnalysisContext: """ return core.BNAnalysisContextIsOffsetBackedByFile(self.handle, offset) + def is_offset_code_semantics(self, offset: int) -> bool: + """ + Check if an offset has code semantics in the cached section map. + + :param offset: Offset to check + :return: True if offset has code semantics + """ + return core.BNAnalysisContextIsOffsetCodeSemantics(self.handle, offset) + + def is_offset_extern_semantics(self, offset: int) -> bool: + """ + Check if an offset has external semantics in the cached section map. + + :param offset: Offset to check + :return: True if offset has external semantics + """ + return core.BNAnalysisContextIsOffsetExternSemantics(self.handle, offset) + + def is_offset_writable_semantics(self, offset: int) -> bool: + """ + Check if an offset has writable semantics in the cached section map. + + :param offset: Offset to check + :return: True if offset has writable semantics + """ + return core.BNAnalysisContextIsOffsetWritableSemantics(self.handle, offset) + + def is_offset_readonly_semantics(self, offset: int) -> bool: + """ + Check if an offset has read-only semantics in the cached section map. + + :param offset: Offset to check + :return: True if offset has read-only semantics + """ + return core.BNAnalysisContextIsOffsetReadOnlySemantics(self.handle, offset) + + def get_sections(self) -> List['binaryninja.binaryview.Section']: + """ + Get all sections from the cached section map. + + :return: List of all sections + """ + count = ctypes.c_ulonglong() + sections = core.BNAnalysisContextGetSections(self.handle, count) + result = [] + for i in range(count.value): + result.append(binaryninja.binaryview.Section(core.BNNewSectionReference(sections[i]))) + core.BNFreeSectionList(sections, count.value) + return result + + def get_section_by_name(self, name: str) -> Optional['binaryninja.binaryview.Section']: + """ + Get a section by name from the cached section map. + + :param name: Section name + :return: Section with the given name, or None if not found + """ + section = core.BNAnalysisContextGetSectionByName(self.handle, name) + if not section: + return None + return binaryninja.binaryview.Section(section) + + def get_sections_at(self, addr: int) -> List['binaryninja.binaryview.Section']: + """ + Get all sections containing the given address from the cached section map. + + :param addr: Address to query + :return: List of sections containing the address + """ + count = ctypes.c_ulonglong() + sections = core.BNAnalysisContextGetSectionsAt(self.handle, addr, count) + result = [] + for i in range(count.value): + result.append(binaryninja.binaryview.Section(core.BNNewSectionReference(sections[i]))) + core.BNFreeSectionList(sections, count.value) + return result + def get_start(self) -> int: """ Get the start address from the cached memory map. -- cgit v1.3.1