VirusTotal / yara-python

The Python interface for YARA
http://virustotal.github.io/yara/
Apache License 2.0
637 stars 178 forks source link

Adding Ruleset statistics at compile time #227

Closed Derekt2 closed 1 year ago

Derekt2 commented 1 year ago

This adds YARA statistics to this python library. Addresses: https://github.com/VirusTotal/yara-python/issues/224

After a ruleset is compiled, a new method may be called .stats() as follows:

import yara

rule = yara.compile(
    source=(
        'rule foo: bar {strings: $a = "dsfsd" condition: $a} rule foo1: bar {strings:'
        ' $a = "dsfsd" condition: $a}'
    )
)
matches = rule.match(data="abcdefgjiklmnoprstuvwxyz")
print(rule.stats())

which produces output: {'num_rules': 2, 'num_strings': 2, 'ac_matches': 2, 'ac_tables_size': 512} exactly as if you used the YARA command line flag --print-stats

I verified the code works locally, but apologies if I missed styling or best practices as this is my first stab at C.

google-cla[bot] commented 1 year ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.