From 716e32750d57c99e62e1803af7e4e5218d08e8ad Mon Sep 17 00:00:00 2001 From: yeggor Date: Fri, 27 Oct 2023 21:18:46 +0100 Subject: [PATCH] fix types --- .gitignore | 4 ++-- idapcode.py | 32 ++++++++++++++++---------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 38c7048..06438b7 100755 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ +.vscode/ +.mypy_cache *.egg-info/ __pycache__/ build/ dist/ - -.vscode/ diff --git a/idapcode.py b/idapcode.py index ee7965d..03acba1 100755 --- a/idapcode.py +++ b/idapcode.py @@ -1,4 +1,5 @@ import traceback +from typing import Dict, List, Optional import ida_bytes import ida_funcs @@ -18,19 +19,20 @@ DEBUG = False + # ----------------------------------------------------------------------- class FuncPcode: """Helper class for getting p-code for a function""" - def __init__(self, addr: int): + def __init__(self, addr: int) -> None: self._addr: int = addr - self._func_pcode: str = None - self._func_name: str = None + self._func_pcode: Optional[List[str]] = None + self._func_name: Optional[str] = None self._inf = idaapi.get_inf_structure() # adopted from # https://github.com/cseagle/blc/blob/b1447562a3598fd411224dfc24b970cf53ca7c94/plugin.cc#L516 - self._proc_map = dict() + self._proc_map: Dict[Any] = dict() self._proc_map[idaapi.PLFM_6502] = "6502" self._proc_map[idaapi.PLFM_68K] = "68000" self._proc_map[idaapi.PLFM_6800] = "6805" @@ -69,7 +71,7 @@ def _inf_is_be(self) -> bool: def _get_proc_id(self) -> int: return idaapi.ph_get_id() - def _get_proc(self) -> str: + def _get_proc(self) -> Optional[str]: proc_id = self._get_proc_id() if proc_id not in self._proc_map: return None @@ -80,7 +82,7 @@ def _get_endian(self) -> str: return "BE" return "LE" - def _get_sleigh_id(self) -> str: + def _get_sleigh_id(self) -> Optional[str]: """Get sleigh language id string""" proc = self._get_proc() @@ -201,27 +203,25 @@ def _get_pcode(self) -> list: f"{insn.asm_mnem.lower()} {insn.asm_body.lower()}", ida_lines.SCOLOR_INSN, ) - pcode_lines.append(f"{asm_prefix}\x20\x20{asm_insn}") + pcode_lines.append(f"{asm_prefix} {asm_insn}") # append P-Code text for op in insn.ops: - pcode_lines.append(f"\x20\x20{PcodePrettyPrinter.fmt_op(op)}") + pcode_lines.append(f" {PcodePrettyPrinter.fmt_op(op)}") pcode_lines.append("\n") return pcode_lines @property - def func_name(self): - if self._func_name is not None: - return self._func_name - self._func_name = self._get_func_name() + def func_name(self) -> str: + if self._func_name is None: + self._func_name = self._get_func_name() return self._func_name @property - def pcode(self): - if self._func_pcode is not None: - return self._func_pcode - self._func_pcode = self._get_pcode() + def pcode(self) -> List[str]: + if self._func_pcode is None: + self._func_pcode = self._get_pcode() return self._func_pcode