Exemple #1
0
    def do_instructionflow(self, arg, opts=None):
        if (not arg):
            self.cprint.print_error(
                "Incorrect Syntax: help instructionflow.\n")
        else:
            method_definition = repr(''.join(arg))[2:-2]
            self.cprint.print_title(
                "*  Method %s Instructions Flow saved to MethodInstructionsFlow.png."
                % (method_definition))
            fnd = InstructionsFinder(method_definition, opts.full_graph)
            self.walker.assign_finder(fnd)
            resultados = self.walker.do_find()
            graph_mgr = GraphManager(True)
            for b1 in resultados:
                for lbl, target in b1.bifurcaciones:
                    for b2 in resultados:
                        if b2.etiqueta == target:
                            graph_mgr.add_block_edge(b1, b2, lbl)
                            break

            try:
                graph_mgr.draw("MethodInstructionsFlow", not opts.store_dot)
            except:
                self.cprint.print_error(
                    "Complex Graph can't be rendered with graphviz libraries, using .dot format instead!\n"
                )
                graph_mgr.draw("MethodInstructionsFlow", False)
Exemple #2
0
	def do_instructionflow(self, arg, opts=None):
		if (not arg):
			self.cprint.print_error("Incorrect Syntax: help instructionflow.\n")
		else:
			method_definition = repr(''.join(arg))[2:-2]
			self.cprint.print_title("*  Method %s Instructions Flow saved to MethodInstructionsFlow.png." % (method_definition))
			fnd = InstructionsFinder(method_definition, opts.full_graph)
			self.walker.assign_finder(fnd)
			resultados = self.walker.do_find()
			graph_mgr = GraphManager(True)
			for b1 in resultados:
				for lbl,target in b1.bifurcaciones:
					for b2 in resultados:
						if b2.etiqueta == target:
							graph_mgr.add_block_edge(b1,b2, lbl)
							break

			try:
				graph_mgr.draw("MethodInstructionsFlow", not opts.store_dot)
			except:
				self.cprint.print_error("Complex Graph can't be rendered with graphviz libraries, using .dot format instead!\n")
				graph_mgr.draw("MethodInstructionsFlow", False)
Exemple #3
0
    def do_crossreferences(self, arg, opts=None):
        def cross_level(start_points, direction, view_system_calls, lvl):
            auxCalls = []
            for methodPair in start_points:
                fcaller, fcalled = methodPair

                fnd = CallsFinder(fcaller)
                self.walker.assign_finder(fnd)
                mthXrefs = self.walker.do_find()

                for callPair in mthXrefs:
                    caller, called = callPair
                    if direction == 0:
                        condition = (called == fcaller)
                    elif direction == 1:
                        condition = (caller == fcaller)
                    else:
                        condition = True

                    if condition:
                        if (caller, called) not in auxCalls:
                            if view_system_calls:
                                auxCalls.append((caller, called))
                            else:
                                if lvl == 0:
                                    auxCalls.append((caller, called))
                                else:
                                    if called.split(
                                            '->'
                                    )[0] in self.walker.AppInventory.keys():
                                        auxCalls.append((caller, called))
            return auxCalls

        if (not arg):
            self.cprint.print_error(
                "Incorrect Syntax: help crossreferences.\n")
            return

        # arg
        method_definition = repr(''.join(arg))[2:-2]

        # str patterns
        StringMatch = None
        if opts.str_reg:
            strings_patterns = [opts.str_reg]
            fnd = StringsFinder(strings_patterns)
            self.walker.assign_finder(fnd)
            StringMatch = self.walker.do_find()

        if StringMatch:
            self.cprint.print_title(
                "*  Cross-References with a %d recursion level and String Pattern search."
                % (opts.max_levels))
        else:
            self.cprint.print_title(
                "*  Cross-References with a %d recursion level." %
                (opts.max_levels))

        level = 0
        PackageUsage = []
        results = []
        PackageUsage.append((method_definition, ''))
        while True:
            PackageUsage2 = cross_level(PackageUsage, opts.direction,
                                        opts.view_system_calls, level)
            if len(PackageUsage) == len(PackageUsage2):
                equal = True
                for a in PackageUsage:
                    equal = a in PackageUsage2
                    if not equal: break
                if equal: break
            results += PackageUsage2
            PackageUsage = PackageUsage2
            level += 1
            if level == opts.max_levels: break

        graph_mgr = GraphManager()
        coincidences = {}

        for calls in results:
            caller, called = calls
            graph_mgr.add_xref_edge(caller, called, method_definition,
                                    StringMatch)
            if StringMatch:
                if (caller in StringMatch) and (caller not in coincidences):
                    coincidences[caller] = StringMatch[caller]
                elif (called in StringMatch) and (called not in coincidences):
                    coincidences[called] = StringMatch[called]

        self.cprint.print_dict(coincidences)

        if StringMatch:
            try:
                graph_mgr.draw("CrossReferencesWithPatterns",
                               not opts.store_dot)
            except:
                self.cprint.print_error(
                    "Complex Graph can't be rendered with graphviz libraries, using .dot format instead!\n"
                )
                graph_mgr.draw("CrossReferencesWithPatterns", False)
        else:
            try:
                graph_mgr.draw("CrossReferences", not opts.store_dot)
            except:
                self.cprint.print_error(
                    "Complex Graph can't be rendered with graphviz libraries, using .dot format instead!\n"
                )
                graph_mgr.draw("CrossReferences", False)
