Giter Club home page Giter Club logo

rmuch / clamav.managed Goto Github PK

View Code? Open in Web Editor NEW
19.0 3.0 8.0 167 KB

ClamAV bindings for the .NET Framework, Mono and PowerShell. ClamAV.Managed is a library written in C# for the .NET Framework and Mono, providing managed bindings for the libclamav interface. It includes ClamAV.Managed.PowerShell, a set of PowerShell cmdlets for ClamAV scanning. It comes with sample code for building a GUI virus scanner application.

License: GNU General Public License v2.0

C# 96.00% PowerShell 3.65% Batchfile 0.09% F# 0.26%
clamav clamav-scanning clamav-binding clamav-wrapper antivirus c-sharp libclamav mono

clamav.managed's Introduction

Managed Bindings for ClamAV

Introduction

ClamAV.Managed is a library written in C# for the .NET Framework and Mono, providing managed bindings for libclamav. It includes ClamAV.Managed.PowerShell, a set of PowerShell cmdlets for ClamAV scanning. It also comes with GUI sample code for performing virus scanning.

Prerequisites

To use ClamAV.Managed, P/Invoke must be able to locate libclamav, either in your binary's execution directory or at some location in your system's library search path.

You can obtain ClamAV binaries compiled for Windows at http://oss.netfarm.it/clamav/. It is recommended to use a version of libclamav compiled with Microsoft Visual C++.

ClamAV.Managed is designed to be platform-agnostic with the intention of supporting Mono on Linux and Mac OS X. Although this is currently not a widely used combination, users are encouraged to try the software on these platforms to help find any possible issues that may arise.

For file scanning to work, you need to download ClamAV databases from http://www.clamav.net. Databases can be loaded from an arbitrary directory by specifying a path in the ClamEngine.LoadDatabase method, or from a folder in your application's working directory. This folder may be named db or database, depending on which build of libclamav you are running.

Getting Started

ClamAV.Managed Library

To get started using ClamAV.Managed in your project, you need to add a reference to ClamAV.Managed.dll.

libclamav must be either in your application's binary directory, or some other system path where it may be discovered. It is recommended that you bundle libclamav with your application, taking care to comply with the terms of the GNU General Public License, version 2.

You need to obtain ClamAV databases. By default, ClamAV looks for databases in a folder called db in the current working directory. Depending on the version of ClamAV, this directory may be called database instead. You can specify an arbitrary location from which to load virus databases as an argument to the ClamEngine.LoadDatabase method.

It is recommended to use the freshclam utility to obtain the latest ClamAV databases, but you can also try the FetchDatabases.ps1 PowerShell script in the scripts directory and adapt it to your own purposes, remembering to select which databases you would like to obtain and changing the download URL to a local mirror.

You can find a list of ClamAV database mirrors at http://www.clamav.net/mirrors.html. Databases will be named main.cvd, daily.cvd, bytecode.cvd, safebrowsing.cvd in the root directory of the mirror. More information about obtaining ClamAV databases can be found on the ClamAV website.

ClamAV.Managed.Async Task-based Asynchronous Scanning

ClamAV.Managed provides a task-based asynchronous API using the new async/await feature for .NET 4.5.1 in the ClamAV.Managed.Async project.

These extensions are still experimental, and you may encounter issues while performing parallel scans, particularly with a large quantity of long-running scan tasks.

ClamAV.Managed.Async is implemented as extension methods and can be used by adding a reference to the library from your project.

ClamAV.Managed.PowerShell Cmdlets

To use the cmdlets provided by ClamAV.Managed.PowerShell, use the New-ClamEngine cmdlet.

  1. Use Import-Module to load the ClamAV.Managed.PowerShell library. Assume we have created a directory C:\ClamAV-Managed, containing ClamAV.Managed.dll, ClamAV.Managed.PowerShell.dll, ClamAV.Managed.PowerShell.psd1, libclamav.dll and a subdirectory containing definitions datases called db. We're now ready to proceed. Import-Module C:\ClamAV-Managed\ClamAV.Managed.PowerShell.psd1
  2. Create an instance of the ClamAV engine. $eng = New-ClamEngine -WithDatabase C:\ClamAV-Managed\db
  3. If you didn't provide a -WithDatabase parameter to New-ClamEngine, use Import-ClamDatabase to load a definitions database. Import-ClamDatabase -Engine $eng -Path C:\ClamAV-Managed\db
  4. To scan a file: Invoke-ClamScanFile -Engine $eng -Path C:\File.exe
  5. To scan a directory: Invoke-ClamScanDirectory -Engine $eng -Path C:\Directory\

