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 the ability to select which functions or processes you which to extract capabilities from #2156

Merged
merged 46 commits into from
Aug 20, 2024
Merged
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
38c6623
initial commit
yelhamer Jun 19, 2024
154afe1
test_capabilities.py: add tests
yelhamer Jun 19, 2024
1ae174b
CHANGELOG.md: update changelog
yelhamer Jun 19, 2024
acd69a3
usage.md: updated documentation
yelhamer Jun 19, 2024
3aaae2e
main.py: use input_format instead of file_extractors to determine ana…
yelhamer Jun 19, 2024
f7c43e9
fix linting
yelhamer Jun 19, 2024
b7e345d
apply flake8 suggestions
yelhamer Jun 19, 2024
8c8321b
main.py: Use Optional typehint
yelhamer Jun 19, 2024
1642e7e
main.py: bugfix for return instead of raise
yelhamer Jun 19, 2024
090ade5
main.py: add errorcode for invalid input format
yelhamer Jun 19, 2024
8e8e0ec
Function/Process filtering: use a function to filter
yelhamer Jun 20, 2024
1d52600
Function/Process filtering: ignore mypy errors for method reassignment
yelhamer Jun 20, 2024
d78272f
function/proc filtering tests: use a copy of the extractor in order t…
yelhamer Jun 20, 2024
e3071f8
Extractor Filters: wrap classes and overwrite __class__ instead of us…
yelhamer Jun 21, 2024
c2058bf
Extractor Filters: fix mypy errors
yelhamer Jun 21, 2024
c54bafc
function/proc filtering: overwrite __instancecheck__() for extractor …
yelhamer Jun 21, 2024
fe9f332
base_extractor: update FeatureExtractor type to include filters
yelhamer Jun 21, 2024
b329f3f
capa/loader.py: update assert_never() for mypy
yelhamer Jun 21, 2024
1a79591
capa/loader.py: use tuple in isinstance() for flake8
yelhamer Jun 21, 2024
d2c19cd
Update capa/main.py
yelhamer Jul 16, 2024
f048678
Merge branch 'master' into yelhamer-filtered-scopes
yelhamer Aug 15, 2024
02ce318
process/function filtering: override extractor object method
yelhamer Aug 15, 2024
38e3ab1
function/process filtering: ignore method reassignment type errors
yelhamer Aug 15, 2024
c91580b
process/function filtering: use --restrict-to-{processes/functions} f…
yelhamer Aug 15, 2024
5dc562d
process/functions filtering: make `apply_extractor_filters()` extensible
yelhamer Aug 15, 2024
5300f4a
process/functions filtering: use list comprehension instead of map
yelhamer Aug 15, 2024
d6cf34a
process/functions filtering: use set comprehension instead of set()
yelhamer Aug 15, 2024
e4836e5
capa/main.py: fix mypy issues
yelhamer Aug 15, 2024
9243334
Merge branch 'master' into yelhamer-filtered-scopes
yelhamer Aug 19, 2024
1168996
Update CHANGELOG.md: typo
yelhamer Aug 19, 2024
2f00b7f
Update capa/main.py
yelhamer Aug 19, 2024
79f3097
Update capa/main.py
yelhamer Aug 19, 2024
9ce2a3c
Update doc/usage.md
yelhamer Aug 19, 2024
28e274f
Update doc/usage.md
yelhamer Aug 19, 2024
fa61273
update changelog
yelhamer Aug 20, 2024
0640ba9
Update capa/features/extractors/base_extractor.py
yelhamer Aug 20, 2024
b693aa0
base_extractor.py: rename variable
yelhamer Aug 20, 2024
10a26a8
base_extractor.py: update comments
yelhamer Aug 20, 2024
b0d8071
main.py: add FilterConfig type
yelhamer Aug 20, 2024
ac50103
main.py: add asserts for checking filters are not empty
yelhamer Aug 20, 2024
a194a13
main.py: remove unused Set import
yelhamer Aug 20, 2024
e80f474
main.py: move filters extractor into get_extractor_from_cli() routine
yelhamer Aug 20, 2024
88d9d67
doc/usage.md: update usage according to reviews
yelhamer Aug 20, 2024
c30a10a
Update capa/features/extractors/base_extractor.py
yelhamer Aug 20, 2024
150d6f0
Update capa/features/extractors/base_extractor.py
yelhamer Aug 20, 2024
3aefa76
Update doc/usage.md
yelhamer Aug 20, 2024
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
11 changes: 8 additions & 3 deletions capa/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import textwrap
import contextlib
from types import TracebackType
from typing import Any, Set, Dict, List, Optional
from typing import Any, Set, Dict, List, Optional, TypedDict
from pathlib import Path

import colorama
Expand Down Expand Up @@ -121,6 +121,11 @@
logger = logging.getLogger("capa")


class FilterConfig(TypedDict, total=False):
processes: set[int]
functions: set[int]
yelhamer marked this conversation as resolved.
Show resolved Hide resolved


@contextlib.contextmanager
def timing(msg: str):
t0 = time.time()
Expand Down Expand Up @@ -807,7 +812,7 @@ def get_extractor_from_cli(args, input_format: str, backend: str) -> FeatureExtr
raise ShouldExitError(E_CORRUPT_FILE) from e


def get_extractor_filters_from_cli(args, input_format) -> Dict[str, Set]:
def get_extractor_filters_from_cli(args, input_format) -> FilterConfig:
if input_format in STATIC_FORMATS:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may want to factor out the is_static_analysis into its own routine. though its not required in this PR.

if args.restrict_to_processes:
raise InvalidArgument("Cannot filter processes with static analysis.")
Expand All @@ -820,7 +825,7 @@ def get_extractor_filters_from_cli(args, input_format) -> Dict[str, Set]:
raise ShouldExitError(E_INVALID_INPUT_FORMAT)


def apply_extractor_filters(extractor: FeatureExtractor, extractor_filters: Dict[str, Set]):
def apply_extractor_filters(extractor: FeatureExtractor, extractor_filters: FilterConfig):
if isinstance(extractor, StaticFeatureExtractor):
return FunctionFilter(extractor, extractor_filters["functions"])
yelhamer marked this conversation as resolved.
Show resolved Hide resolved
elif isinstance(extractor, DynamicFeatureExtractor):
Expand Down
Loading