How fics/bigmac works
Project Type and Purpose
• BigMAC is a Python‐based command‐line tool for extracting, processing, and querying Android DAC/MAC/CAP security policies from firmware images.
• It is neither a web/full‐stack app nor a microservice suite; it is a standalone data‐processing and analysis framework with an interactive Prolog query interface.
Key Architectural Layers and Components
a. Ingestion & Extraction
• CLI Frontend (process.py) – parses arguments, coordinates workflow.
• Firmware Extractors (tools/android-extract.sh, extract.py, overlay.py) – pull filesystem and policy blobs from firmware.
• eval/ and tools/ modules – evaluation harness and helper scripts for bulk processing.
b. Policy Parsing & Processing
• Android Policy Config Parsers (android/ directory: file_contexts.py, initrc.py, sepolicy.py, etc.) – wrappers around libsepol and setools interacting with patched C libraries.
• security_policy.py and config.py – high-level orchestration of parsing, layering DAC/MAC/CAP.
c. Graph & Logic Layer
• segraph.py / stats.py / sedump.py – construct internal graph representation of subjects, objects, rules.
• Prolog Integration (prolog.py, graph2prolog.py, logic/ directory) – emit facts, load SWI-Prolog environment, serve interactive queries.
• logic/main*.pl – Prolog rules for querying extracted policies.
d. Persistence & Reporting
• Saved policy databases (db/ under each vendor directory) – SQLite or serialized Python objects.
• facts/*.pl and stats/*.txt – Prolog facts and statistical summaries.
• Evaluation outputs in eval/ – ground truth, CVE analysis, comparison scripts.
Relationships and Data Flows
• The user invokes the CLI (process.py).
• Extraction modules unpack firmware → file trees & raw policy files.
• Parser modules (android/*.py + libsepol/setools) process raw policy into in-memory structures.
• Graph builders convert structures into a property graph (segraph.py).
• Persistence layer serializes the graph to disk (db/), optionally dumps Prolog facts.
• Prolog interface loads facts, provides REPL for interactive queries.
• Evaluation scripts in eval/ ingest saved graphs or raw data, compare policies, generate reports.
Architectural Patterns & Principles
• Pipeline/Layered Architecture: clear separation of extraction → parsing → graph building → query.
• Plugin-like Parsers: android/*.py can be extended to support new policy sources.
• Data-flow Orientation: each step produces artifacts consumed by the next.
• External Tool Integration: libsepol and setools are patched and invoked as native libraries.