def prepare_graph(histories: List[Path], annotations: List[Path], min_size: int, max_rel_fuzz: float) -> Optional[Graph]: logger.debug("Importing history") for history, annotation in zip(histories, annotations): bin_ = get_or_create_binary(history) get_or_create_annotation(bin_, annotation) logger.debug(f"Imported history {bin_.serialize()}") if Binary.select_annotated().count() == 0: typer.echo("No history entries in database") return None if histories: logger.debug("Clearing matchers") Matcher.reset() logger.debug("Grouping function symbols") groups = Function.common_functions(min_size, 1) logger.debug("finished grouping") logger.debug("make matchers") matchers = create_matchers(groups, min_size, max_rel_fuzz) logger.debug(f"{len(matchers)} matchers generated") graph = makeGraph(matchers) logger.debug("finish making matchers") return graph
def _cli_list( list_history: bool, list_targets: bool, ): def format_binary_list( binary_list: Iterable[Binary], is_annotated: Optional[bool] = False) -> Iterable[dict]: keys = ["id", "name", "filepath"] data = [] for binary in list(binaries): b_dict = binary.to_dict(only=keys) if is_annotated is True: b_dict["#annotations"] = binary.annotations.count() b_dict["#functions"] = binary.functions.count() data.append(b_dict) return data if list_history is True: typer.echo("History Files") binaries = Binary.select_annotated() formatted = format_binary_list(binaries, is_annotated=True) table = tabulate(formatted, headers="keys") typer.echo(table) if list_history is True and list_targets is True: typer.echo() # additional newline for readability if list_targets is True: typer.echo("Target Files") binaries = Binary.select_unannotated() formatted = format_binary_list(binaries, is_annotated=False) table = tabulate(formatted, headers="keys") typer.echo(table)