# ifbars/mlvscan architecture

> Architecture diagram of the GitHub repository ifbars/mlvscan, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ifbars/mlvscan
- Repository: https://github.com/ifbars/mlvscan

## Overview

##### Project type and purpose
- MLVScan is a .NET/C# plugin for MelonLoader (a game-mod loader).
- Its purpose is to perform static security scans on mods before they load, identify malicious patterns, disable offending mods, and generate reports.

##### File structure
- Core.cs: the plugin’s entry point, hooks into MelonLoader lifecycle.
- Models/: a set of IScanRule implementations (e.g., Base64Rule, RegistryRule) and data structures (ScanConfig, ScanFinding).
- Services/: the engine that drives scanning—ConfigManager, ServiceFactory, AssemblyScanner, ModScanner, ModDisabler.
- MLVScan.csproj/MLVScan.sln: .NET build artifacts.
- README.md, LICENSE: documentation.

##### README for additional insights
- Confirms static analysis of assemblies using Mono.Cecil.
- Describes modular rule system, severity levels, whitelist mechanism, and report generation.

##### Components and interactions
a. Main components
- Plugin Host (MelonLoader)
- Core Module (Core.cs)
- Configuration Manager (reads ScanConfig, whitelist)
- Service Factory (instantiates scanners and rules)
- Assembly Scanner (applies IScanRule instances)
- Mod Scanner (coordinates scanning of each mod DLL)
- Mod Disabler (blocks load of malicious mods)
- Reporting Engine (ScanFinding collector & report writer)
- Models (collection of rule implementations)
- External library: Mono.Cecil for IL inspection

b. Relationships / data flow
1. MelonLoader invokes Core.Initialize at game start.
2. Core calls ConfigManager → loads settings (whitelist, severity threshold).
3. Core invokes ServiceFactory → creates AssemblyScanner with attached IScanRule objects.
4. ModScanner enumerates mod assemblies (DLLs) to scan.
5. For each mod:
- AssemblyScanner loads assembly via Mono.Cecil.
- Iterates through available IScanRule rules (from Models/).
- Each rule’s IsSuspicious(methodRef) inspects IL patterns.
- If suspicious, generate a ScanFinding.
6. ModDisabler receives findings → decides to disable mod if severity ≥ threshold or not whitelisted.
7. Reporting Engine writes report file & logs.
8. Security guidance output to user console via Core or logger.

c. Architectural patterns / principles
- Factory pattern (ServiceFactory creates scanner with pluggable rules)
- Strategy pattern (each IScanRule is a strategy for detection)
- Modular design: rules can be added without core changes
- Separation of concerns: config loading, scanning, rule definition, disabling, and reporting are distinct services

d. Relevant technologies / libraries
- .NET 6+ / C#
- MelonLoader plugin framework
- Mono.Cecil for static assembly analysis
- MelonPreferences for config (MelonPreferences.cfg)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Plugin Host
    subgraph "Plugin Host"
        ML["MelonLoader"]:::external
    end

    %% Core Module
    subgraph "Core Module"
        Core["Core Module"]:::core
    end

    ML -->|"Invoke Initialize"| Core

    %% Configuration
    subgraph "Configuration"
        ConfigFile["MelonPreferences.cfg"]:::config
    end
    Core --> Config["ConfigManager"]:::core
    ConfigFile -.-> Config

    %% Services
    subgraph "Services"
        Factory["ServiceFactory"]:::core
        AssemblyScan["AssemblyScanner"]:::core
        ModScan["ModScanner"]:::core
        Disabler["ModDisabler"]:::core
        Reporting["Reporting Engine"]:::core
    end

    Config --> Factory
    Factory --> AssemblyScan
    ModScan -->|"Enumerate DLLs"| AssemblyScan
    Core --> ModScan
    AssemblyScan --> Disabler
    AssemblyScan --> Reporting

    %% Detection Rules
    subgraph "Detection Rules"
        IScan["IScanRule Interface"]:::models
        BR["Base64Rule"]:::models
        BAM["ByteArrayManipulationRule"]:::models
        DImport["DllImportRule"]:::models
        LFS["LoadFromStreamRule"]:::models
        PSR["ProcessStartRule"]:::models
        RegR["RegistryRule"]:::models
        ShellR["Shell32Rule"]:::models
    end

    AssemblyScan --- IScan
    IScan --> BR
    IScan --> BAM
    IScan --> DImport
    IScan --> LFS
    IScan --> PSR
    IScan --> RegR
    IScan --> ShellR

    %% Models
    ScanConfig["ScanConfig Model"]:::models
    ScanFinding["ScanFinding Model"]:::models
    Config --> ScanConfig
    AssemblyScan --> ScanFinding
    ScanFinding --> Disabler
    ScanFinding --> Reporting

    %% External Dependencies
    subgraph "External"
        Mono["Mono.Cecil"]:::external
    end
    AssemblyScan -->|"Uses"| Mono

    %% Project Artifacts
    subgraph "Repository"
        Proj["MLVScan.csproj"]:::docs
        Sol["MLVScan.sln"]:::docs
        Readme["README.md"]:::docs
        License["LICENSE"]:::docs
    end

    %% Click Events
    click Core "https://github.com/ifbars/mlvscan/blob/master/Core.cs"
    click Config "https://github.com/ifbars/mlvscan/blob/master/Services/ConfigManager.cs"
    click Factory "https://github.com/ifbars/mlvscan/blob/master/Services/ServiceFactory.cs"
    click AssemblyScan "https://github.com/ifbars/mlvscan/blob/master/Services/AssemblyScanner.cs"
    click ModScan "https://github.com/ifbars/mlvscan/blob/master/Services/ModScanner.cs"
    click Disabler "https://github.com/ifbars/mlvscan/blob/master/Services/ModDisabler.cs"
    click IScan "https://github.com/ifbars/mlvscan/blob/master/Models/IScanRule.cs"
    click BR "https://github.com/ifbars/mlvscan/blob/master/Models/Base64Rule.cs"
    click BAM "https://github.com/ifbars/mlvscan/blob/master/Models/ByteArrayManipulationRule.cs"
    click DImport "https://github.com/ifbars/mlvscan/blob/master/Models/DllImportRule.cs"
    click LFS "https://github.com/ifbars/mlvscan/blob/master/Models/LoadFromStreamRule.cs"
    click PSR "https://github.com/ifbars/mlvscan/blob/master/Models/ProcessStartRule.cs"
    click RegR "https://github.com/ifbars/mlvscan/blob/master/Models/RegistryRule.cs"
    click ShellR "https://github.com/ifbars/mlvscan/blob/master/Models/Shell32Rule.cs"
    click ScanConfig "https://github.com/ifbars/mlvscan/blob/master/Models/ScanConfig.cs"
    click ScanFinding "https://github.com/ifbars/mlvscan/blob/master/Models/ScanFinding.cs"
    click Proj "https://github.com/ifbars/mlvscan/blob/master/MLVScan.csproj"
    click Sol "https://github.com/ifbars/mlvscan/blob/master/MLVScan.sln"
    click Readme "https://github.com/ifbars/mlvscan/blob/master/README.md"
    click License "https://github.com/ifbars/mlvscan/tree/master/LICENSE"

    %% Styles
    classDef core fill:#add8e6,stroke:#000,stroke-width:1px
    classDef models fill:#90ee90,stroke:#000,stroke-width:1px
    classDef external fill:#ffa500,stroke:#000,stroke-width:1px
    classDef docs fill:#eeeeee,stroke:#000,stroke-width:1px
    classDef config fill:#f9f,stroke:#000,stroke-width:1px,stroke-dasharray: 5 5
```