Exemple #4
0
	def do_crossreferences(self, arg, opts=None):
		def cross_level(start_points, direction, view_system_calls, lvl):
			auxCalls = []
			for methodPair in start_points:
				fcaller, fcalled = methodPair

				fnd = CallsFinder(fcaller)
				self.walker.assign_finder(fnd)
				mthXrefs = self.walker.do_find()

				for callPair in mthXrefs:
					caller, called = callPair
					if direction == 0:
						condition = (called == fcaller)
					elif direction == 1:
						condition = (caller == fcaller)
					else:
						condition = True

					if condition:
						if (caller, called) not in auxCalls:
							if view_system_calls:
								auxCalls.append( (caller, called) )
							else:
								if lvl==0:
									auxCalls.append( (caller, called) )
								else:
									if called.split('->')[0] in self.walker.AppInventory.keys():
										auxCalls.append( (caller, called) )
			return auxCalls

		if (not arg):
			self.cprint.print_error("Incorrect Syntax: help crossreferences.\n")
			return

		# arg
		method_definition = repr(''.join(arg))[2:-2]

		# str patterns
		StringMatch = None
		if opts.str_reg:
			strings_patterns = [opts.str_reg]
			fnd = StringsFinder(strings_patterns)
			self.walker.assign_finder(fnd)
			StringMatch = self.walker.do_find()

		if StringMatch:
			self.cprint.print_title("*  Cross-References with a %d recursion level and String Pattern search." % (opts.max_levels))
		else:
			self.cprint.print_title("*  Cross-References with a %d recursion level." % (opts.max_levels))

		level = 0
		PackageUsage = []
		results = []
		PackageUsage.append( (method_definition,'') )
		while True:
			PackageUsage2 = cross_level(PackageUsage, opts.direction, opts.view_system_calls, level)
			if len(PackageUsage) == len(PackageUsage2):
				equal = True
				for a in PackageUsage:
					equal = a in PackageUsage2
					if not equal: break
				if equal: break
			results += PackageUsage2
			PackageUsage = PackageUsage2
			level +=1
			if level == opts.max_levels: break

		graph_mgr = GraphManager()
		coincidences = {}

		for calls in results:
			caller, called = calls
			graph_mgr.add_xref_edge(caller, called, method_definition, StringMatch)
			if StringMatch:
				if (caller in StringMatch) and (caller not in coincidences):
					coincidences[caller] = StringMatch[caller]
				elif (called in StringMatch) and (called not in coincidences):
					coincidences[called] = StringMatch[called]

		self.cprint.print_dict(coincidences)

		if StringMatch:
			try:
				graph_mgr.draw("CrossReferencesWithPatterns", not opts.store_dot)
			except:
				self.cprint.print_error("Complex Graph can't be rendered with graphviz libraries, using .dot format instead!\n")
				graph_mgr.draw("CrossReferencesWithPatterns", False)
		else:
			try:
				graph_mgr.draw("CrossReferences", not opts.store_dot)
			except:
				self.cprint.print_error("Complex Graph can't be rendered with graphviz libraries, using .dot format instead!\n")
				graph_mgr.draw("CrossReferences", False)