Import-ClamDatabase will, by default, look for databases in libclamav's default subdirectory, probably db or perhaps database, within the directory containing the ClamAV.Managed.PowerShell dynamic library. However, you may specify a path manually with the -DatabasePath parameter.

Samples

Refer to the project ClamAV.Managed.Samples.Gui to see an example of ClamAV.Managed in action. To run the sample, you need to obtain libclamav, as described above, and download virus databases to a folder named db in the binary directory.

ClamAV.Managed.Samples.AsyncGui provides a sample with a user interface implemented using Windows Presentation Foundation (WPF).

License Information

This project is licensed under the terms of the GNU General Public License, version 2. You can find a full copy of the license text in GPLv2.txt.

Disclaimer

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

While the public version of this library is still in early development, the type names and class interfaces are subject to change.

clamav.managed's People

Contributors

rmuch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

clamav.managed's Issues

Test with .NET Core

.NET Core supports P/Invoke, so, in theory, everything should work fine. It should be tested and .NET Core-compatible builds should be ensured before .NET Core can be added to the compatibility matrix.

ClamAV.Managed.Samples.Gui

I will use ClamAV.Managed.Samples.Gui is a startup project and is linked with libclamav + its db. when I run this sample it will crash the program at clamengine.cs line 292 having method 'ScanFile'. I have spent more than 3 days and couldn't get the solution. I have attached the screenshots of errors that show at console/output, runtime crash as well the line of clamengine.cs line 292. One more thing is ClamAV.Managed can scan files whose content is up to less than equal to (=<5 ).
ClamAV-Managed.pdf

Upgrade to .NET Standard 2.0

Upgrade ClamAV.Managed and ClamAV.Managed.Async to .NET Standard 2.0 the SDK-style (.NET Core) project format.

This could possibly be accomplished using automated tooling.

This may also necessitate upgrading other dependent projects to at least .NET 4.6.1, because earlier versions are not supported by .NET Standard, as per the documentation here.

Since the original issue (#8) was created, the .NET ecosystem has come a long way. This issue supersedes the previous one.

This will not be merged until after the 0.4.0.0 release, which will be the final release using the legacy .NET Framework.

Asynchronous wrappers for ScanFile, etc.

Implement asynchronous file and directory scanning.

Asynchronous scanning using the async/await pattern new in .NET 4.5 would probably be the easiest to implement. However, this would require upgrading the solution projects to .NET 4.5, which might be a problem for those who wish to target earlier framework versions.

A good first step would be to provide asynchronous methods using the older Begin/End asynchronous programming model.

Distribution bundles

Currently, the plan is to use WiX to provide a Windows Installer package with the ability to select libraries, source code, documentation and PowerShell integration, primarily to facilitate automated deployment on servers.

As well as the WiX package, there will definitely be binary builds distributed in a ZIP archive.

ClamAV.Managed could also be distributed via NuGet, but the issue of how to provide ClamAV binary builds along with the managed libraries, especially to support Mac OS X and Linux, should be considered.

A ZIP archive distribution should be available for 0.2, and a Windows Installer package at a later version.

Upgrade to .NET Framework 4.8

As per the lifecycle documentation:

.NET Framework 4.5.2, 4.6, and 4.61 will retire on April 26, 2022. These specific releases were previously digitally signed using Secure Hash Algorithm (SHA-1) certificates. This algorithm is no longer deemed secure. Go here to learn more about this retirement. Customers are encouraged to move to SHA-2. Go here to learn about validating your application functionality on the newer runtime version.

Release 0.4.0.0 will be upgraded to .NET Framework 4.8, as the last release exclusively supporting .NET 4.x.

.NET Framework 4.8: Support for .NET 4.8 follows the Lifecycle Policy of the parent OS. It is supported as a Windows component on the latest required update for the operating systems below. We recommend customers upgrade to .NET Framework 4.8 to receive the highest level of performance, reliability, and security.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.