Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
yeggor committed Oct 27, 2023
1 parent 7b55438 commit 716e327
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.vscode/
.mypy_cache
*.egg-info/
__pycache__/
build/
dist/

.vscode/
32 changes: 16 additions & 16 deletions idapcode.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import traceback
from typing import Dict, List, Optional

import ida_bytes
import ida_funcs
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 716e327

Please sign in to comment.