|
8 | 8 | import click
|
9 | 9 | from rich.console import Console
|
10 | 10 | from rich.panel import Panel
|
| 11 | +from rich.style import Style |
11 | 12 | from rich.table import Table
|
12 | 13 | from structlog import get_logger
|
13 | 14 |
|
14 | 15 | from unblob.models import DirectoryHandlers, Handlers, ProcessResult
|
15 | 16 | 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 | +) |
17 | 23 |
|
18 | 24 | from .cli_options import verbosity_option
|
19 | 25 | from .dependencies import get_dependencies, pretty_format_dependencies
|
@@ -279,7 +285,10 @@ def cli(
|
279 | 285 | logger.info("Start processing file", file=file)
|
280 | 286 | process_results = process_file(config, file, report_file)
|
281 | 287 | 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) |
283 | 292 | return process_results
|
284 | 293 |
|
285 | 294 |
|
@@ -349,6 +358,50 @@ def get_size_report(task_results: List) -> Tuple[int, int, int, int]:
|
349 | 358 | return total_files, total_dirs, total_links, extracted_size
|
350 | 359 |
|
351 | 360 |
|
| 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 | + |
352 | 405 | def print_report(reports: ProcessResult):
|
353 | 406 | total_files, total_dirs, total_links, extracted_size = get_size_report(
|
354 | 407 | reports.results
|
|
0 commit comments