Skip to content

Commit 716e327

Browse files
committed
fix types
1 parent 7b55438 commit 716e327

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
.vscode/
2+
.mypy_cache
13
*.egg-info/
24
__pycache__/
35
build/
46
dist/
5-
6-
.vscode/

idapcode.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import traceback
2+
from typing import Dict, List, Optional
23

34
import ida_bytes
45
import ida_funcs
@@ -18,19 +19,20 @@
1819

1920
DEBUG = False
2021

22+
2123
# -----------------------------------------------------------------------
2224
class 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

Comments
 (0)