diff --git a/unblob/cli.py b/unblob/cli.py index d0eb805fa4..9a117c86e1 100755 --- a/unblob/cli.py +++ b/unblob/cli.py @@ -8,12 +8,18 @@ import click from rich.console import Console from rich.panel import Panel +from rich.style import Style from rich.table import Table from structlog import get_logger from unblob.models import DirectoryHandlers, Handlers, ProcessResult from unblob.plugins import UnblobPluginManager -from unblob.report import ChunkReport, Severity, StatReport, UnknownChunkReport +from unblob.report import ( + ChunkReport, + Severity, + StatReport, + UnknownChunkReport, +) from .cli_options import verbosity_option from .dependencies import get_dependencies, pretty_format_dependencies @@ -279,7 +285,10 @@ def cli( logger.info("Start processing file", file=file) process_results = process_file(config, file, report_file) if verbose == 0: - print_report(process_results) + if skip_extraction: + print_scan_report(process_results) + else: + print_report(process_results) return process_results @@ -349,6 +358,50 @@ def get_size_report(task_results: List) -> Tuple[int, int, int, int]: return total_files, total_dirs, total_links, extracted_size +def print_scan_report(reports: ProcessResult): + console = Console(stderr=True) + + chunks_offset_table = Table( + expand=False, + show_lines=True, + show_edge=True, + style=Style(color="white"), + header_style=Style(color="white"), + row_styles=[Style(color="red")], + ) + chunks_offset_table.add_column("Start offset") + chunks_offset_table.add_column("End offset") + chunks_offset_table.add_column("Size") + chunks_offset_table.add_column("Description") + + for task_result in reports.results: + chunk_reports = [ + report + for report in task_result.reports + if isinstance(report, (ChunkReport, UnknownChunkReport)) + ] + chunk_reports.sort(key=lambda x: x.start_offset) + + for chunk_report in chunk_reports: + if isinstance(chunk_report, ChunkReport): + chunks_offset_table.add_row( + f"{chunk_report.start_offset:0d}", + f"{chunk_report.end_offset:0d}", + human_size(chunk_report.size), + chunk_report.handler_name, + style=Style(color="#00FFC8"), + ) + if isinstance(chunk_report, UnknownChunkReport): + chunks_offset_table.add_row( + f"{chunk_report.start_offset:0d}", + f"{chunk_report.end_offset:0d}", + human_size(chunk_report.size), + "unknown", + style=Style(color="#008ED5"), + ) + console.print(chunks_offset_table) + + def print_report(reports: ProcessResult): total_files, total_dirs, total_links, extracted_size = get_size_report( reports.results diff --git a/unblob/processing.py b/unblob/processing.py index 4f5028f93f..5aefa6905a 100644 --- a/unblob/processing.py +++ b/unblob/processing.py @@ -476,7 +476,7 @@ def __init__( def process(self): logger.debug("Processing file", path=self.task.path, size=self.size) - if not self.config.skip_extraction and self.carve_dir.exists(): + if self.carve_dir.exists() and not self.config.skip_extraction: # Extraction directory is not supposed to exist, it is usually a simple mistake of running # unblob again without cleaning up or using --force. # It would cause problems continuing, as it would mix up original and extracted files,