How supunhg/filo works
1. Repository purpose
Filo is an offline Python file-forensics toolkit. Its core job is to take an arbitrary blob, classify it into one or more formats, explain the evidence behind that decision, and optionally repair or extract hidden content.
2. Primary entry points
The main user-facing boundary is the CLI in filo/cli.py, which exposes subcommands such as analyze, batch, teach, repair, pcap, stego, lineage, and reset operations. The Python API mirrors the same capabilities through classes and helpers exported from filo/__init__.py.
3. Central orchestration layer
filo/analyzer.py is the hub of the system. It coordinates format detection, confidence scoring, evidence collection, contradiction checks, and downstream enrichments like metadata, fingerprints, embedded-object discovery, and ML-assisted classification.
4. Format knowledge base
File-type knowledge is mostly data-driven. filo/formats.py and the filo/formats/*.yaml catalog encode signatures and structural rules for 60+ formats, including archives, documents, executables, images, network captures, and container formats. This is what lets the analyzer distinguish close cousins like DOCX vs ZIP or APK vs JAR.
5. Evidence and confidence model
The repository is built around explainable detection rather than a single yes/no classifier. filo/models.py defines the structured results passed between modules, while filo/architecture.py, filo/metadata.py, filo/fingerprint.py, and filo/contradictions.py contribute evidence used to rank candidates and produce the confidence breakdown shown in the CLI.
6. Specialized analysis subsystems
Several modules handle domain-specific inspections:
- filo/container.py for ZIP-based/container formats
- filo/polyglot.py for dual-format files
- filo/embedded.py for hidden payloads and trailing data
- filo/crypto.py for encrypted-data heuristics
- filo/stego.py for image/document steganography
- filo/pcap.py for network capture analysis
- filo/office.py for Office macro/macros-in-OLE analysis
- filo/yarascanner.py for YARA rule matching
These modules are mostly independent detectors that feed findings back into the main result object.
7. Learning and profiling path
filo/ml.py and filo/profiler.py provide the offline learning layer. The pipeline learns discriminative byte patterns, statistical features, and n-gram profiles from known-good files, then uses those learned artifacts to improve later detections. This is explicitly local-state based, not cloud-backed.
8. Repair and carving path
filo/repair.py and filo/carver.py are the remediation side of the tool. They focus on reconstructing damaged headers, recovering structure, and extracting embedded or recoverable content from corrupted files. This is separate from pure identification, so analysis can remain non-destructive unless repair is requested.
9. Batching, export, and reporting
filo/batch.py handles directory-scale processing and parallelization. filo/export.py turns analysis results into machine-friendly outputs such as JSON or SARIF. The CLI’s default “top evidence” view is just one presentation layer over the same structured report.
10. State, lineage, and persistence boundaries
filo/lineage.py tracks hash-based chain-of-custody and file transformation history. The README indicates user state lives under ~/.filo/, including learned patterns and the lineage database, so the analyzer is stateless relative to file inputs but stateful across sessions for ML and provenance.
11. Packaging and deployment shape
The repo supports multiple delivery modes: pip/PyPI, Docker, and Debian packaging. Dockerfile, build-deb.sh, and packaging/DEBIAN/* show that the runtime is still the same Python application, but wrapped for isolated installation and offline use.
12. Test and demo corpus
tests/ is the main regression boundary, covering each subsystem individually and in integration. demo/ and examples/ provide representative malicious, corrupted, polyglot, and stego samples, which are important because this architecture is validated primarily by analyzing real file specimens rather than synthetic unit-only cases.
Main entry points: analyzer.py Analyzer · cli.py CLI · repair.py Repair · formats.py Format catalog
Components 25
Entry points
User-facing CLI and Python API boundaries
- CLI · Subcommands for analyze, batch, teach, repair, pcap, stego, lineage, and reset
filo/cli.py - Python API · Package exports that mirror the CLI capabilities
filo/__init__.py
Core analysis
Main orchestration, evidence, and format knowledge
- Analyzer · Coordinates detection, scoring, evidence collection, and enrichments
filo/analyzer.py - Result models · Structured analysis results and shared objects passed between modules
filo/models.py - Format catalog · Data-driven format knowledge and structural signatures
filo/formats.py - YAML rules · Per-format signatures and constraints for many file types
filo/formats - Architecture · Structural evidence used to identify and explain files
filo/architecture.py - Metadata · Extracts metadata signals for ranking and explanation
filo/metadata.py - Fingerprinting · Build and tool fingerprints used in confidence breakdowns
filo/fingerprint.py - Contradictions · Checks evidence conflicts and suppresses bad matches
filo/contradictions.py
Specialized detectors
Domain-specific inspection modules feeding analysis
- Containers · Inspects ZIP-based and other container formats
filo/container.py - Polyglots · Detects dual-format and overlapping file identities
filo/polyglot.py - Embedded data · Finds hidden payloads, overlays, and trailing content
filo/embedded.py - Crypto heuristics · Flags encrypted or key-protected content patterns
filo/crypto.py - Steganography · Looks for hidden content in images and documents
filo/stego.py - PCAP analysis · Analyzes packet-capture files and network evidence
filo/pcap.py - Office analysis · Special handling for Office and macro-bearing documents
filo/office.py - YARA scan · Matches rule-based indicators against file contents
filo/yarascanner.py
Learning and state
Local profiling, lineage, and persistent state
- ML learning · Learns discriminative byte patterns and feature models offline
filo/ml.py - Profiling · Builds byte statistics and n-gram profiles from known files
filo/profiler.py - Lineage · Tracks hash-based chain of custody and transformation history
filo/lineage.py
Repair and output
Batch processing, repair, carving, and export
- Repair · Reconstructs damaged structure and fixes corrupted files
filo/repair.py - Carving · Extracts recoverable or embedded content from damaged inputs
filo/carver.py - Batch · Directory-scale processing and parallel execution
filo/batch.py - Export · Serializes results to JSON, SARIF, and other machine formats
filo/export.py
Connections 27
- CLI → Analyzer: analyze · CLI drives the main analysis flow
- CLI → Batch: batch · CLI submits directory-scale jobs
- CLI → Repair: repair · CLI invokes remediation mode
- CLI → Lineage: lineage · CLI exposes provenance operations
- Python API → Analyzer: API · Package exports analysis helpers
- Analyzer → Result models: results · Produces structured result objects
- Analyzer → Format catalog: classify · Consults format knowledge during detection
- Format catalog → YAML rules: rules · Loads per-format YAML signatures
- Analyzer → Architecture: evidence · Uses structural evidence in scoring
- Analyzer → Metadata: evidence · Uses metadata signals in ranking
- Analyzer → Fingerprinting: evidence · Uses fingerprinting signals in ranking
- Analyzer → Contradictions: validate · Checks for conflicting evidence
- Analyzer → Containers: inspect · Delegates container-specific analysis
- Analyzer → Polyglots: inspect · Delegates polyglot detection
- Analyzer → Embedded data: inspect · Delegates hidden-payload discovery
- Analyzer → Crypto heuristics: inspect · Delegates encryption heuristics
- Analyzer → Steganography: inspect · Delegates steganography checks
- Analyzer → PCAP analysis: inspect · Delegates packet-capture analysis
- Analyzer → Office analysis: inspect · Delegates Office-specific inspection
- Analyzer → YARA scan: scan · Uses YARA rule matching as an auxiliary signal
- Analyzer → ML learning: learned signals · Consumes learned classification artifacts
- ML learning → Profiling: profiles · Builds learned features from known samples
- Lineage → Export: persist · Stores provenance for reporting and reuse
- Batch → Analyzer: fan out · Runs the analyzer across many inputs
- Repair → Carving: recover · Uses carving to extract recoverable content
- Repair → Analyzer: verify · Re-analyzes repaired files to confirm outcome
- Analyzer → Export: report · Feeds structured results into exporters