def get_regs(*regs): result = [] if 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("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 = pwndbg.color.underline(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("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 = pwndbg.color.underline(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 cpsr(): if pwndbg.arch.current != 'arm': print(message.warn("This is only available on ARM")) return cpsr = pwndbg.regs.cpsr N = cpsr & (1 << 31) Z = cpsr & (1 << 30) C = cpsr & (1 << 29) V = cpsr & (1 << 28) T = cpsr & (1 << 5) result = [ context.flag_set('N') if N else context.flag_unset('n'), context.flag_set('Z') if Z else context.flag_unset('z'), context.flag_set('C') if C else context.flag_unset('c'), context.flag_set('V') if V else context.flag_unset('v'), context.flag_set('T') if T else context.flag_unset('t') ] print('CPSR %s %s %s %s' % (context.flag_value('%#x' % cpsr), context.flag_bracket('['), ' '.join(result), context.flag_bracket(']')))
def cpsr(): if pwndbg.arch.current != 'arm': print(message.warn("This is only available on ARM")) return cpsr = pwndbg.regs.cpsr N = cpsr & (1 << 31) Z = cpsr & (1 << 30) C = cpsr & (1 << 29) V = cpsr & (1 << 28) T = cpsr & (1 << 5) result = [ context.flag_set('N') if N else context.flag_unset('n'), context.flag_set('Z') if Z else context.flag_unset('z'), context.flag_set('C') if C else context.flag_unset('c'), context.flag_set('V') if V else context.flag_unset('v'), context.flag_set('T') if T else context.flag_unset('t') ] print('CPSR %s %s %s %s' % (context.flag_value('%#x' % cpsr), context.flag_bracket('['), ' '.join(result), context.flag_bracket(']')))