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
Co-authored-by: Krisztián Fekete <[email protected]>
  • Loading branch information
qkaiser and e3krisztian committed Jan 3, 2024
1 parent 58f9f25 commit d1b6ccc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 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 @@ -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


Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion unblob/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d1b6ccc

Please sign in to comment.