def get_regs(*regs): result = [] if not regs and pwndbg.config.show_retaddr_reg: regs = pwndbg.regs.gpr + (pwndbg.regs.frame, pwndbg.regs.current.stack) + pwndbg.regs.retaddr + (pwndbg.regs.current.pc,) elif not regs: regs = pwndbg.regs.gpr + (pwndbg.regs.frame, pwndbg.regs.current.stack, pwndbg.regs.current.pc) if pwndbg.config.show_flags: regs += tuple(pwndbg.regs.flags) changed = pwndbg.regs.changed for reg in regs: if reg is None: continue if reg not in pwndbg.regs: message.warn("Unknown register: %r" % reg) continue value = pwndbg.regs[reg] # Make the register stand out regname = C.register(reg.ljust(4).upper()) # Show a dot next to the register if it changed change_marker = "%s" % C.config_register_changed_marker m = ' ' * len(change_marker) if reg not in changed else C.register_changed(change_marker) if reg not in pwndbg.regs.flags: desc = pwndbg.chain.format(value) else: names = [] desc = C.flag_value('%#x' % value) last = pwndbg.regs.last.get(reg, 0) or 0 flags = pwndbg.regs.flags[reg] for name, bit in sorted(flags.items()): bit = 1<<bit if value & bit: name = name.upper() name = C.flag_set(name) else: name = name.lower() name = C.flag_unset(name) if value & bit != last & bit: name = C.flag_changed(name) names.append(name) if names: desc = '%s %s %s %s' % (desc, C.flag_bracket('['), ' '.join(names), C.flag_bracket(']')) result.append("%s%s %s" % (m, regname, desc)) return result
def get_regs(*regs): result = [] if not regs and pwndbg.config.show_retaddr_reg: regs = pwndbg.regs.gpr + (pwndbg.regs.frame, pwndbg.regs.current.stack) + pwndbg.regs.retaddr + (pwndbg.regs.current.pc,) elif not regs: regs = pwndbg.regs.gpr + (pwndbg.regs.frame, pwndbg.regs.current.stack, pwndbg.regs.current.pc) if pwndbg.config.show_flags: regs += tuple(pwndbg.regs.flags) changed = pwndbg.regs.changed for reg in regs: if reg is None: continue if reg not in pwndbg.regs: print(message.warn("Unknown register: %r" % reg)) continue value = pwndbg.regs[reg] # Make the register stand out regname = C.register(reg.ljust(4).upper()) # Show a dot next to the register if it changed change_marker = "%s" % C.config_register_changed_marker m = ' ' * len(change_marker) if reg not in changed else C.register_changed(change_marker) if reg not in pwndbg.regs.flags: desc = pwndbg.chain.format(value) else: names = [] desc = C.flag_value('%#x' % value) last = pwndbg.regs.last.get(reg, 0) or 0 flags = pwndbg.regs.flags[reg] for name, bit in sorted(flags.items()): bit = 1<<bit if value & bit: name = name.upper() name = C.flag_set(name) else: name = name.lower() name = C.flag_unset(name) if value & bit != last & bit: name = C.flag_changed(name) names.append(name) if names: desc = '%s %s %s %s' % (desc, C.flag_bracket('['), ' '.join(names), C.flag_bracket(']')) result.append("%s%s %s" % (m, regname, desc)) return result