fix: address reportAttributeAccessIssue and override mismatches (chunk 4)

- dnfile/helpers.py, insn.py: add import dnfile.mdtable; type: ignore dnfile Unknown returns
- dnfile/extractor.py: rename get_basic_blocks param f->fh
- pefile.py: rename f/bb->fh/bbh stub params; type: ignore for pefile OPTIONAL_HEADER stubs
- ghidra/file.py, helpers.py: initialize addr=0 before conditional loop
This commit is contained in:
Willi Ballenthin
2026-04-22 17:03:16 +03:00
committed by Willi Ballenthin
parent b34079208c
commit 96cabbcc6b
6 changed files with 13 additions and 9 deletions

View File

@@ -157,11 +157,11 @@ class DnfileFeatureExtractor(StaticFeatureExtractor):
def extract_function_features(self, fh) -> Iterator[tuple[Feature, Address]]:
yield from capa.features.extractors.dnfile.function.extract_features(fh)
def get_basic_blocks(self, f) -> Iterator[BBHandle]:
def get_basic_blocks(self, fh) -> Iterator[BBHandle]:
# each dotnet method is considered 1 basic block
yield BBHandle(
address=f.address,
inner=f.inner,
address=fh.address,
inner=fh.inner,
)
def extract_basic_block_features(self, fh, bbh):

View File

@@ -21,6 +21,7 @@ from typing import Union, Iterator, Optional
from pathlib import Path
import dnfile
import dnfile.mdtable
from dncil.cil.body import CilMethodBody
from dncil.cil.error import MethodBodyFormatError
from dncil.clr.token import Token, StringToken, InvalidToken
@@ -48,7 +49,7 @@ class DnfileMethodBodyReader(CilMethodBodyReaderBase):
self.offset: int = self.pe.get_offset_from_rva(row.Rva)
def read(self, n: int) -> bytes:
data: bytes = self.pe.get_data(self.pe.get_rva_from_offset(self.offset), n)
data: bytes = self.pe.get_data(self.pe.get_rva_from_offset(self.offset), n) # type: ignore # dnfile stubs return Unknown for get_data/get_rva_from_offset
self.offset += n
return data

View File

@@ -22,6 +22,7 @@ if TYPE_CHECKING:
from capa.features.extractors.dnfile.extractor import DnFileFeatureExtractorCache
import dnfile
import dnfile.mdtable
from dncil.clr.token import Token, StringToken, InvalidToken
from dncil.cil.opcode import OpCodes

View File

@@ -143,6 +143,7 @@ def extract_file_import_names() -> Iterator[tuple[Feature, Address]]:
"""
for f in capa.features.extractors.ghidra.helpers.get_current_program().getFunctionManager().getExternalFunctions():
addr: int = 0
for r in f.getSymbol().getReferences():
if r.getReferenceType().isData():
addr = r.getFromAddress().getOffset() # gets pointer to fake external addr

View File

@@ -123,6 +123,7 @@ def get_file_imports() -> dict[int, list[str]]:
import_dict: dict[int, list[str]] = {}
for f in get_current_program().getFunctionManager().getExternalFunctions():
addr: int = 0
for r in f.getSymbol().getReferences():
if r.getReferenceType().isData():
addr = r.getFromAddress().getOffset() # gets pointer to fake external addr

View File

@@ -202,7 +202,7 @@ class PefileFeatureExtractor(StaticFeatureExtractor):
self.pe = pefile.PE(str(path))
def get_base_address(self):
return AbsoluteVirtualAddress(self.pe.OPTIONAL_HEADER.ImageBase)
return AbsoluteVirtualAddress(self.pe.OPTIONAL_HEADER.ImageBase) # type: ignore[union-attr] # pefile stubs type OPTIONAL_HEADER as Optional
def extract_global_features(self):
buf = Path(self.path).read_bytes()
@@ -217,16 +217,16 @@ class PefileFeatureExtractor(StaticFeatureExtractor):
def get_functions(self):
raise NotImplementedError("PefileFeatureExtract can only be used to extract file features")
def extract_function_features(self, f):
def extract_function_features(self, fh):
raise NotImplementedError("PefileFeatureExtract can only be used to extract file features")
def get_basic_blocks(self, f):
def get_basic_blocks(self, fh):
raise NotImplementedError("PefileFeatureExtract can only be used to extract file features")
def extract_basic_block_features(self, f, bb):
def extract_basic_block_features(self, fh, bbh):
raise NotImplementedError("PefileFeatureExtract can only be used to extract file features")
def get_instructions(self, f, bb):
def get_instructions(self, fh, bbh):
raise NotImplementedError("PefileFeatureExtract can only be used to extract file features")
def extract_insn_features(self, fh, bbh, ih):