Skip to content

Antimalware scanners

Christian Haase edited this page Dec 2, 2025 · 1 revision

ByteGuard.FileValidator supports integration to various antimalware scanners. This allows the file validator to send the contents of the file to the configured antimalware scanner before saving the file to disk, database, or other storage device. A curated list of available scanners is listed here on the wiki.

Setup

Antimalware scanners are completely optional, as it's up to you to integrate the antimalware scanner with the file validator. The file validator has a constructor that takes both the configuration and the antimalware scanner as arguments. The configuration of the antimalware scanner is dependent on the specific implementation. This example uses the Microsoft Antimalware Scan Interface (AMSI) scanner implementation.

var amsiConfiguration = new AmsiScannerConfiguration()
{
    ApplicationName = "MyApplication"
};

var amsiScanner = new AmsiAntimalwareScanner(configuration);

var validator = new FileValidator(/* file validator configuration */, amsiScanner);

Usage

With an antimalware scanner implemented, the function IsValidFile() automatically scans the file with the given scanner. Furthermore, you have the option to only check whether the file is malware clean by using any of the function IsMalwareClean().

var validator = new FileValidator(/* file validator configuration */, amsiScanner);

var isValid = validator.IsValidFile(fileName, fileStream);
var isClean = validator.IsMalwareClean(fileName, fileStream);

If no antimalware scanner has been configured and added, the functions IsValidFile() will not perform an antimalware check, and the functions IsMalwareClean will throw an InvalidOpenrationException as IsMalwareClean() expects an antimalware scanner to be configured to the file validator.

Clone this wiki locally