diff --git a/api/python/debuggercontroller.py b/api/python/debuggercontroller.py index 63a52d92..c1609740 100644 --- a/api/python/debuggercontroller.py +++ b/api/python/debuggercontroller.py @@ -187,6 +187,34 @@ def __repr__(self): return f"" +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: @@ -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: """