def basic_block(self): """Basic block associated with this part of the flow graph""" block = core.BNGetFlowGraphBasicBlock(self.handle) if not block: return None func_handle = core.BNGetBasicBlockFunction(block) if not func_handle: core.BNFreeBasicBlock(block) return None view = binaryview.BinaryView( handle=core.BNGetFunctionData(func_handle)) func = function.Function(view, func_handle) if core.BNIsLowLevelILBasicBlock(block): block = lowlevelil.LowLevelILBasicBlock( view, block, lowlevelil.LowLevelILFunction( func.arch, core.BNGetBasicBlockLowLevelILFunction(block), func)) elif core.BNIsMediumLevelILBasicBlock(block): block = mediumlevelil.MediumLevelILBasicBlock( view, block, mediumlevelil.MediumLevelILFunction( func.arch, core.BNGetBasicBlockMediumLevelILFunction(block), func)) else: block = basicblock.BasicBlock(block, view) return block
def function(self): """Function for a flow graph""" func = core.BNGetFunctionForFlowGraph(self.handle) if func is None: return None return function.Function( binaryview.BinaryView(handle=core.BNGetFunctionData(func)), func)
def _function_action(cls, view, func, action): try: file_metadata = binaryninja.filemetadata.FileMetadata(handle = core.BNGetFileForView(view)) view_obj = binaryninja.binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view)) func_obj = function.Function(view_obj, core.BNNewFunctionReference(func)) action(view_obj, func_obj) except: binaryninja.log.log_error(traceback.format_exc())
def _medium_level_il_instruction_action(cls, view, func, instr, action): try: file_metadata = filemetadata.FileMetadata(handle = core.BNGetFileForView(view)) view_obj = binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view)) owner = function.Function(view_obj, core.BNGetMediumLevelILOwnerFunction(func)) func_obj = binaryninja.mediumlevelil.MediumLevelILFunction(owner.arch, core.BNNewMediumLevelILFunctionReference(func), owner) action(view_obj, func_obj[instr]) except: binaryninja.log.log_error(traceback.format_exc())
def _recognize_medium_level_il(self, ctxt, data, func, il): try: file_metadata = filemetadata.FileMetadata(handle = core.BNGetFileForView(data)) view = binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(data)) func = function.Function(view, handle = core.BNNewFunctionReference(func)) il = mediumlevelil.MediumLevelILFunction(func.arch, handle = core.BNNewMediumLevelILFunctionReference(il)) return self.recognize_medium_level_il(view, func, il) except: log.log_error(traceback.format_exc()) return False
def _function_is_valid(cls, view, func, is_valid): try: if is_valid is None: return True file_metadata = binaryninja.filemetadata.FileMetadata(handle = core.BNGetFileForView(view)) view_obj = binaryninja.binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view)) func_obj = function.Function(view_obj, core.BNNewFunctionReference(func)) return is_valid(view_obj, func_obj) except: binaryninja.log.log_error(traceback.format_exc()) return False
def _medium_level_il_function_is_valid(cls, view, func, is_valid): try: if is_valid is None: return True file_metadata = filemetadata.FileMetadata(handle = core.BNGetFileForView(view)) view_obj = binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view)) owner = function.Function(view_obj, core.BNGetMediumLevelILOwnerFunction(func)) func_obj = binaryninja.mediumlevelil.MediumLevelILFunction(owner.arch, core.BNNewMediumLevelILFunctionReference(func), owner) return is_valid(view_obj, func_obj) except: binaryninja.log.log_error(traceback.format_exc()) return False
def function(self): """Function for a flow graph""" func = core.BNGetFunctionForFlowGraph(self.handle) if func is None: return None return function.Function(handle=func)