mirror of
https://github.com/volodymyrsmirnov/MalwareMultiScan.git
synced 2025-08-25 14:01:13 +00:00
refactoring and adding clamav scanning backend
This commit is contained in:
@@ -12,7 +12,12 @@ namespace MalwareMultiScan.Backends.Backends.Abstracts
|
||||
public abstract class AbstractLocalProcessScanBackend : AbstractScanBackend
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
|
||||
protected AbstractLocalProcessScanBackend(ILogger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
protected virtual Regex MatchRegex { get; }
|
||||
protected virtual string BackendPath { get; }
|
||||
protected virtual bool ParseStdErr { get; }
|
||||
@@ -22,11 +27,6 @@ namespace MalwareMultiScan.Backends.Backends.Abstracts
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected AbstractLocalProcessScanBackend(ILogger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public override async Task<string[]> ScanAsync(string path, CancellationToken cancellationToken)
|
||||
{
|
||||
var process = new Process
|
||||
@@ -38,12 +38,12 @@ namespace MalwareMultiScan.Backends.Backends.Abstracts
|
||||
WorkingDirectory = Path.GetDirectoryName(BackendPath) ?? Directory.GetCurrentDirectory()
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
_logger.LogInformation(
|
||||
$"Starting process {process.StartInfo.FileName} " +
|
||||
$"with arguments {process.StartInfo.Arguments} " +
|
||||
$"in working directory {process.StartInfo.WorkingDirectory}");
|
||||
|
||||
|
||||
process.Start();
|
||||
|
||||
cancellationToken.Register(() =>
|
||||
@@ -51,14 +51,14 @@ namespace MalwareMultiScan.Backends.Backends.Abstracts
|
||||
if (!process.HasExited)
|
||||
process.Kill(true);
|
||||
});
|
||||
|
||||
|
||||
process.WaitForExit();
|
||||
|
||||
_logger.LogInformation($"Process has exited with code {process.ExitCode}");
|
||||
|
||||
var standardOutput = await process.StandardOutput.ReadToEndAsync();
|
||||
var standardError = await process.StandardError.ReadToEndAsync();
|
||||
|
||||
|
||||
_logger.LogDebug($"Process standard output: {standardOutput}");
|
||||
_logger.LogDebug($"Process standard error: {standardError}");
|
||||
|
||||
|
Reference in New Issue
Block a user