mirror of
https://github.com/volodymyrsmirnov/MalwareMultiScan.git
synced 2025-10-10 20:26:16 +00:00
refactoring, documentation pending
This commit is contained in:
@@ -18,15 +18,12 @@ namespace MalwareMultiScan.Backends.Backends.Abstracts
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
protected virtual Regex MatchRegex { get; }
|
||||
protected virtual string BackendPath { get; }
|
||||
protected abstract Regex MatchRegex { get; }
|
||||
protected abstract string BackendPath { get; }
|
||||
protected virtual bool ParseStdErr { get; }
|
||||
protected virtual bool ThrowOnNonZeroExitCode { get; } = true;
|
||||
|
||||
protected virtual string GetBackendArguments(string path)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
protected abstract string GetBackendArguments(string path);
|
||||
|
||||
public override async Task<string[]> ScanAsync(string path, CancellationToken cancellationToken)
|
||||
{
|
||||
|
@@ -3,23 +3,21 @@ using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MalwareMultiScan.Shared.Interfaces;
|
||||
using MalwareMultiScan.Backends.Interfaces;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace MalwareMultiScan.Backends.Backends.Abstracts
|
||||
{
|
||||
public abstract class AbstractScanBackend : IScanBackend
|
||||
{
|
||||
public virtual string Id => throw new NotImplementedException();
|
||||
public abstract string Id { get; }
|
||||
|
||||
public virtual Task<string[]> ScanAsync(string path, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public abstract Task<string[]> ScanAsync(string path, CancellationToken cancellationToken);
|
||||
|
||||
public async Task<string[]> ScanAsync(Uri uri, CancellationToken cancellationToken)
|
||||
{
|
||||
using var httpClient = new HttpClient();
|
||||
|
||||
await using var uriStream = await httpClient.GetStreamAsync(uri);
|
||||
|
||||
return await ScanAsync(uriStream, cancellationToken);
|
||||
|
@@ -1,5 +1,3 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using MalwareMultiScan.Backends.Backends.Abstracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
@@ -2,7 +2,7 @@ using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MalwareMultiScan.Shared.Interfaces;
|
||||
using MalwareMultiScan.Backends.Interfaces;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace MalwareMultiScan.Backends.Backends.Implementations
|
||||
|
14
MalwareMultiScan.Backends/Enums/BackendType.cs
Normal file
14
MalwareMultiScan.Backends/Enums/BackendType.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace MalwareMultiScan.Backends.Enums
|
||||
{
|
||||
public enum BackendType
|
||||
{
|
||||
Dummy,
|
||||
Defender,
|
||||
Clamav,
|
||||
DrWeb,
|
||||
Kes,
|
||||
Comodo,
|
||||
Sophos,
|
||||
McAfee
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using MalwareMultiScan.Backends.Backends.Implementations;
|
||||
using MalwareMultiScan.Backends.Enums;
|
||||
using MalwareMultiScan.Backends.Interfaces;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace MalwareMultiScan.Backends.Extensions
|
||||
{
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
public static void AddScanningBackend(this IServiceCollection services, BackendType type)
|
||||
{
|
||||
using var provider = services.BuildServiceProvider();
|
||||
|
||||
var logger = provider.GetService<ILogger<IScanBackend>>();
|
||||
|
||||
services.AddSingleton<IScanBackend>(type switch
|
||||
{
|
||||
BackendType.Dummy => new DummyScanBackend(),
|
||||
BackendType.Defender => new WindowsDefenderScanBackend(logger),
|
||||
BackendType.Clamav => new ClamavScanBackend(logger),
|
||||
BackendType.DrWeb => new DrWebScanBackend(logger),
|
||||
BackendType.Kes => new KesScanBackend(logger),
|
||||
BackendType.Comodo => new ComodoScanBackend(logger),
|
||||
BackendType.Sophos => new SophosScanBackend(logger),
|
||||
BackendType.McAfee => new McAfeeScanBackend(logger),
|
||||
_ => throw new NotImplementedException()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
18
MalwareMultiScan.Backends/Interfaces/IScanBackend.cs
Normal file
18
MalwareMultiScan.Backends/Interfaces/IScanBackend.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace MalwareMultiScan.Backends.Interfaces
|
||||
{
|
||||
public interface IScanBackend
|
||||
{
|
||||
public string Id { get; }
|
||||
|
||||
public Task<string[]> ScanAsync(string path, CancellationToken cancellationToken);
|
||||
public Task<string[]> ScanAsync(Uri uri, CancellationToken cancellationToken);
|
||||
public Task<string[]> ScanAsync(IFormFile file, CancellationToken cancellationToken);
|
||||
public Task<string[]> ScanAsync(Stream stream, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
@@ -8,4 +8,8 @@
|
||||
<ProjectReference Include="..\MalwareMultiScan.Shared\MalwareMultiScan.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.9" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
11
MalwareMultiScan.Backends/Messages/ScanRequestMessage.cs
Normal file
11
MalwareMultiScan.Backends/Messages/ScanRequestMessage.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace MalwareMultiScan.Backends.Messages
|
||||
{
|
||||
public class ScanRequestMessage
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
public Uri Uri { get; set; }
|
||||
}
|
||||
}
|
9
MalwareMultiScan.Backends/Messages/ScanResultMessage.cs
Normal file
9
MalwareMultiScan.Backends/Messages/ScanResultMessage.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace MalwareMultiScan.Backends.Messages
|
||||
{
|
||||
public class ScanResultMessage
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Backend { get; set; }
|
||||
public string[] Threats { get; set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user