2018-02-12 20:11:54 +01:00
import json
try :
import yara
2018-09-07 18:06:01 +02:00
except ( OSError , ImportError ) :
2018-11-12 16:22:14 +01:00
print ( " yara is missing, use ' pip3 install -I -r REQUIREMENTS ' from the root of this repository to install it. " )
2018-02-12 20:11:54 +01:00
misperrors = { ' error ' : ' Error ' }
mispattributes = { ' input ' : [ ' yara ' ] , ' output ' : [ ' text ' ] }
moduleinfo = { ' version ' : ' 0.1 ' , ' author ' : ' Dennis Rand ' , ' description ' : ' An expansion hover module to perform a syntax check on if yara rules are valid or not. ' , ' module-type ' : [ ' hover ' ] }
moduleconfig = [ ]
def handler ( q = False ) :
if q is False :
return False
request = json . loads ( q )
if not request . get ( ' yara ' ) :
misperrors [ ' error ' ] = ' Yara rule missing '
return misperrors
try :
2018-12-11 15:29:09 +01:00
yara . compile ( source = request . get ( ' yara ' ) )
2018-02-12 20:11:54 +01:00
summary = ( " Syntax valid " )
except Exception as e :
summary = ( " Syntax error: " + str ( e ) )
r = { ' results ' : [ { ' types ' : mispattributes [ ' output ' ] , ' values ' : summary } ] }
return r
def introspection ( ) :
return mispattributes
def version ( ) :
moduleinfo [ ' config ' ] = moduleconfig
return moduleinfo