Skip to content

Commit

Permalink
added and propagated cli option to skip extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
dorpvom committed Oct 12, 2022
1 parent 91a2b04 commit f5a9490
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
10 changes: 10 additions & 0 deletions unblob/cli.py
Expand Up @@ -151,6 +151,14 @@ def __init__(
type=click.Path(path_type=Path),
help="File to store metadata generated during the extraction process (in JSON format).",
)
@click.option(
"-s",
"--skip_extraction",
"skip_extraction",
is_flag=True,
show_default=True,
help="Only carve chunks and skip further extraction",
)
@click.option(
"-k",
"--keep-extracted-chunks",
Expand All @@ -176,6 +184,7 @@ def cli(
depth: int,
entropy_depth: int,
skip_magic: Iterable[str],
skip_extraction: bool,
keep_extracted_chunks: bool,
handlers: Handlers,
plugins_path: Optional[Path],
Expand All @@ -194,6 +203,7 @@ def cli(
max_depth=depth,
entropy_depth=entropy_depth,
entropy_plot=bool(verbose >= 3),
skip_extraction=skip_extraction,
skip_magic=skip_magic,
process_num=process_num,
handlers=handlers,
Expand Down
22 changes: 12 additions & 10 deletions unblob/processing.py
Expand Up @@ -72,6 +72,7 @@ class ExtractionConfig:
entropy_plot: bool = False
max_depth: int = DEFAULT_DEPTH
skip_magic: Iterable[str] = DEFAULT_SKIP_MAGIC
skip_extraction: bool = False
process_num: int = DEFAULT_PROCESS_NUM
keep_extracted_chunks: bool = False
extract_suffix: str = "_extract"
Expand Down Expand Up @@ -367,19 +368,20 @@ def _extract_chunk(self, file, chunk: ValidChunk):
carved_path = inpath

extraction_reports = []
try:
chunk.extract(inpath, extract_dir)
if not self.config.skip_extraction:
try:
chunk.extract(inpath, extract_dir)

if carved_path and not self.config.keep_extracted_chunks:
logger.debug("Removing extracted chunk", path=carved_path)
carved_path.unlink()
if carved_path and not self.config.keep_extracted_chunks:
logger.debug("Removing extracted chunk", path=carved_path)
carved_path.unlink()

except ExtractError as e:
extraction_reports.extend(e.reports)
except ExtractError as e:
extraction_reports.extend(e.reports)

except Exception as exc:
logger.exception("Unknown error happened while extracting chunk")
extraction_reports.append(UnknownError(exception=exc))
except Exception as exc:
logger.exception("Unknown error happened while extracting chunk")
extraction_reports.append(UnknownError(exception=exc))

self.result.add_report(chunk.as_report(extraction_reports))

Expand Down

0 comments on commit f5a9490

Please sign in to comment.