Skip to content

Commit

Permalink
Improvement to the register Python API
Browse files Browse the repository at this point in the history
  • Loading branch information
op2786 authored and xusheng6 committed Dec 15, 2022
1 parent ba1a21e commit 573d21e
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions api/python/debuggercontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,34 @@ def __repr__(self):
return f"<DebugRegister: {self.name}, {self.value:#x}{hint_str}>"


class DebugRegisters:
"""
DebugRegisters represents all registers of the target.
"""
def __init__(self, handle):
self.handle = handle
self.regs = {}
count = ctypes.c_ulonglong()
registers = dbgcore.BNDebuggerGetRegisters(handle, count)
for i in range(0, count.value):
bp = DebugRegister(registers[i].m_name, registers[i].m_value,
registers[i].m_width, registers[i].m_registerIndex, registers[i].m_hint)
self.regs[registers[i].m_name] = bp
dbgcore.BNDebuggerFreeRegisters(registers, count.value)

def __repr__(self) -> str:
return self.regs.__repr__()

def __getitem__(self, name):
if name not in self.regs:
return None

return self.regs[name]

def __setitem__(self, name, val):
dbgcore.BNDebuggerSetRegisterValue(self.handle, name, val)


class DebugBreakpoint:
"""
DebugBreakpoint represents a breakpoint in the target. It has the following fields:
Expand Down Expand Up @@ -674,21 +702,13 @@ def modules(self) -> List[DebugModule]:
return result

@property
def regs(self) -> List[DebugRegister]:
def regs(self) -> DebugRegisters:
"""
All registers of the target
:return: a list of ``DebugRegister``
"""
count = ctypes.c_ulonglong()
registers = dbgcore.BNDebuggerGetRegisters(self.handle, count)
result = []
for i in range(0, count.value):
bp = DebugRegister(registers[i].m_name, registers[i].m_value, registers[i].m_width, registers[i].m_registerIndex, registers[i].m_hint)
result.append(bp)

dbgcore.BNDebuggerFreeRegisters(registers, count.value)
return result
return DebugRegisters(self.handle)

def get_reg_value(self, reg: str) -> int:
"""
Expand Down

0 comments on commit 573d21e

Please sign in to comment.