How bofeng17/aim-interrupt-modeling works
Main Components & Their Roles
• CLI & Experiment Driver:
• File: analysis.py (the entry point that takes in the firmware name and result folder via command-line arguments).
• Role: Orchestrates the overall analysis flow, invokes the necessary processing routines, and manages result output.
• Firmware Artifacts:
• Directory: fw/ (subdirectories such as cnc_r1, drone_hardfpu, plc_r1, etc.).
• Role: Provides the various firmware images (binary files, ELF files, configuration files, and peripheral models in JSON) that serve as inputs to the analysis engine.
• Analysis Engine & Core Modules:
• Files: int.py, int_solving.py, isr_analysis.py, path_sched.py, util.py, and error_checker.py.
• Role: Consists of the logic for analyzing firmware, particularly handling the interrupt modeling and scheduling. These modules likely prepare the data, set up the symbolic execution with angr (possibly by modifying control flow or interrupt simulation aspects), and interpret execution paths.
• Evaluation & Visualization:
• Directory: eval/ (contains scripts like cp_statuscsv.py, func_cov.py, misc.py, plot.py, process.py, statistics.py, and an example C file).
• Role: Handles post-analysis processes such as computing coverage, generating plots/statistics, and creating visual representations of the results.
• Additional Utilities:
• Files: analysis.py, error_checker.py, and others that provide support functions for error detection, result evaluation, and experiment baseline settings.
• Dependency Integration (angr & Modifications):
• Role: The project is built on the angr symbolic execution framework (with specific tested versions and custom modifications to its internal modules, as described in the README). This ensures that the analysis engine correctly handles interrupts—especially with modifications in DDG analysis and lifting functions.
Mapping Component Relationships & Data Flow
• Start at the CLI Driver (analysis.py):
• Takes a firmware ID (e.g., “plc_r1”) and passes it to the analysis engine.
• Firmware Loader:
• The analysis engine uses the fw directory as the source for firmware images, configurations, and peripheral models.
• Core Analysis Process:
• Modules such as int.py, int_solving.py, isr_analysis.py, and path_sched.py collaborate, leveraging angr for symbolic execution. Their interactions model dynamic firmware behavior, particularly focusing on how interrupts affect execution.
• Symbolic Execution Engine:
• Acts as a backbone for analysis. The customized angr environment (with modifications on DDG and lifting configurations) executes the firmware’s control flow, tracking interrupts.
• Result Aggregation & Evaluation:
• Once the dynamic analysis completes, evaluation modules (in the eval directory) process the output to compute metrics (like function coverage and control flow statistics), and generate plots or CSV reports.
Architectural Patterns & Design Principles
• Modularity:
• Each main functionality (firmware analysis, interrupt modeling, results evaluation) is separated into its own set of files and directories. This clear modular division facilitates independent development, testing, and future extension.
• Separation of Concerns:
• The system distinguishes between core data processing (analysis engine), external data (firmware files), and result evaluation (post-processing scripts). This separation supports maintainability and scalability.
• Configuration Flexibility:
• The firmware directories and config files suggest high customizability to model different hardware scenarios (e.g., CNC, drone, PLC).
• Dependency & Environment Setup:
• Specific instructions regarding the angr version and modifications indicate careful dependency management to ensure the symbolic execution engine’s correctness.