Skip to content

Commit 5f854c8

Browse files
author
netanelc305
committed
libvmi: Add __str__ method to Registers
1 parent e364ccd commit 5f854c8

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

libvmi/libvmi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,22 @@ def __setitem__(self, index, value):
139139
raise_from(RuntimeError('Unknown field {} in regs.x86'
140140
.format(index.name.lower())), e)
141141

142+
def __str__(self):
143+
# Heuristic to determine the architecture
144+
if hasattr(self.cffi_regs.x86, 'rip') or hasattr(self.cffi_regs.x86, 'eip'):
145+
regs_to_print = self.cffi_regs.x86
146+
elif hasattr(self.cffi_regs.arm, 'pc'):
147+
regs_to_print = self.cffi_regs.arm
148+
else:
149+
raise RuntimeError("Unable to determine architecture")
150+
attributes = []
151+
for attr in dir(regs_to_print):
152+
if not attr.startswith('_'):
153+
value = getattr(regs_to_print, attr)
154+
attributes.append(f"{attr.lower()} = {value:#x}")
155+
156+
return '\n'.join(attributes)
157+
142158

143159
class VMIMode(Enum):
144160
XEN = lib.VMI_XEN

0 commit comments

Comments
 (0)