Skip to content

Commit 2895922

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

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

Diff for: 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
@@ -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 skip_extraction:
277+
print_scan_report(process_results)
278+
else:
279+
print_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

Diff for: unblob/processing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ def __init__(
469469
def process(self):
470470
logger.debug("Processing file", path=self.task.path, size=self.size)
471471

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

0 commit comments

Comments
 (0)