Ejemplo n.º 1
0
  def print_vulnerability(cls, vulnerability: Vulnerabilities):
    """
    print_vulnerability takes a vulnerability, and well, it prints it
    """
    cvss_score = vulnerability.get_cvss_score()
    table_data = [
        ["ID", vulnerability.get_id()],
        ["Title", vulnerability.get_title()],
        ["Description", '\n'.join(wrap(vulnerability.get_description(), 100))],
        ["CVSS Score", f"{vulnerability.get_cvss_score()} - {cls.get_cvss_severity(cvss_score)}"],
        ]
    if vulnerability.get_cvss_vector():
      table_data.append(
          ["CVSS Vector", vulnerability.get_cvss_vector()]
          )

    table_data.extend(
        [
            ["CVE", vulnerability.get_cve()],
            ["Reference", vulnerability.get_reference()]
        ]
        )
    table_instance = DoubleTable(table_data)
    table_instance.inner_heading_row_border = False
    table_instance.inner_row_border = True
    cls.do_print(table_instance.table, cvss_score)

    print("----------------------------------------------------")
Ejemplo n.º 2
0
    def archs(self):
        filtered = []
        table    = []
        
        archs = sorted(list(self.executor.get_archs()))

        cur     = [archs[0]]
        loc_max = MN_INF
        for pos in range(1, len(archs)):
            if self.__is_similar(archs[pos], archs[pos-1]):
                cur.append(archs[pos])
            else:
                loc_max = max(loc_max, len(cur))
                filtered.append(['<cyan>{}</>'.format(x) for x in cur])
                cur = [archs[pos]]
        filtered.append(['<cyan>{}</>'.format(x) for x in cur])
        loc_max = max(loc_max, len(cur))
        
        table.append(['\r'] * len(filtered))
        for i in range(loc_max):
            cur_row = []
            for j in range(len(filtered)):
                cur_row.append('' if i >= len(filtered[j]) else make_colors(filtered[j][i]))
            table.append(cur_row)
        rtable = DoubleTable(table)
        rtable.inner_heading_row_border = False
        return rtable.table
Ejemplo n.º 3
0
    def archs(self):
        filtered = []
        table    = []
        
        archs = sorted(list(self.executor.get_archs()))

        cur     = [archs[0]]
        loc_max = MN_INF
        for pos in range(1, len(archs)):
            if self.__is_similar(archs[pos], archs[pos-1]):
                cur.append(archs[pos])
            else:
                loc_max = max(loc_max, len(cur))
                filtered.append(['<cyan>{}</>'.format(x) for x in cur])
                cur = [archs[pos]]
        filtered.append(['<cyan>{}</>'.format(x) for x in cur])
        loc_max = max(loc_max, len(cur))
        
        table.append(['\r'] * len(filtered))
        for i in range(loc_max):
            cur_row = []
            for j in range(len(filtered)):
                cur_row.append('' if i >= len(filtered[j]) else make_colors(filtered[j][i]))
            table.append(cur_row)
        rtable = DoubleTable(table)
        rtable.inner_heading_row_border = False
        return rtable.table
Ejemplo n.º 4
0
def choice(choices, default):
    """ Asks the user which string he wants from a list of strings.
    Returns the selected string.

    :param choices: List of choices (one choice is a string)
    :type choices: list
    :param default: One element from the choices list.
    :type default: str
    :return: The choice selected by the user.
    :rtype: str
    """
    idx = 0
    data = list()
    colorama.init()
    default_idx = 0
    for choice in choices:
        if choice == default:
            data.append([
                '{}-> {}{}'.format(Fore.GREEN, idx, Style.RESET_ALL),
                '{}{}{}'.format(Fore.GREEN, choice, Style.RESET_ALL)
            ])
            default_idx = idx
        else:
            data.append([idx, choice])
        idx = idx + 1

    table = DoubleTable(data, title='Choices')
    table.inner_heading_row_border = False
    print(table.table)

    while True:
        input_msg = '{}[Choice or Enter for {} -> default ({}){}]> {}'.format(
            Fore.LIGHTBLUE_EX, Fore.GREEN, default_idx, Fore.LIGHTBLUE_EX,
            Style.RESET_ALL)
        print(input_msg, end='')
        last_in = input()

        if len(last_in) == 0:
            return choices[default_idx]

        choice, *args = shlex.split(last_in)
        if len(args) > 0:
            print('What did you mean?')
            continue

        try:
            choice = int(choice)
        except ValueError:
            print('Illegal choice "' + str(choice) + '", choose again')
            continue

        if choice >= 0 and choice < idx:
            return choices[choice]

        print('Illegal choice "' + str(choice) + '", choose again')
Ejemplo n.º 5
0
def print_terminal_table(table_data, method_used):
    """
    Prints a table with the results in the terminal.
    :param table_data: the data of the table
    :param method_used: the method used, to print as the table title
    :return: None
    """
    table = DoubleTable(table_data)
    table.title = method_used
    table.inner_heading_row_border = False
    table.inner_row_border = True
    print(table.table)
Ejemplo n.º 6
0
def table(title, rows=[]):
    print(Style.RESET_ALL)

    if len(rows) > 0 and type(rows[0]) != tuple:
        rows = [[
            row,
        ] for row in rows]

    table_instance = DoubleTable(rows, Fore.YELLOW + title + Fore.RESET)
    table_instance.outer_border = True
    table_instance.inner_heading_row_border = False
    table_instance.inner_column_border = True

    print(table_instance.table)
Ejemplo n.º 7
0
    def imputer(self, imputMethod='norm.nob'):
        def __plot_conversion(missingValueIndex=0):
            plt.plot(list(range(0, self.iteration)),
                     self.iterationLog[:, missingValueIndex], 'bo',
                     list(range(0, self.iteration)),
                     self.iterationLog[:, missingValueIndex], 'k')
            plt.axis([
                0, self.iteration,
                np.min(self.iterationLog[:, missingValueIndex]) - 1,
                np.max(self.iterationLog[:, missingValueIndex]) + 1
            ])
            plt.ylabel('Iteration')
            plt.show()

        featureWithNone = set(self.missedValuesMap[1])
        self.simple_imputation(imputMethod='imputMean')  # Step1: Mice
        iterations = iter(range(0, self.iteration))
        doneLooping = False
        while not doneLooping:
            try:
                iteration = next(iterations)
                print('The iteration {} is started:'.format(iteration + 1))
                imputeValuesOrdByCol = []
                for featureItem in featureWithNone:
                    rowIndexes = self.__place_holder(
                        featureItem=featureItem)  # Step2: Mice
                    predictedValues = self.predictive_model(
                    )  # methodName='norm'
                    self.__imput(rowIndexes, predictedValues, featureItem)
                    print(predictedValues.ravel().tolist())
                    imputeValuesOrdByCol.append(list(
                        predictedValues.flatten()))
            except StopIteration:
                doneLooping = True
            else:
                # Flatten the list of list ^ add to the iteration log
                self.iterationLog[iteration] = list(
                    itertools.chain(*imputeValuesOrdByCol))
                print('-' * 100)
        table = DoubleTable(self.iterationLog.tolist())
        table.inner_heading_row_border = False
        table.justify_columns[1] = 'center'
        print(table.table)
        __plot_conversion()