diff --git a/capa/features/extractors/elf.py b/capa/features/extractors/elf.py index d5c187dc..4fed06dc 100644 --- a/capa/features/extractors/elf.py +++ b/capa/features/extractors/elf.py @@ -92,17 +92,18 @@ class Shdr: class ELF: - def __init__(self, f): + def __init__(self, f: BinaryIO): self.f = f - self.bitness: int = None - self.endian: str = None - self.e_phentsize: int = None - self.e_phnum: int = None - self.e_shentsize: int = None - self.e_shnum: int = None - self.phbuf = None - self.shbuf = None + # these will all be initialized in `_parse()` + self.bitness: int = 0 + self.endian: str = "" + self.e_phentsize: int = 0 + self.e_phnum: int = 0 + self.e_shentsize: int = 0 + self.e_shnum: int = 0 + self.phbuf: bytes = b"" + self.shbuf: bytes = b"" self._parse() @@ -512,13 +513,14 @@ class ABITag: class PHNote: - def __init__(self, endian, buf): + def __init__(self, endian: str, buf: bytes): self.endian = endian self.buf = buf - self.type_: int = None - self.descsz: int = None - self.name: str = None + # these will be initialized in `_parse()` + self.type_: int = 0 + self.descsz: int = 0 + self.name: str = "" self._parse() @@ -560,13 +562,14 @@ class PHNote: class SHNote: - def __init__(self, endian, buf): + def __init__(self, endian: str, buf: bytes): self.endian = endian self.buf = buf - self.type_: int = None - self.descsz: int = None - self.name: str = None + # these will be initialized in `_parse()` + self.type_: int = 0 + self.descsz: int = 0 + self.name: str = "" self._parse() diff --git a/capa/features/extractors/ida/helpers.py b/capa/features/extractors/ida/helpers.py index a333f064..5c997f69 100644 --- a/capa/features/extractors/ida/helpers.py +++ b/capa/features/extractors/ida/helpers.py @@ -5,7 +5,7 @@ # Unless required by applicable law or agreed to in writing, software distributed under the License # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and limitations under the License. -from typing import Any, Dict, Tuple, Iterator +from typing import Any, Dict, Tuple, Iterator, Optional import idc import idaapi @@ -36,7 +36,7 @@ def find_byte_sequence(start: int, end: int, seq: bytes) -> Iterator[int]: def get_functions( - start: int = None, end: int = None, skip_thunks: bool = False, skip_libs: bool = False + start: Optional[int] = None, end: Optional[int] = None, skip_thunks: bool = False, skip_libs: bool = False ) -> Iterator[FunctionHandle]: """get functions, range optional @@ -287,7 +287,7 @@ def is_frame_register(reg: int) -> bool: return reg in (idautils.procregs.sp.reg, idautils.procregs.bp.reg) -def get_insn_ops(insn: idaapi.insn_t, target_ops: Tuple[Any] = None) -> idaapi.op_t: +def get_insn_ops(insn: idaapi.insn_t, target_ops: Optional[Tuple[Any]] = None) -> idaapi.op_t: """yield op_t for instruction, filter on type if specified""" for op in insn.ops: if op.type == idaapi.o_void: diff --git a/capa/features/extractors/viv/basicblock.py b/capa/features/extractors/viv/basicblock.py index 6341ec3a..9848bec0 100644 --- a/capa/features/extractors/viv/basicblock.py +++ b/capa/features/extractors/viv/basicblock.py @@ -31,7 +31,7 @@ def interface_extract_basic_block_XXX(f: FunctionHandle, bb: BBHandle) -> Iterat yields: (Feature, Address): the feature and the address at which its found. """ - ... + raise NotImplementedError def _bb_has_tight_loop(f, bb): diff --git a/capa/features/extractors/viv/function.py b/capa/features/extractors/viv/function.py index 64671711..cf1df527 100644 --- a/capa/features/extractors/viv/function.py +++ b/capa/features/extractors/viv/function.py @@ -27,7 +27,7 @@ def interface_extract_function_XXX(fh: FunctionHandle) -> Iterator[Tuple[Feature yields: (Feature, Address): the feature and the address at which its found. """ - ... + raise NotImplementedError def extract_function_calls_to(fhandle: FunctionHandle) -> Iterator[Tuple[Feature, Address]]: diff --git a/capa/features/extractors/viv/insn.py b/capa/features/extractors/viv/insn.py index ae106c31..738c69a7 100644 --- a/capa/features/extractors/viv/insn.py +++ b/capa/features/extractors/viv/insn.py @@ -44,7 +44,7 @@ def interface_extract_instruction_XXX( yields: (Feature, Address): the feature and the address at which its found. """ - ... + raise NotImplementedError def get_imports(vw):