Skip to content

Commit

Permalink
libvmi: Add __str__ method to Registers
Browse files Browse the repository at this point in the history
  • Loading branch information
netanelc305 committed Dec 27, 2023
1 parent e364ccd commit 5f854c8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions libvmi/libvmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,22 @@ def __setitem__(self, index, value):
raise_from(RuntimeError('Unknown field {} in regs.x86'
.format(index.name.lower())), e)

def __str__(self):
# Heuristic to determine the architecture
if hasattr(self.cffi_regs.x86, 'rip') or hasattr(self.cffi_regs.x86, 'eip'):
regs_to_print = self.cffi_regs.x86
elif hasattr(self.cffi_regs.arm, 'pc'):
regs_to_print = self.cffi_regs.arm
else:
raise RuntimeError("Unable to determine architecture")
attributes = []
for attr in dir(regs_to_print):
if not attr.startswith('_'):
value = getattr(regs_to_print, attr)
attributes.append(f"{attr.lower()} = {value:#x}")

return '\n'.join(attributes)


class VMIMode(Enum):
XEN = lib.VMI_XEN
Expand Down

0 comments on commit 5f854c8

Please sign in to comment.