diff --git a/pwndbg/commands/cpsr.py b/pwndbg/commands/cpsr.py index d2278585b..f4302f1bd 100644 --- a/pwndbg/commands/cpsr.py +++ b/pwndbg/commands/cpsr.py @@ -2,31 +2,13 @@ import pwndbg.commands import pwndbg.gdblib.arch import pwndbg.gdblib.regs from pwndbg.color import context -from pwndbg.color import message -@pwndbg.commands.ArgparsedCommand("Print out ARM CPSR or xPSR register") +@pwndbg.commands.ArgparsedCommand("Print out ARM CPSR or xPSR register", aliases=["xpsr", "pstate"]) +@pwndbg.commands.OnlyWithArch(["arm", "armcm", "aarch64"]) @pwndbg.commands.OnlyWhenRunning def cpsr(): - arm_print_psr() - - -@pwndbg.commands.ArgparsedCommand("Print out ARM xPSR or CPSR register") -@pwndbg.commands.OnlyWhenRunning -def xpsr(): - arm_print_psr() - - -def arm_print_psr(): - if pwndbg.gdblib.arch.current not in ("arm", "armcm"): - print(message.warn("This is only available on ARM")) - return - - reg = "cpsr" if pwndbg.gdblib.arch.current == "arm" else "xpsr" - print( - "%s %s" - % ( - reg, - context.format_flags(getattr(pwndbg.gdblib.regs, reg), pwndbg.gdblib.regs.flags[reg]), - ) - ) + reg = "xpsr" if pwndbg.gdblib.arch.name == "armcm" else "cpsr" + reg_val = getattr(pwndbg.gdblib.regs, reg) + reg_flags = pwndbg.gdblib.regs.flags[reg] + print(f"{reg} {context.format_flags(reg_val, reg_flags)}") diff --git a/pwndbg/lib/regs.py b/pwndbg/lib/regs.py index 6c55f0ba6..e8efa2092 100644 --- a/pwndbg/lib/regs.py +++ b/pwndbg/lib/regs.py @@ -94,6 +94,25 @@ arm_xpsr_flags = collections.OrderedDict( [("N", 31), ("Z", 30), ("C", 29), ("V", 28), ("Q", 27), ("T", 24)] ) +aarch64_cpsr_flags = collections.OrderedDict( + [ + ("N", 31), + ("Z", 30), + ("C", 29), + ("V", 28), + ("Q", 27), + ("PAN", 22), + ("IL", 20), + ("D", 9), + ("A", 8), + ("I", 7), + ("F", 6), + # TODO: EL is two bits + ("EL", 2), + ("SP", 0), + ] +) + arm = RegisterSet( retaddr=("lr",), flags={"cpsr": arm_cpsr_flags}, @@ -111,10 +130,10 @@ armcm = RegisterSet( retval="r0", ) -# FIXME AArch64 does not have a CPSR register +# AArch64 has a PSTATE register, but GDB represents it as the CPSR register aarch64 = RegisterSet( retaddr=("lr",), - flags={"cpsr": {}}, + flags={"cpsr": aarch64_cpsr_flags}, # X29 is the frame pointer register (FP) but setting it # as frame here messes up the register order to the point # it's confusing. Think about improving this if frame