Skip to content

Commit d1b6ccc

Browse files
qkaisere3krisztian
andcommitted
feat(ui): display scan report when extraction is skipped.
Co-authored-by: Krisztián Fekete <[email protected]>
1 parent 58f9f25 commit d1b6ccc

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

unblob/cli.py

+55-2
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
@@ -279,7 +285,10 @@ def cli(
279285
logger.info("Start processing file", file=file)
280286
process_results = process_file(config, file, report_file)
281287
if verbose == 0:
282-
print_report(process_results)
288+
if skip_extraction:
289+
print_scan_report(process_results)
290+
else:
291+
print_report(process_results)
283292
return process_results
284293

285294

@@ -349,6 +358,50 @@ def get_size_report(task_results: List) -> Tuple[int, int, int, int]:
349358
return total_files, total_dirs, total_links, extracted_size
350359

351360

361+
def print_scan_report(reports: ProcessResult):
362+
console = Console(stderr=True)
363+
364+
chunks_offset_table = Table(
365+
expand=False,
366+
show_lines=True,
367+
show_edge=True,
368+
style=Style(color="white"),
369+
header_style=Style(color="white"),
370+
row_styles=[Style(color="red")],
371+
)
372+
chunks_offset_table.add_column("Start offset")
373+
chunks_offset_table.add_column("End offset")
374+
chunks_offset_table.add_column("Size")
375+
chunks_offset_table.add_column("Description")
376+
377+
for task_result in reports.results:
378+
chunk_reports = [
379+
report
380+
for report in task_result.reports
381+
if isinstance(report, (ChunkReport, UnknownChunkReport))
382+
]
383+
chunk_reports.sort(key=lambda x: x.start_offset)
384+
385+
for chunk_report in chunk_reports:
386+
if isinstance(chunk_report, ChunkReport):
387+
chunks_offset_table.add_row(
388+
f"{chunk_report.start_offset:0d}",
389+
f"{chunk_report.end_offset:0d}",
390+
human_size(chunk_report.size),
391+
chunk_report.handler_name,
392+
style=Style(color="#00FFC8"),
393+
)
394+
if isinstance(chunk_report, UnknownChunkReport):
395+
chunks_offset_table.add_row(
396+
f"{chunk_report.start_offset:0d}",
397+
f"{chunk_report.end_offset:0d}",
398+
human_size(chunk_report.size),
399+
"unknown",
400+
style=Style(color="#008ED5"),
401+
)
402+
console.print(chunks_offset_table)
403+
404+
352405
def print_report(reports: ProcessResult):
353406
total_files, total_dirs, total_links, extracted_size = get_size_report(
354407
reports.results

unblob/processing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ def __init__(
476476
def process(self):
477477
logger.debug("Processing file", path=self.task.path, size=self.size)
478478

479-
if not self.config.skip_extraction and self.carve_dir.exists():
479+
if self.carve_dir.exists() and not self.config.skip_extraction:
480480
# Extraction directory is not supposed to exist, it is usually a simple mistake of running
481481
# unblob again without cleaning up or using --force.
482482
# It would cause problems continuing, as it would mix up original and extracted files,

0 commit comments

Comments
 (0)