Пример #1
0
    def _get_lines_for_data(self, ctxt, view, addr, type, prefix, prefixCount,
                            width, count, typeCtx, ctxCount):
        try:
            file_metadata = filemetadata.FileMetadata(
                handle=core.BNGetFileForView(view))
            view = binaryview.BinaryView(file_metadata=file_metadata,
                                         handle=core.BNNewViewReference(view))
            type = types.Type(handle=core.BNNewTypeReference(type))

            prefixTokens = function.InstructionTextToken.get_instruction_lines(
                prefix, prefixCount)
            pycontext = []
            for i in range(ctxCount):
                pycontext.append(
                    TypeContext(
                        types.Type(core.BNNewTypeReference(typeCtx[i].type)),
                        typeCtx[i].offset))

            result = self.perform_get_lines_for_data(ctxt, view, addr, type,
                                                     prefixTokens, width,
                                                     pycontext)

            count[0] = len(result)
            line_buf = (core.BNDisassemblyTextLine * len(result))()
            for i in range(len(result)):
                line = result[i]
                color = line.highlight
                if not isinstance(
                        color,
                        enums.HighlightStandardColor) and not isinstance(
                            color, highlight.HighlightColor):
                    raise ValueError(
                        "Specified color is not one of HighlightStandardColor, highlight.HighlightColor"
                    )
                if isinstance(color, enums.HighlightStandardColor):
                    color = highlight.HighlightColor(color)
                line_buf[i].highlight = color._get_core_struct()
                if line.address is None:
                    if len(line.tokens) > 0:
                        line_buf[i].addr = line.tokens[0].address
                    else:
                        line_buf[i].addr = 0
                else:
                    line_buf[i].addr = line.address
                if line.il_instruction is not None:
                    line_buf[i].instrIndex = line.il_instruction.instr_index
                else:
                    line_buf[i].instrIndex = 0xffffffffffffffff

                line_buf[i].count = len(line.tokens)
                line_buf[
                    i].tokens = function.InstructionTextToken.get_instruction_lines(
                        line.tokens)

            return ctypes.cast(line_buf, ctypes.c_void_p).value
        except:
            log.log_error(traceback.format_exc())
            return None
Пример #2
0
	def _show_graph_report(self, ctxt, view, title, graph):
		try:
			if view:
				view = binaryview.BinaryView(handle = core.BNNewViewReference(view))
			else:
				view = None
			self.show_graph_report(view, title, flowgraph.CoreFlowGraph(core.BNNewFlowGraphReference(graph)))
		except:
			log.log_error(traceback.format_exc())
Пример #3
0
	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())
Пример #4
0
	def _show_html_report(self, ctxt, view, title, contents, plaintext):
		try:
			if view:
				view = binaryview.BinaryView(handle = core.BNNewViewReference(view))
			else:
				view = None
			self.show_html_report(view, title, contents, plaintext)
		except:
			log.log_error(traceback.format_exc())
	def _set_current_binary_view(self, ctxt, view):
		try:
			if view:
				view = binaryninja.binaryview.BinaryView(handle = core.BNNewViewReference(view))
			else:
				view = None
			self.perform_set_current_binary_view(view)
		except:
			log.log_error(traceback.format_exc())
Пример #6
0
 def _default_action(cls, view, action):
     try:
         file_metadata = binaryninja.filemetadata.FileMetadata(
             handle=core.BNGetFileForView(view))
         view_obj = binaryninja.binaryview.BinaryView(
             file_metadata=file_metadata,
             handle=core.BNNewViewReference(view))
         action(view_obj)
     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
Пример #8
0
	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
Пример #9
0
	def _is_valid_for_data(self, ctxt, view, addr, type, context, ctxCount):
		try:
			file_metadata = FileMetadata(handle=core.BNGetFileForView(view))
			view = BinaryView(file_metadata=file_metadata, handle=core.BNNewViewReference(view))
			type = Type(handle=core.BNNewTypeReference(type))
			pycontext = []
			for i in range(0, ctxCount):
				pycontext.append(Type(core.BNNewTypeReference(context[i])))
			return self.perform_is_valid_for_data(ctxt, view, addr, type, pycontext)
		except:
			log_error(traceback.format_exc())
			return False
