# shreyansh26/opcodes-for-malware-detection architecture

> Architecture diagram of the GitHub repository shreyansh26/opcodes-for-malware-detection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shreyansh26/opcodes-for-malware-detection
- Repository: https://github.com/shreyansh26/opcodes-for-malware-detection

## Overview

##### Project type and purpose
- This is a standalone command-line machine-learning pipeline for malware detection.
- It takes ELF binaries as input, extracts opcode statistics, preprocesses them into ARFF/CSV datasets, applies pre-trained models (J48, JRip, Random Forest), and outputs classification results.
- It uses Python for orchestration and preprocessing, and Java (Weka) for model evaluation.

##### File structure
Top-level items:
- elf/                – input folder of ELF binaries (malware & benign)
- benign.csv, malware.csv  – labeled opcode frequency datasets
- opcode_freq.py       – Python script to extract opcode frequencies
- preprocess.ipynb     – exploratory notebook for preprocessing
- run_system.py        – main Python orchestrator
- models/              – stored pre-trained Weka models (.model files)
- system/
– preprocess.py     – Python preprocessing module
– evaluate.java     – Java code that loads ARFF and models, then classifies
– weka.jar          – Weka library
– final.arff/.csv    – consolidated dataset outputs
– Makefile          – build/run targets
- results*.csv         – output classification results

Patterns & choices:
- A linear ETL+ML pipeline
- Separation of concern: data ingestion → feature extraction → dataset assembly → model evaluation
- Mixed-language approach: Python for data prep, Java (Weka) for classification

##### README for additional insights
- Entry point: `python run_system.py`
- Models have been pre-trained; current code focuses on evaluation on new ELF files.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Data Ingestion & Feature Extraction
    subgraph "1. Data Ingestion & Feature Extraction"
        ELF["elf/"]:::fs
        opcode["opcode_freq.py"]:::script
        raw_csv["Opcode CSVs"]:::data
        notebook["preprocess.ipynb"]:::script
    end

    ELF -->|"ELF binaries"| opcode
    opcode -->|"opcode CSV"| raw_csv
    notebook -.->|"exploration"| raw_csv

    %% Dataset Assembly
    subgraph "2. Dataset Assembly"
        benign["benign.csv"]:::data
        malware["malware.csv"]:::data
        preprocess_mod["system/preprocess.py"]:::script
        final_arff["final.arff"]:::data
        final_csv["final.csv"]:::data
        final2["final2.csv"]:::data
    end

    raw_csv -->|"raw CSVs"| preprocess_mod
    benign -->|"labeled CSV"| preprocess_mod
    malware -->|"labeled CSV"| preprocess_mod
    preprocess_mod -->|"ARFF"| final_arff
    preprocess_mod -->|"CSV"| final_csv
    preprocess_mod -->|"CSV"| final2

    %% Model Evaluation
    subgraph "3. Model Evaluation"
        models["models/"]:::data
        evaluate_java["evaluate.java"]:::java
        weka["weka.jar"]:::java
        makefile["Makefile"]:::script
        results_all["results.csv"]:::data
        results_ben["results_benign.csv"]:::data
        results_mal["results_malware.csv"]:::data
    end

    final_arff -->|"ARFF dataset"| evaluate_java
    models -->|"*.model files"| evaluate_java
    weka --> evaluate_java
    makefile --> evaluate_java
    evaluate_java -->|"classification results"| results_all
    evaluate_java -->|"classification results"| results_ben
    evaluate_java -->|"classification results"| results_mal

    %% Orchestrator
    orchestrator["run_system.py"]:::script
    orchestrator -->|"start pipeline"| opcode
    orchestrator -->|"invoke evaluation"| evaluate_java

    %% Click Events
    click ELF "https://github.com/shreyansh26/opcodes-for-malware-detection/tree/master/elf/"
    click opcode "https://github.com/shreyansh26/opcodes-for-malware-detection/blob/master/opcode_freq.py"
    click notebook "https://github.com/shreyansh26/opcodes-for-malware-detection/blob/master/preprocess.ipynb"
    click orchestrator "https://github.com/shreyansh26/opcodes-for-malware-detection/blob/master/run_system.py"
    click preprocess_mod "https://github.com/shreyansh26/opcodes-for-malware-detection/blob/master/system/preprocess.py"
    click final_arff "https://github.com/shreyansh26/opcodes-for-malware-detection/blob/master/system/final.arff"
    click final_csv "https://github.com/shreyansh26/opcodes-for-malware-detection/blob/master/system/final.csv"
    click final2 "https://github.com/shreyansh26/opcodes-for-malware-detection/blob/master/system/final2.csv"
    click models "https://github.com/shreyansh26/opcodes-for-malware-detection/tree/master/models/"
    click evaluate_java "https://github.com/shreyansh26/opcodes-for-malware-detection/blob/master/system/evaluate.java"
    click weka "https://github.com/shreyansh26/opcodes-for-malware-detection/blob/master/system/weka.jar"
    click makefile "https://github.com/shreyansh26/opcodes-for-malware-detection/tree/master/system/Makefile"
    click benign "https://github.com/shreyansh26/opcodes-for-malware-detection/blob/master/benign.csv"
    click malware "https://github.com/shreyansh26/opcodes-for-malware-detection/blob/master/malware.csv"
    click results_all "https://github.com/shreyansh26/opcodes-for-malware-detection/blob/master/results.csv"
    click results_ben "https://github.com/shreyansh26/opcodes-for-malware-detection/blob/master/results_benign.csv"
    click results_mal "https://github.com/shreyansh26/opcodes-for-malware-detection/blob/master/results_malware.csv"

    %% Styles
    classDef fs fill:#f9f,stroke:#333,stroke-width:1px
    classDef script fill:#bbf,stroke:#333,stroke-width:1px
    classDef data fill:#bfb,stroke:#333,stroke-width:1px
    classDef java fill:#fbf,stroke:#333,stroke-width:1px
```
