11import traceback
2+ from typing import Dict , List , Optional
23
34import ida_bytes
45import ida_funcs
1819
1920DEBUG = False
2021
22+
2123# -----------------------------------------------------------------------
2224class FuncPcode :
2325 """Helper class for getting p-code for a function"""
2426
25- def __init__ (self , addr : int ):
27+ def __init__ (self , addr : int ) -> None :
2628 self ._addr : int = addr
27- self ._func_pcode : str = None
28- self ._func_name : str = None
29+ self ._func_pcode : Optional [ List [ str ]] = None
30+ self ._func_name : Optional [ str ] = None
2931 self ._inf = idaapi .get_inf_structure ()
3032
3133 # adopted from
3234 # https://github.com/cseagle/blc/blob/b1447562a3598fd411224dfc24b970cf53ca7c94/plugin.cc#L516
33- self ._proc_map = dict ()
35+ self ._proc_map : Dict [ Any ] = dict ()
3436 self ._proc_map [idaapi .PLFM_6502 ] = "6502"
3537 self ._proc_map [idaapi .PLFM_68K ] = "68000"
3638 self ._proc_map [idaapi .PLFM_6800 ] = "6805"
@@ -69,7 +71,7 @@ def _inf_is_be(self) -> bool:
6971 def _get_proc_id (self ) -> int :
7072 return idaapi .ph_get_id ()
7173
72- def _get_proc (self ) -> str :
74+ def _get_proc (self ) -> Optional [ str ] :
7375 proc_id = self ._get_proc_id ()
7476 if proc_id not in self ._proc_map :
7577 return None
@@ -80,7 +82,7 @@ def _get_endian(self) -> str:
8082 return "BE"
8183 return "LE"
8284
83- def _get_sleigh_id (self ) -> str :
85+ def _get_sleigh_id (self ) -> Optional [ str ] :
8486 """Get sleigh language id string"""
8587
8688 proc = self ._get_proc ()
@@ -201,27 +203,25 @@ def _get_pcode(self) -> list:
201203 f"{ insn .asm_mnem .lower ()} { insn .asm_body .lower ()} " ,
202204 ida_lines .SCOLOR_INSN ,
203205 )
204- pcode_lines .append (f"{ asm_prefix } \x20 \x20 { asm_insn } " )
206+ pcode_lines .append (f"{ asm_prefix } { asm_insn } " )
205207 # append P-Code text
206208 for op in insn .ops :
207- pcode_lines .append (f"\x20 \x20 { PcodePrettyPrinter .fmt_op (op )} " )
209+ pcode_lines .append (f" { PcodePrettyPrinter .fmt_op (op )} " )
208210
209211 pcode_lines .append ("\n " )
210212
211213 return pcode_lines
212214
213215 @property
214- def func_name (self ):
215- if self ._func_name is not None :
216- return self ._func_name
217- self ._func_name = self ._get_func_name ()
216+ def func_name (self ) -> str :
217+ if self ._func_name is None :
218+ self ._func_name = self ._get_func_name ()
218219 return self ._func_name
219220
220221 @property
221- def pcode (self ):
222- if self ._func_pcode is not None :
223- return self ._func_pcode
224- self ._func_pcode = self ._get_pcode ()
222+ def pcode (self ) -> List [str ]:
223+ if self ._func_pcode is None :
224+ self ._func_pcode = self ._get_pcode ()
225225 return self ._func_pcode
226226
227227
0 commit comments