From e8d6feb5e0b2f8201e06c3cbd5c25194829761d8 Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Thu, 29 Jun 2023 11:36:48 -0400 Subject: Improve __repr__ for IL instructions, and related objects --- python/mediumlevelil.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'python/mediumlevelil.py') diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py index df5ae4a0..e781b1da 100644 --- a/python/mediumlevelil.py +++ b/python/mediumlevelil.py @@ -67,7 +67,7 @@ class SSAVariable: version: int def __repr__(self): - return f"" + return f"" @property def name(self) -> str: @@ -102,8 +102,8 @@ class MediumLevelILOperationAndSize: def __repr__(self): if self.size == 0: - return f"<{self.operation.name}>" - return f"<{self.operation.name} {self.size}>" + return f"" + return f"" @dataclass(frozen=True) @@ -364,7 +364,7 @@ class MediumLevelILInstruction(BaseILInstruction): return result def __repr__(self): - return f"" + return f"<{self.__class__.__name__}: {self}>" def __eq__(self, other: 'MediumLevelILInstruction') -> bool: if not isinstance(other, MediumLevelILInstruction): @@ -479,6 +479,11 @@ class MediumLevelILInstruction(BaseILInstruction): @property def tokens(self) -> TokenList: """MLIL tokens (read-only)""" + + # Special case for the helper instructions which don't have tokens + if isinstance(self, (MediumLevelILCallParam, MediumLevelILCallParamSsa)): + return [] + count = ctypes.c_ulonglong() tokens = ctypes.POINTER(core.BNInstructionTextToken)() assert self.function.arch is not None, f"type(self.function): {type(self.function)} " @@ -1246,6 +1251,9 @@ class MediumLevelILCallOutput(MediumLevelILInstruction): @dataclass(frozen=True, repr=False, eq=False) class MediumLevelILCallParam(MediumLevelILInstruction): + def __repr__(self): + return f"" + @property def src(self) -> List[variable.Variable]: return self._get_var_list(0, 1) @@ -1806,6 +1814,9 @@ class MediumLevelILCallOutputSsa(MediumLevelILInstruction, SSA): @dataclass(frozen=True, repr=False, eq=False) class MediumLevelILCallParamSsa(MediumLevelILInstruction, SSA): + def __repr__(self): + return f"" + @property def src_memory(self) -> int: return self._get_int(0) @@ -2990,9 +3001,9 @@ class MediumLevelILFunction: def __repr__(self): arch = self.source_function.arch if arch: - return f"" + return f"" else: - return f"" + return f"" def __len__(self): return int(core.BNGetMediumLevelILInstructionCount(self.handle)) -- cgit v1.3.1