Skip to content
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 Property Feature. #1116

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions capa/features/freeze/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def to_capa(self) -> capa.features.common.Feature:
elif isinstance(self, APIFeature):
return capa.features.insn.API(self.api, description=self.description)

elif isinstance(self, PropertyFeature):
return capa.features.insn.Property(self.property, description=self.description)

elif isinstance(self, NumberFeature):
return capa.features.insn.Number(self.number, description=self.description)

Expand Down Expand Up @@ -147,6 +150,9 @@ def feature_from_capa(f: capa.features.common.Feature) -> "Feature":
elif isinstance(f, capa.features.insn.API):
return APIFeature(api=f.value, description=f.description)

elif isinstance(f, capa.features.insn.Property):
return PropertyFeature(property=f.value, description=f.description)

elif isinstance(f, capa.features.insn.Number):
return NumberFeature(number=f.value, description=f.description)

Expand Down Expand Up @@ -266,6 +272,12 @@ class APIFeature(FeatureModel):
description: Optional[str]


class PropertyFeature(FeatureModel):
type: str = "property"
property: str
description: Optional[str]


class NumberFeature(FeatureModel):
type: str = "number"
number: Union[int, float]
Expand Down Expand Up @@ -320,6 +332,7 @@ class OperandOffsetFeature(FeatureModel):
ClassFeature,
NamespaceFeature,
APIFeature,
PropertyFeature,
NumberFeature,
BytesFeature,
OffsetFeature,
Expand Down
5 changes: 5 additions & 0 deletions capa/features/insn.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def __init__(self, name: str, description=None):
super(API, self).__init__(name, description=description)


class Property(Feature):
def __init__(self, name: str, description=None):
super().__init__(name, description=description)


class Number(Feature):
def __init__(self, value: Union[int, float], description=None):
super(Number, self).__init__(value, description=description)
Expand Down
3 changes: 3 additions & 0 deletions capa/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class Scope(str, Enum):
INSTRUCTION_SCOPE: {
capa.features.common.MatchedRule,
capa.features.insn.API,
capa.features.insn.Property,
capa.features.insn.Number,
capa.features.common.String,
capa.features.common.Bytes,
Expand Down Expand Up @@ -254,6 +255,8 @@ def parse_feature(key: str):
# keep this in sync with supported features
if key == "api":
return capa.features.insn.API
elif key == "property":
return capa.features.insn.Property
elif key == "string":
return capa.features.common.StringFactory
elif key == "substring":
Expand Down