Skip to content

Commit

Permalink
Add support for text string sets. (VirusTotal#63)
Browse files Browse the repository at this point in the history
This adds support for text string sets (VirusTotal/yara#1787).
  • Loading branch information
wxsBSD authored Dec 29, 2022
1 parent a2dc104 commit 9343e33
Show file tree
Hide file tree
Showing 4 changed files with 436 additions and 356 deletions.
9 changes: 5 additions & 4 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,11 @@ type ForOf struct {
// If "In" is non-nil there is an "in" condition: 3 of them in (0..100)
// If "At" is non-nil there is an "at" condition: 1 of them at 0
type Of struct {
Quantifier Expression
Strings Node
Rules Node
In *Range
Quantifier Expression
Strings Node
Rules Node
TextStrings []string
In *Range
At Expression
}

Expand Down
38 changes: 38 additions & 0 deletions parser/grammar.y
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ type stringModifiers struct {
%type <node> rule_set
%type <exprs> rule_enumeration
%type <ident> rule_enumeration_item
%type <ss> text_string_set
%type <ss> text_string_enumeration
%type <s> text_string_enumeration_item


%union {
Expand Down Expand Up @@ -953,6 +956,13 @@ expression
Rules: $3,
}
}
| for_expression _OF_ text_string_set
{
$$ = &ast.Of{
Quantifier: $1,
TextStrings: $3,
}
}
| primary_expression '%' _OF_ string_set
{
$$ = &ast.Of{
Expand Down Expand Up @@ -1214,6 +1224,34 @@ rule_enumeration_item
;


text_string_set
: '(' text_string_enumeration ')'
{
$$ = $2
}
;


text_string_enumeration
: text_string_enumeration_item
{
$$ = []string{$1}
}
| text_string_enumeration ',' text_string_enumeration_item
{
$$ = append($1, $3)
}
;


text_string_enumeration_item
: _TEXT_STRING_
{
$$ = $1
}
;


for_expression
: primary_expression
{
Expand Down
Loading

0 comments on commit 9343e33

Please sign in to comment.