Skip to content

Commit

Permalink
dotnet: combine dnfile_.py and dotnetfile.py (#1895)
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-hunhoff authored Dec 7, 2023
1 parent d1b213a commit d6f7d21
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 201 deletions.
158 changes: 0 additions & 158 deletions capa/features/extractors/dnfile_.py

This file was deleted.

4 changes: 2 additions & 2 deletions capa/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ def get_auto_format(path: Path) -> str:
def get_format(sample: Path) -> str:
# imported locally to avoid import cycle
from capa.features.extractors.common import extract_format
from capa.features.extractors.dnfile_ import DnfileFeatureExtractor
from capa.features.extractors.dotnetfile import DotnetFileFeatureExtractor

buf = sample.read_bytes()

for feature, _ in extract_format(buf):
if feature == Format(FORMAT_PE):
dnfile_extractor = DnfileFeatureExtractor(sample)
dnfile_extractor = DotnetFileFeatureExtractor(sample)
if dnfile_extractor.is_dotnet_file():
feature = Format(FORMAT_DOTNET)

Expand Down
3 changes: 1 addition & 2 deletions capa/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import capa.render.result_document as rdoc
import capa.features.extractors.common
import capa.features.extractors.pefile
import capa.features.extractors.dnfile_
import capa.features.extractors.elffile
import capa.features.extractors.dotnetfile
import capa.features.extractors.base_extractor
Expand Down Expand Up @@ -370,7 +369,7 @@ def get_file_extractors(sample: Path, format_: str) -> List[FeatureExtractor]:

elif format_ == FORMAT_DOTNET:
file_extractors.append(capa.features.extractors.pefile.PefileFeatureExtractor(sample))
file_extractors.append(capa.features.extractors.dnfile_.DnfileFeatureExtractor(sample))
file_extractors.append(capa.features.extractors.dotnetfile.DotnetFileFeatureExtractor(sample))

elif format_ == capa.features.common.FORMAT_ELF:
file_extractors.append(capa.features.extractors.elffile.ElfFeatureExtractor(sample))
Expand Down
13 changes: 7 additions & 6 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,11 @@ def get_pefile_extractor(path: Path):
return extractor


def get_dotnetfile_extractor(path: Path):
import capa.features.extractors.dotnetfile
@lru_cache(maxsize=1)
def get_dnfile_extractor(path: Path):
import capa.features.extractors.dnfile.extractor

extractor = capa.features.extractors.dotnetfile.DotnetFileFeatureExtractor(path)
extractor = capa.features.extractors.dnfile.extractor.DnfileFeatureExtractor(path)

# overload the extractor so that the fixture exposes `extractor.path`
setattr(extractor, "path", path.as_posix())
Expand All @@ -153,10 +154,10 @@ def get_dotnetfile_extractor(path: Path):


@lru_cache(maxsize=1)
def get_dnfile_extractor(path: Path):
import capa.features.extractors.dnfile.extractor
def get_dotnetfile_extractor(path: Path):
import capa.features.extractors.dotnetfile

extractor = capa.features.extractors.dnfile.extractor.DnfileFeatureExtractor(path)
extractor = capa.features.extractors.dotnetfile.DotnetFileFeatureExtractor(path)

# overload the extractor so that the fixture exposes `extractor.path`
setattr(extractor, "path", path.as_posix())
Expand Down
33 changes: 0 additions & 33 deletions tests/test_dotnet_features.py

This file was deleted.

0 comments on commit d6f7d21

Please sign in to comment.