|
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
|
@@ -267,7 +273,10 @@ def cli(
|
267 | 273 | logger.info("Start processing file", file=file)
|
268 | 274 | process_results = process_file(config, file, report_file)
|
269 | 275 | 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) |
271 | 280 | return process_results
|
272 | 281 |
|
273 | 282 |
|
@@ -337,6 +346,50 @@ def get_size_report(task_results: List) -> Tuple[int, int, int, int]:
|
337 | 346 | return total_files, total_dirs, total_links, extracted_size
|
338 | 347 |
|
339 | 348 |
|
| 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 | + |
340 | 393 | def print_report(reports: ProcessResult):
|
341 | 394 | total_files, total_dirs, total_links, extracted_size = get_size_report(
|
342 | 395 | reports.results
|
|
0 commit comments