Development¶
Architecture¶
Yaramod is a C++ library with Python bindings capable of parsing, building, formatting and also modifying YARA rules; hence the main four parts of Yaramod are:
- Parser of YARA rules
The main parser class is the
ParserDriver
class declared in the header fileparser_driver.h
and defined in source fileparser_driver.cpp
. The parser is based on POG and its grammar and tokens are defined in methodsdefineTokens
anddefineGrammar
of theParserDriver
class. Detailed wiki page on how to use yaramod to parse YARA rules can be found in this section.- Builder of YARA rules
The builder machinery is declared within the builder folder. The
YaraExpressionBuilder
creates expressions so that YARA rules conditions can be created. TheYaraHexStringBuilder
is a tool for easy creation of hexadecimal strings. TheYaraRuleBuilder
helps to create YARA rules and theYaraFileBuilder
is there to construct YARA files from rules and module imports. More on the construction of YARA files is written here.- YARA rules formatting
The main component taking care of proper formatting of YARA files is the
TokenStream
defined in filetokenstream.h
. EachYaraFile
instance holds aTokenStream
instance in which all Tokens that theYaraFile
refers to are stored. TheTokenStream::getText
method prints the tokens formatted in the desired format. TheYaraFile::getTextFormatted
method simply calls thegetText
method of the TokenStream that it owns. Please see wiki page for more on formatting.- YARA rules modifying visitor
The class
ModifyingVisitor
is defined in modifying_visitor.h and serves as the base class for our custom visitors designed to modify specific parts of visited conditions. See section Modifying Rulesets for more information and examples.
Run it locally¶
See Installation section.