mirror of https://github.com/pwndbg/pwndbg.git
Allow passing an argument to cpsr command (#2032)
parent
8dad24d375
commit
f7ffe38888
@ -1,21 +1,34 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
|
||||||
import pwndbg.commands
|
import pwndbg.commands
|
||||||
import pwndbg.gdblib.arch
|
import pwndbg.gdblib.arch
|
||||||
import pwndbg.gdblib.regs
|
import pwndbg.gdblib.regs
|
||||||
from pwndbg.color import context
|
from pwndbg.color import context
|
||||||
from pwndbg.commands import CommandCategory
|
from pwndbg.commands import CommandCategory
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description="Print out ARM CPSR or xPSR register.")
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"cpsr_value", help="Parse the given CPSR value instead of the actual one.", nargs="?", type=int
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pwndbg.commands.ArgparsedCommand(
|
@pwndbg.commands.ArgparsedCommand(
|
||||||
"Print out ARM CPSR or xPSR register.",
|
parser,
|
||||||
aliases=["xpsr", "pstate"],
|
aliases=["xpsr", "pstate"],
|
||||||
category=CommandCategory.REGISTER,
|
category=CommandCategory.REGISTER,
|
||||||
)
|
)
|
||||||
@pwndbg.commands.OnlyWithArch(["arm", "armcm", "aarch64"])
|
@pwndbg.commands.OnlyWithArch(["arm", "armcm", "aarch64"])
|
||||||
@pwndbg.commands.OnlyWhenRunning
|
@pwndbg.commands.OnlyWhenRunning
|
||||||
def cpsr() -> None:
|
def cpsr(cpsr_value=None) -> None:
|
||||||
reg = "xpsr" if pwndbg.gdblib.arch.name == "armcm" else "cpsr"
|
reg = "xpsr" if pwndbg.gdblib.arch.name == "armcm" else "cpsr"
|
||||||
reg_val = getattr(pwndbg.gdblib.regs, reg)
|
|
||||||
reg_flags = pwndbg.gdblib.regs.flags[reg]
|
reg_flags = pwndbg.gdblib.regs.flags[reg]
|
||||||
|
|
||||||
|
if cpsr_value is not None:
|
||||||
|
reg_val = cpsr_value
|
||||||
|
else:
|
||||||
|
reg_val = getattr(pwndbg.gdblib.regs, reg)
|
||||||
|
|
||||||
print(f"{reg} {context.format_flags(reg_val, reg_flags)}")
|
print(f"{reg} {context.format_flags(reg_val, reg_flags)}")
|
||||||
|
|||||||
Loading…
Reference in new issue