Skip to content

Commit

Permalink
feat(ui): display scan report when extraction is skipped.
Browse files Browse the repository at this point in the history
  • Loading branch information
qkaiser committed Dec 24, 2023
1 parent 6aabbc7 commit 5e2c679
Showing 1 changed file with 55 additions and 2 deletions.
57 changes: 55 additions & 2 deletions unblob/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -267,7 +273,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 not skip_extraction:
print_report(process_results)
else:
print_scan_report(process_results)
return process_results


Expand Down Expand Up @@ -337,6 +346,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
Expand Down

0 comments on commit 5e2c679

Please sign in to comment.