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
ParserDriverclass declared in the header fileparser_driver.hand defined in source fileparser_driver.cpp. The parser is based on POG and its grammar and tokens are defined in methodsdefineTokensanddefineGrammarof theParserDriverclass. 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
YaraExpressionBuildercreates expressions so that YARA rules conditions can be created. TheYaraHexStringBuilderis a tool for easy creation of hexadecimal strings. TheYaraRuleBuilderhelps to create YARA rules and theYaraFileBuilderis 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
TokenStreamdefined in filetokenstream.h. EachYaraFileinstance holds aTokenStreaminstance in which all Tokens that theYaraFilerefers to are stored. TheTokenStream::getTextmethod prints the tokens formatted in the desired format. TheYaraFile::getTextFormattedmethod simply calls thegetTextmethod of the TokenStream that it owns. Please see wiki page for more on formatting.- YARA rules modifying visitor
The class
ModifyingVisitoris 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.