-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow iterating over compiled ruleset before scanning #136
Conversation
The YR_RULES type is opaque since 43d0be1 It was made opaque mostly for codegen size reasons, so we can totally decide to expand it once again. This would give access to the rules_table field, which would be imho preferred, as it avoids adding C code for the bindings. |
I am not a big fan of adding a mandatory dependence to cc. Is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll have to include the generated binding files (look at the bindings Github action).
I will probably rename Rule to MatchingRule later (with a deprecation period for Rule).
@Hugal31 could you please release a new version that includes this change? |
This PR fixes #135. It includes an updated
tutorial.rs
showcasing how to iterate over the compiled ruleset and disabling certain rules. This feature is crucial for implementing custom rule filters in client-side applications.Please let me know any feedback and thanks for creating these bindings!
Implementation details
On the new get_rules.c file
The approach taken by existing iterators such as
TagIterator
is difficult to apply, because the rules_table is not properly exposed via bindgen. We just have a binary blob to work with:Therefore, I created a new file
get_rules.c
which uses theyr_rules_foreach
macro to retrieve the rules from the ruleset. This is inspired by the Go bindings.Since we need to compile this file in any case, the
cc
build-dependency is now mandatory, hence the changes in theCargo.toml
andbuild.rs
.On the new RulesetRule struct
The existing
Rule
struct represents a rule that matched during a scan. It would have involved some more refactoring to lift this assumption. I went with the less invasive change here and created a newRulesetRule
struct.