Implementation:416rehman DeepZero SemgrepScanner
| Knowledge Sources | |
|---|---|
| Domains | Static_Analysis, Security_Research, External_Tool |
| Last Updated | 2026-10-27 00:00 GMT |
Overview
External BulkMapProcessor that runs semgrep batch scans against decompiled source across all active samples, with batching, finding distribution, and silent-empty-results guards.
Description
The SemgrepScanner class is an external BulkMapProcessor (located in processors/semgrep_scanner/) that scans decompiled C code with semgrep using custom rule packs. As a BulkMap processor, it processes all active samples in one (or batched) semgrep invocation, which is more efficient than per-sample invocation because semgrep has high startup cost.
Key behaviors:
- Batching: samples are divided into batches (default 200 per batch) so a batch timeout or failure costs only its own samples, not the whole corpus.
- Bulk directory: decompiled files from all samples in a batch are hard-linked (or copied) into a temporary directory with sample-prefixed names, so semgrep scans them in one run and findings can be distributed back to their source samples.
- Finding distribution: after the scan, findings are matched back to samples by filename prefix and written as per-sample findings.json files.
- Silent-empty-results guards: three guards prevent false "clean" results:
- If semgrep exits with errors and no results, the sample is marked FAILED (not clean).
- If semgrep reports config load errors in its "errors" array, the sample is marked FAILED.
- If semgrep lists zero scanned files, the sample is marked FAILED (no files read ≠ no vulnerabilities found).
- Caching: samples with existing findings.json are read from cache without rescanning.
The processor provides finding_count, findings_cached, files_submitted, files_scanned, findings (filename), and findings_json (parsed report).
Usage
- BYOVD scanning: rules_dir: "pipelines/loldrivers/rules", target_dir: "decompiled"
- Minimum findings threshold: min_findings: 1 (filters samples with no findings)
- Batch size control: batch_size: 200
Code Reference
Source Location
- Repository: DeepZero
- File: processors/semgrep_scanner/semgrep_scanner.py
Signature
class SemgrepScanner(BulkMapProcessor):
description = "runs semgrep batch scan against decompiled source across all active samples"
provides = (
"finding_count", "findings_cached", "files_submitted",
"files_scanned", "findings", "findings_json",
)
def validate(self, ctx: ProcessorContext) -> list[str]: ...
def process(
self, ctx: ProcessorContext, entries: list[ProcessorEntry]
) -> list[ProcessorResult]: ...
Import
# Loaded via pipeline YAML as: processor: semgrep_scanner/semgrep_scanner.py
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| rules_dir | str | Yes (config) | Path to semgrep rule YAMLs |
| target_dir | str | No (config) | Subdir with decompiled code (default "decompiled") |
| timeout | int | No (config) | Per-batch timeout (default 300) |
| min_findings | int | No (config) | Min findings to pass (default 0) |
| batch_size | int | No (config) | Samples per batch (default 200) |
| entries | list[ProcessorEntry] | Yes (runtime) | All active samples with decompiled code |
Outputs
| Name | Type | Description |
|---|---|---|
| returns | list[ProcessorResult] | One result per entry (ok/filter/fail) |
| artifacts["findings"] | str | "findings.json" per sample |
| data | dict | finding_count, findings_cached, files_submitted, files_scanned |
Usage Examples
BYOVD Pipeline YAML
stages:
- name: semgrep_scanner
processor: semgrep_scanner/semgrep_scanner.py
config:
rules_dir: "pipelines/loldrivers/rules"
target_dir: "decompiled"
timeout: 300
min_findings: 0
batch_size: 200
Semgrep Command (Built Internally)
# The processor runs this per batch:
semgrep scan \
--config <rules_dir> \
--json \
--output <report_path> \
--no-git-ignore \
--quiet \
--metrics=off \
--disable-version-check \
<bulk_dir>
Related Pages
Implements Principle
- Principle:416rehman_DeepZero_Static_Analysis_Scanning
- Principle:416rehman_DeepZero_Processor_Contract