mirror of
https://github.com/mandiant/capa.git
synced 2026-04-28 11:53:20 -07:00
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:
committed by
Willi Ballenthin
parent
b34079208c
commit
96cabbcc6b
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user