From 422b365c48badc04207c15e79fdb53c447df4261 Mon Sep 17 00:00:00 2001 From: Disconnect3d Date: Mon, 4 May 2020 18:52:13 +0200 Subject: [PATCH 1/2] Add __repr__ for capstone.CsInsn Currently, a `print(instruction)` displays a not very useful string like ``. This PR enhances adds a `__repr__` magic method to the `capstone.CsInsn` class so it displays as follows: ``` ``` --- bindings/python/capstone/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bindings/python/capstone/__init__.py b/bindings/python/capstone/__init__.py index d5ea918b80..1f7a643302 100644 --- a/bindings/python/capstone/__init__.py +++ b/bindings/python/capstone/__init__.py @@ -539,6 +539,10 @@ def __init__(self, cs, all_info): self._raw.detail = ctypes.pointer(all_info.detail._type_()) ctypes.memmove(ctypes.byref(self._raw.detail[0]), ctypes.byref(all_info.detail[0]), ctypes.sizeof(type(all_info.detail[0]))) + def __repr__(self): + def __repr__(self): + return '' % (self.address, self.size, self.mnemonic, self.op_str) + # return instruction's ID. @property def id(self): From 358d74767a2fd8c0199bb8165f357dd8c457979c Mon Sep 17 00:00:00 2001 From: Disconnect3d Date: Mon, 4 May 2020 19:45:20 +0200 Subject: [PATCH 2/2] Update __init__.py --- bindings/python/capstone/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bindings/python/capstone/__init__.py b/bindings/python/capstone/__init__.py index 1f7a643302..2afa550022 100644 --- a/bindings/python/capstone/__init__.py +++ b/bindings/python/capstone/__init__.py @@ -540,8 +540,7 @@ def __init__(self, cs, all_info): ctypes.memmove(ctypes.byref(self._raw.detail[0]), ctypes.byref(all_info.detail[0]), ctypes.sizeof(type(all_info.detail[0]))) def __repr__(self): - def __repr__(self): - return '' % (self.address, self.size, self.mnemonic, self.op_str) + return '' % (self.address, self.bytes.hex(), self.mnemonic, self.op_str) # return instruction's ID. @property