How ifbars/mlvscan works
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)