Skip to content

Commit 5e2c679

Browse files
committed
feat(ui): display scan report when extraction is skipped.
1 parent 6aabbc7 commit 5e2c679

File tree

1 file changed

+55
-2
lines changed

1 file changed

+55
-2
lines changed

unblob/cli.py

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@
88
import click
99
from rich.console import Console
1010
from rich.panel import Panel
11+
from rich.style import Style
1112
from rich.table import Table
1213
from structlog import get_logger
1314

1415
from unblob.models import DirectoryHandlers, Handlers, ProcessResult
1516
from unblob.plugins import UnblobPluginManager
16-
from unblob.report import ChunkReport, Severity, StatReport, UnknownChunkReport
17+
from unblob.report import (
18+
ChunkReport,
19+
Severity,
20+
StatReport,
21+
UnknownChunkReport,
22+
)
1723

1824
from .cli_options import verbosity_option
1925
from .dependencies import get_dependencies, pretty_format_dependencies
@@ -267,7 +273,10 @@ def cli(
267273
logger.info("Start processing file", file=file)
268274
process_results = process_file(config, file, report_file)
269275
if verbose == 0:
270-
print_report(process_results)
276+
if not skip_extraction:
277+
print_report(process_results)
278+
else:
279+
print_scan_report(process_results)
271280
return process_results
272281

273282

@@ -337,6 +346,50 @@ def get_size_report(task_results: List) -> Tuple[int, int, int, int]:
337346
return total_files, total_dirs, total_links, extracted_size
338347

339348

349+
def print_scan_report(reports: ProcessResult):
350+
console = Console(stderr=True)
351+
352+
chunks_offset_table = Table(
353+
expand=False,
354+
show_lines=True,
355+
show_edge=True,
356+
style=Style(color="white"),
357+
header_style=Style(color="white"),
358+
row_styles=[Style(color="red")],
359+
)
360+
chunks_offset_table.add_column("Start offset")
361+
chunks_offset_table.add_column("End offset")
362+
chunks_offset_table.add_column("Size")
363+
chunks_offset_table.add_column("Description")
364+
365+
for task_result in reports.results:
366+
chunk_reports = [
367+
report
368+
for report in task_result.reports
369+
if isinstance(report, (ChunkReport, UnknownChunkReport))
370+
]
371+
chunk_reports.sort(key=lambda x: x.start_offset)
372+
373+
for chunk_report in chunk_reports:
374+
if isinstance(chunk_report, ChunkReport):
375+
chunks_offset_table.add_row(
376+
f"{chunk_report.start_offset:0d}",
377+
f"{chunk_report.end_offset:0d}",
378+
human_size(chunk_report.size),
379+
chunk_report.handler_name,
380+
style=Style(color="#00FFC8"),
381+
)
382+
if isinstance(chunk_report, UnknownChunkReport):
383+
chunks_offset_table.add_row(
384+
f"{chunk_report.start_offset:0d}",
385+
f"{chunk_report.end_offset:0d}",
386+
human_size(chunk_report.size),
387+
"unknown",
388+
style=Style(color="#008ED5"),
389+
)
390+
console.print(chunks_offset_table)
391+
392+
340393
def print_report(reports: ProcessResult):
341394
total_files, total_dirs, total_links, extracted_size = get_size_report(
342395
reports.results

0 commit comments

Comments
 (0)