Пример #10
0
 def _range_is_valid(cls, view, addr, length, 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))
         return is_valid(view_obj, addr, length)
     except:
         binaryninja.log.log_error(traceback.format_exc())
         return False
Пример #11
0
	def _get_address_input(self, ctxt, result, prompt, title, view, current_address):
		try:
			if view:
				view = binaryview.BinaryView(handle = core.BNNewViewReference(view))
			else:
				view = None
			value = self.get_address_input(prompt, title, view, current_address)
			if value is None:
				return False
			result[0] = value
			return True
		except:
			log.log_error(traceback.format_exc())
Пример #12
0
 def _get_form_input(self, ctxt, fields, count, title):
     try:
         field_objs = []
         for i in range(0, count):
             if fields[i].type == FormInputFieldType.LabelFormField:
                 field_objs.append(LabelField(fields[i].prompt))
             elif fields[i].type == FormInputFieldType.SeparatorFormField:
                 field_objs.append(SeparatorField())
             elif fields[i].type == FormInputFieldType.TextLineFormField:
                 field_objs.append(TextLineField(fields[i].prompt))
             elif fields[
                     i].type == FormInputFieldType.MultilineTextFormField:
                 field_objs.append(MultilineTextField(fields[i].prompt))
             elif fields[i].type == FormInputFieldType.IntegerFormField:
                 field_objs.append(IntegerField(fields[i].prompt))
             elif fields[i].type == FormInputFieldType.AddressFormField:
                 view = None
                 if fields[i].view:
                     view = binaryview.BinaryView(
                         handle=core.BNNewViewReference(fields[i].view))
                 field_objs.append(
                     AddressField(fields[i].prompt, view,
                                  fields[i].currentAddress))
             elif fields[i].type == FormInputFieldType.ChoiceFormField:
                 choices = []
                 for j in range(0, fields[i].count):
                     choices.append(fields[i].choices[j])
                 field_objs.append(ChoiceField(fields[i].prompt, choices))
             elif fields[
                     i].type == FormInputFieldType.OpenFileNameFormField:
                 field_objs.append(
                     OpenFileNameField(fields[i].prompt, fields[i].ext))
             elif fields[
                     i].type == FormInputFieldType.SaveFileNameFormField:
                 field_objs.append(
                     SaveFileNameField(fields[i].prompt, fields[i].ext,
                                       fields[i].defaultName))
             elif fields[
                     i].type == FormInputFieldType.DirectoryNameFormField:
                 field_objs.append(
                     DirectoryNameField(fields[i].prompt,
                                        fields[i].defaultName))
             else:
                 field_objs.append(LabelField(fields[i].prompt))
         if not self.get_form_input(field_objs, title):
             return False
         for i in range(0, count):
             field_objs[i]._fill_core_result(fields[i])
         return True
     except:
         log.log_error(traceback.format_exc())
Пример #13
0
 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
Пример #14
0
    def _get_type_lines(self, ctxt, type, data, name, line_width, collapsed,
                        escaping, result, result_count):
        try:
            result_py = self.get_type_lines(
                types.Type(handle=core.BNNewTypeReference(type)),
                binaryview.BinaryView(handle=core.BNNewViewReference(data)),
                types.QualifiedName._from_core_struct(name.contents),
                line_width, collapsed, escaping)

            TypePrinter._cached_lines = (core.BNTypeDefinitionLine *
                                         len(result_py))()
            for (i, line) in enumerate(result_py):
                TypePrinter._cached_lines[i] = line._to_core_struct()
            result[0] = TypePrinter._cached_lines
            result_count[0] = len(result_py)

            return True
        except:
            log_error(traceback.format_exc())
            return False