adding decoration for cpu arch

pull/3051/head
jxuanli 6 months ago
parent c48e84016b
commit 84aa120f68

@ -142,6 +142,7 @@ class CommandObj:
aliases: List[str],
examples: str,
notes: str,
archs: List[str] | None,
/, # All parameters must be passed in positionally
) -> None:
assert function
@ -166,6 +167,7 @@ class CommandObj:
assert category
self.category = category
self.archs = archs
self.aliases = aliases
self.examples = examples.strip()
@ -286,6 +288,10 @@ class CommandObj:
log.error("Pwndbg commands require a target binary to be selected")
return
if self.archs is not None and pwndbg.aglib.arch.name not in self.archs:
log.error(f"The CPU architecutre must be one of {self.archs}")
return
# Put the arguments through the debugger
try:
arg_list = pwndbg.dbg.lex_args(argument)
@ -367,6 +373,7 @@ class Command:
notes: str = "",
only_debuggers: Set[pwndbg.dbg_mod.DebuggerType] = None,
exclude_debuggers: Set[pwndbg.dbg_mod.DebuggerType] = None,
archs: List[str] = None,
) -> None:
# Setup an ArgumentParser even if we were only passed a description.
if isinstance(parser_or_desc, str):
@ -382,6 +389,7 @@ class Command:
self.notes = notes
self.only_debuggers = only_debuggers
self.exclude_debuggers = exclude_debuggers
self.archs = archs
def __call__(self, function: Callable[..., Any]) -> CommandObj:
# Since this is the __call__ of a parametrized decorator, it is
@ -420,6 +428,7 @@ class Command:
self.aliases,
self.examples,
self.notes,
self.archs,
)

@ -34,7 +34,7 @@ def pg_indices(vaddr, nr_level):
return result
@pwndbg.commands.Command(parser, category=CommandCategory.KERNEL)
@pwndbg.commands.Command(parser, category=CommandCategory.KERNEL, archs=["x86-64"])
@pwndbg.commands.OnlyWhenQemuKernel
@pwndbg.commands.OnlyWhenPagingEnabled
def pagewalk(vaddr, entry=None):

@ -178,8 +178,8 @@ def test_command_buddydump():
@pytest.mark.skipif(
pwndbg.aglib.arch.name not in ["i386", "x86-64"],
reason="pagewalk is only fully implemented for x86 (partially relies on cr3)",
pwndbg.aglib.arch.name not in ["x86-64"],
reason="pagewalk is only fully implemented for x64",
)
def test_command_pagewalk():
address = pwndbg.aglib.kernel.kbase()

Loading…
Cancel
Save