This commit is contained in:
Willi Ballenthin
2022-12-13 13:20:24 +01:00
parent 8afebc1f17
commit b1d6fcd6c8
5 changed files with 26 additions and 23 deletions

View File

@@ -92,17 +92,18 @@ class Shdr:
class ELF: class ELF:
def __init__(self, f): def __init__(self, f: BinaryIO):
self.f = f self.f = f
self.bitness: int = None # these will all be initialized in `_parse()`
self.endian: str = None self.bitness: int = 0
self.e_phentsize: int = None self.endian: str = ""
self.e_phnum: int = None self.e_phentsize: int = 0
self.e_shentsize: int = None self.e_phnum: int = 0
self.e_shnum: int = None self.e_shentsize: int = 0
self.phbuf = None self.e_shnum: int = 0
self.shbuf = None self.phbuf: bytes = b""
self.shbuf: bytes = b""
self._parse() self._parse()
@@ -512,13 +513,14 @@ class ABITag:
class PHNote: class PHNote:
def __init__(self, endian, buf): def __init__(self, endian: str, buf: bytes):
self.endian = endian self.endian = endian
self.buf = buf self.buf = buf
self.type_: int = None # these will be initialized in `_parse()`
self.descsz: int = None self.type_: int = 0
self.name: str = None self.descsz: int = 0
self.name: str = ""
self._parse() self._parse()
@@ -560,13 +562,14 @@ class PHNote:
class SHNote: class SHNote:
def __init__(self, endian, buf): def __init__(self, endian: str, buf: bytes):
self.endian = endian self.endian = endian
self.buf = buf self.buf = buf
self.type_: int = None # these will be initialized in `_parse()`
self.descsz: int = None self.type_: int = 0
self.name: str = None self.descsz: int = 0
self.name: str = ""
self._parse() self._parse()

View File

@@ -5,7 +5,7 @@
# Unless required by applicable law or agreed to in writing, software distributed under the License # 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. # 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. # 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 idc
import idaapi import idaapi
@@ -36,7 +36,7 @@ def find_byte_sequence(start: int, end: int, seq: bytes) -> Iterator[int]:
def get_functions( 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]: ) -> Iterator[FunctionHandle]:
"""get functions, range optional """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) 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""" """yield op_t for instruction, filter on type if specified"""
for op in insn.ops: for op in insn.ops:
if op.type == idaapi.o_void: if op.type == idaapi.o_void:

View File

@@ -31,7 +31,7 @@ def interface_extract_basic_block_XXX(f: FunctionHandle, bb: BBHandle) -> Iterat
yields: yields:
(Feature, Address): the feature and the address at which its found. (Feature, Address): the feature and the address at which its found.
""" """
... raise NotImplementedError
def _bb_has_tight_loop(f, bb): def _bb_has_tight_loop(f, bb):

View File

@@ -27,7 +27,7 @@ def interface_extract_function_XXX(fh: FunctionHandle) -> Iterator[Tuple[Feature
yields: yields:
(Feature, Address): the feature and the address at which its found. (Feature, Address): the feature and the address at which its found.
""" """
... raise NotImplementedError
def extract_function_calls_to(fhandle: FunctionHandle) -> Iterator[Tuple[Feature, Address]]: def extract_function_calls_to(fhandle: FunctionHandle) -> Iterator[Tuple[Feature, Address]]:

View File

@@ -44,7 +44,7 @@ def interface_extract_instruction_XXX(
yields: yields:
(Feature, Address): the feature and the address at which its found. (Feature, Address): the feature and the address at which its found.
""" """
... raise NotImplementedError
def get_imports(vw): def get_imports(vw):