Add convenience method for YaraScanner#1859
Add convenience method for YaraScanner#1859JSCU-CNI wants to merge 2 commits intovolatilityfoundation:developfrom
Conversation
ikelos
left a comment
There was a problem hiding this comment.
This seems fairly innocuous, but to avoid code duplication, I'd probably make use of it whenever text is being compiled into a pattern, so use it in get_rule as well. You'd need to check if there's a subtle difference in output between yara.compile(source=...) and yara.compile(sources=...) but I don't think that should be too catastrophic for people to cope with.
|
|
||
| @classmethod | ||
| def from_text(cls, rule): | ||
| formatted_rule = rule.replace("\n", "") |
There was a problem hiding this comment.
Why are we stripping all new line characters, and is there any situation in which that could change the meaning of the rule?
There was a problem hiding this comment.
It also feels like get_rule could be modified to call this after wrapping its parameter into simple rule text?
There was a problem hiding this comment.
New line stripping: good point! The docs of yara-python contains an example with a single line rule hence I replaced the newlines. I tested it with ~20 rules, and the newline can be included without any problems. I removed the replace line of code.
The source vs sources thing: the main difference is the namespacing. Theoretically we could check whether the given rule is a string or a dict and use source and sources accordingly. Don't prefer that though because of it's implicitness. The function name from_text is also clear in that it requires text, and not a dict.
The get_rule currently uses namespaces while from_text does not. I don't think it'd be wise to change it to use from_text because that would result in a backwards incompatible change. What do you think?
There was a problem hiding this comment.
Yeah, fair enough. Looks good then, thanks! 5:)
|
Oh, |
|
Also, the type hinting uses |
This convenience method makes it easier to use the YaraScanner with a Python defined YARA rule. This makes one off, single file plugins easier to make because one can include the YARA rule directly in Python instead of having to include the rule in a separate YARA file. I.e.: