-
Notifications
You must be signed in to change notification settings - Fork 569
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
add flavored scopes #1580
add flavored scopes #1580
Conversation
Currently, the scope member of each Rule object is a Flavor object, and I think that class name (Flavor) is pretty confusing and should be renamed. Ideally, we would rename that class to Scope, but that's already taken. So I suggest that we either rename the current Scope enum class (maybe to ScopeEnum ?), or we rename Flavor to RuleScope. What are your thoughts on that? and do you have any other suggestions? |
first: the description text for this PR is really good! i appreciate the summary of the background, the example of the rule, and what this means for users. really nice job. |
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.
nice start to the changes to the rule syntax. i've made some comments inline, though im not sure whether or not they'll be easy to understand. so, i'll try to summarize them here, and don't hesitate to reach out with more questions.
-
only support the case when both static & dynamic scopes are provided. make any other case an error (for now). if we want to add special handling, lets do that later when we know the easy case works well.
-
update rule syntax to have
meta.scopes
instead ofmeta.scope
. the type of this thing should beScopes
, which replaces yourFlavor
class (but looks approximately the same). this way we don't have to use the term "flavor" very much/at all :-). because each rule should have multiple scope entries, it makes sense for the field name to be plural. then, when we say "scope" we mean a single scope, likefunction
, and when we say "scopes" we mean the mapping from flavor to scope, like{static: function, dynamic: thread}
. -
try to work with single scopes (
Scope
, singular) wherever possible. if a function accepts aScopes
(plural) argument, then its return value should be a mapping (like aDict
) from flavor to some result. for example, if you want a functionensure_feature_valid_for_scopes
(Scopes
, plural), then the result should indicate if the given feature is valid for each provided scope. but i think this should be uncommon, and you should prefer the singular when possible. this is because our matching engine won't be mixing rule logic across flavors, so i think its unlikely that we'll want to mix any data structure or logic across flavors. -
therefore, if we need to build different rule logic trees, one for each flavor, that's fine. this might take a bit of work - feel free to propose a design or start a discussion if you have questions.
the tests look great, so if those can continue passing while we address the above, we'll know things will be ready to merge.
Co-authored-by: Willi Ballenthin (Google) <[email protected]>
I have xfailed all the tests that rely on old rules (has |
@yelhamer can you work on the merge conflicts? |
sure, will do. |
for these, update here: Lines 51 to 61 in c1cd272
|
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.
lgtm
@yelhamer please resolve conflicts and then i'll merge |
2532766
to
4ee38cb
Compare
looks like there's still conflicts, happy to merge after those are resolved |
06f5ed1
to
4ee38cb
Compare
sorry if these are unrelated issues to this PR :( |
ah no it's my fault. I switched mid-way through from using the '==' operator to using the 'in' one, but forgot to update the ida plugin again with that. |
@mr-tz checks passed, and should be ready to merge! |
great work! |
🥳 |
This PR proposes an implementation for the concept of flavors (as discussed in #1517 ).
In this PR, each rule is assumed to have two different interpretations depending on what type of extractor it is matching against (Dynamic or Static). If the extractor is static, it will be looking to match against static scopes and will thus fetch the static interpretation of the rule form the RuleSet class, and if it is a dynamic extractor, it will do the same by fetching the dynamic interpretation. A rule may lack one interpretation/flavor at most (either a static scope or a dynamic one must be specified).
One advantage of this design is we can have rules written for one analysis mode (static for example) be used in a dynamic analysis context. For example the following rule:
In this case, if the rule is being matched against features extracted by a dynamic extractor then the
API(socket)
feature would still match, and thereby the whole rule would still match and it won't be lost.Disadvantages of this approach is the the
Flavor
class feels like a hack. I feel like it could be nice if we could rename that class intoScope
, and find another way to represent theScope
enum class.Checklist