Files
Moonlight/Moonlight/App/Services/MalwareScanService.cs

49 lines
1.4 KiB
C#

using Moonlight.App.Database.Entities;
using Moonlight.App.MalwareScans;
using Moonlight.App.Models.Misc;
using Moonlight.App.Services.Plugins;
namespace Moonlight.App.Services;
public class MalwareScanService //TODO: Make this moddable using plugins
{
private readonly PluginService PluginService;
private readonly IServiceScopeFactory ServiceScopeFactory;
public MalwareScanService(PluginService pluginService, IServiceScopeFactory serviceScopeFactory)
{
PluginService = pluginService;
ServiceScopeFactory = serviceScopeFactory;
}
public async Task<MalwareScanResult[]> Perform(Server server)
{
var defaultScans = new List<MalwareScan>
{
new SelfBotScan(),
new MinerJarScan(),
new SelfBotCodeScan(),
new FakePlayerPluginScan()
};
var scans = await PluginService.BuildMalwareScans(defaultScans.ToArray());
var results = new List<MalwareScanResult>();
using var scope = ServiceScopeFactory.CreateScope();
foreach (var scan in scans)
{
var result = await scan.Scan(server, scope.ServiceProvider);
if (result.Any())
{
foreach (var scanResult in result)
{
results.Add(scanResult);
}
}
}
return results.ToArray();
}
}