YaraSharp
1.0.0
C# wrapper รอบ ๆ ห้องสมุดการจับคู่รูปแบบ YARA
ใช้แบบฟอร์มลายเซ็น Loki หรือ Yara
มีแพ็คเกจ Nuget
// All API calls happens here
YSInstance YSInstance = new YSInstance ( ) ;
// Declare external variables (could be null)
Dictionary < string , object > externals = new Dictionary < string , object > ( )
{
{ "filename" , string . Empty } ,
{ "filepath" , string . Empty } ,
{ "extension" , string . Empty }
} ;
// Get list of YARA rules
List < string > ruleFilenames = Directory . GetFiles ( @"D:Testyara" , "*.yar" , SearchOption . AllDirectories ) . ToList ( ) ;
// Context is where yara is initialized
// From yr_initialize() to yr_finalize()
using ( YSContext context = new YSContext ( ) )
{
// Compiling rules
using ( YSCompiler compiler = instance . CompileFromFiles ( ruleFilenames , externals ) )
{
// Get compiled rules
YSRules rules = compiler . GetRules ( ) ;
// Get errors
YSReport errors = compiler . GetErrors ( ) ;
// Get warnings
YSReport warnings = compiler . GetWarnings ( ) ;
// Some file to test yara rules
string Filename = @"" ;
// Get matches
List < YSMatches > Matches = instance . ScanFile ( Filename , rules ,
new Dictionary < string , object > ( )
{
{ "filename" , Alphaleonis . Win32 . Filesystem . Path . GetFileName ( Filename ) } ,
{ "filepath" , Alphaleonis . Win32 . Filesystem . Path . GetFullPath ( Filename ) } ,
{ "extension" , Alphaleonis . Win32 . Filesystem . Path . GetExtension ( Filename ) }
} ,
0 ) ;
// Iterate over matches
foreach ( YSMatches Match in Matches )
{
//...
}
}
// Log errors
}สำหรับการใช้สแกนแบบ async ต้อง เรียกวิธีการทำลาย:
YaraSharp . CYaraSharp YSInstance = new CYaraSharp ( ) ;
YaraSharp . CContext YSContext = new YaraSharp . CContext ( ) ;
YaraSharp . CRules YSRules = YSInstance . CompileFromFiles ( RuleFilenames , null , out Errors ) ;
// Async here
YSRules . Destroy ( ) ;
YSContext . Destroy ( ) ; LIBYARA C API Documentation สำหรับภาพรวมทั่วไปเกี่ยวกับวิธีการใช้ LIBYARA
Soultion มี 2 โครงการ:
สร้างใน VS 2017
รวบรวมด้วย Yara 3.8.1
Yara ติดตั้งเพื่อรองรับเส้นทาง Unicode
คุณสามารถใช้หรือแก้ไขแหล่งที่มาตามที่คุณต้องการ
ขอขอบคุณเป็นพิเศษสำหรับ Kallanreed