Giter Site home page Giter Site logo

xnetdude / libyara.net Goto Github PK

View Code? Open in Web Editor NEW

This project forked from microsoft/libyara.net

0.0 0.0 0.0 59 KB

.NET wrapper for libyara built in C++ CLI used to easily incorporate yara into .NET projects

License: BSD 3-Clause "New" or "Revised" License

C# 26.75% C++ 72.14% YARA 1.11%

libyara.net's Introduction

libyara.NET

A .NET wrapper for libyara that provides a simplified API for developing tools in C# and PowerShell. This library targets .NET 4.6.

This library is built against the Microsoft.O365.Security.Native.Libyara package which is based on VirusTotal's yara built with vcpkg. This library is currently based on yara 4.0.2 per the vcpkg port. We will update yara version to include the latest features and bug fixes if necessary.

This library is avaiable in forms of two NuGet packages, depending on your project types:

For .NET framework projects, x86 and x64 binary versions are available on NuGet with the package id Microsoft.O365.Security.Native.libyara.NET. The public key token of official binaries is 31bf3856ad364e35. Projects that use libyara.NET should use 'All CPU' or 'x86' as the platform name to select the x86 binaries and use 'x64' to select the x64 binaries.

For .NET Core projects, only x64 binary version is avaiable on NuGet with the package id Microsoft.O365.Security.Native.libyara.NET.Core. The public key token of official binaries is 31bf3856ad364e35. Projects that use libyara.NET should use 'x64' as the platform name to use this NuGet package.

Quick Start

static void Main(string[] args)
{
    // Use the QuickScan class when you don't need to reuse rules
    // or other yara objects. QuickScan handles all of the resource
    // management including the YaraContext.

    // var results = QuickScan.File(".\\SampleFile.txt", ".\\HelloWorldRules.yara");

    // When you need to reuse yara objects (e.g. when scanning multiple files) it's
    // more efficient to use the pattern below. Note that all yara operations must
    // take place within the scope of a YaraContext.
    using (var ctx = new YaraContext())
    {
        Rules rules = null;

        try
        {
            // Rules and Compiler objects must be disposed.
            using (var compiler = new Compiler())
            {
                compiler.AddRuleFile(".\\HelloWorldRules.yara");
                rules = compiler.GetRules();
            }

            // Scanner and ScanResults do not need to be disposed.
            var scanner = new Scanner();
            var results = scanner.ScanFile(".\\SampleFile.txt", rules);
        }
        finally
        {
            // Rules and Compiler objects must be disposed.
            if (rules != null) rules.Dispose();
        }
    }
}

Reference

See the libyara C API documentation for a general overview on how to use libyara. This API is adapted to present an API that is more consistent with .NET so usage differs slightly, but the core concepts remain the same.

TODO: API Reference

Limitations

  • Rule metadata not supported
  • Modules are not currently supported
  • Scan results are collected and returned (as compared with the callback approach normally used) which may result in high memory use with rules that match many items.

libyara.net's People

Contributors

kylereedmsft avatar swannman avatar kallanreed avatar themobiusstrip avatar

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.