diff --git a/docs/commands/kernel/klookup.md b/docs/commands/kernel/klookup.md index 562225982..4ca256338 100644 --- a/docs/commands/kernel/klookup.md +++ b/docs/commands/kernel/klookup.md @@ -22,5 +22,9 @@ Lookup kernel symbols |-h|--help|show this help message and exit| |-a|--apply|applies all the symbols that satisfy the filter| +### Notes +Using `--apply` makes sense for kernel modules. If you want to symbolize the whole kernel, +use vmlinux-to-elf (https://github.com/marin-m/vmlinux-to-elf) or compile it yourself. + diff --git a/docs/contributing/adding-a-command.md b/docs/contributing/adding-a-command.md index e633c223c..b251e26d9 100644 --- a/docs/contributing/adding-a-command.md +++ b/docs/contributing/adding-a-command.md @@ -175,7 +175,7 @@ OnlyWithFile OnlyWhenQemuKernel OnlyWhenUserspace OnlyWithKernelDebugInfo -OnlyWithKernelDebugSymbols +OnlyWithKernelSymbols OnlyWhenPagingEnabled OnlyWithTcache OnlyWhenHeapIsInitialized diff --git a/pwndbg/commands/__init__.py b/pwndbg/commands/__init__.py index f0b7a8af3..197aa887f 100644 --- a/pwndbg/commands/__init__.py +++ b/pwndbg/commands/__init__.py @@ -655,18 +655,21 @@ def OnlyWithKernelDebugInfo(function: Callable[P, T]) -> Callable[P, Optional[T] return _OnlyWithKernelDebugInfo -def OnlyWithKernelDebugSymbols(function: Callable[P, T]) -> Callable[P, Optional[T]]: +def OnlyWithKernelSymbols(function: Callable[P, T]) -> Callable[P, Optional[T]]: @functools.wraps(function) - def _OnlyWithKernelDebugSymbols(*a: P.args, **kw: P.kwargs) -> Optional[T]: + def _OnlyWithKernelSymbols(*a: P.args, **kw: P.kwargs) -> Optional[T]: if pwndbg.aglib.kernel.has_debug_symbols(): return function(*a, **kw) else: log.error( - f"{func_name(function)}: This command may only be run when debugging a Linux kernel with debug symbols." + f"{func_name(function)}: This command may only be run when debugging a Linux kernel with symbols.\n" + + message.hint( + "Check out vmlinux-to-elf to get them easily (https://github.com/marin-m/vmlinux-to-elf) or compile the kernel yourself." + ) ) return None - return _OnlyWithKernelDebugSymbols + return _OnlyWithKernelSymbols def OnlyWhenPagingEnabled(function: Callable[P, T]) -> Callable[P, Optional[T]]: diff --git a/pwndbg/commands/buddydump.py b/pwndbg/commands/buddydump.py index c26a192f4..e0d6456b1 100644 --- a/pwndbg/commands/buddydump.py +++ b/pwndbg/commands/buddydump.py @@ -332,7 +332,7 @@ v @pwndbg.commands.Command(parser, category=CommandCategory.KERNEL) @pwndbg.commands.OnlyWhenQemuKernel -@pwndbg.commands.OnlyWithKernelDebugSymbols +@pwndbg.commands.OnlyWithKernelSymbols @pwndbg.commands.OnlyWhenPagingEnabled def buddydump( zone: str, pcp_only: bool, order: int, mtype: str, cpu: int, node: int, find: int diff --git a/pwndbg/commands/kbpf.py b/pwndbg/commands/kbpf.py index 079798e7c..6eb192ca9 100644 --- a/pwndbg/commands/kbpf.py +++ b/pwndbg/commands/kbpf.py @@ -226,7 +226,7 @@ def print_bpf_maps(verbose): @pwndbg.commands.Command(parser, category=CommandCategory.KERNEL) @pwndbg.commands.OnlyWhenQemuKernel -@pwndbg.commands.OnlyWithKernelDebugSymbols +@pwndbg.commands.OnlyWithKernelSymbols @pwndbg.commands.OnlyWhenPagingEnabled def kbpf(verbose: int, print_progs: bool, print_maps: bool): if not pwndbg.aglib.kernel.has_debug_info(): diff --git a/pwndbg/commands/kdmabuf.py b/pwndbg/commands/kdmabuf.py index a489af9fe..a64414c97 100644 --- a/pwndbg/commands/kdmabuf.py +++ b/pwndbg/commands/kdmabuf.py @@ -5,6 +5,7 @@ import argparse import pwndbg.aglib.kernel import pwndbg.aglib.kernel.dmabuf import pwndbg.color.message as M +import pwndbg.commands from pwndbg.aglib.kernel.macros import for_each_entry from pwndbg.commands import CommandCategory from pwndbg.lib.exception import IndentContextManager @@ -60,7 +61,7 @@ def print_sgl(sgl, indent): # adapted from https://github.com/bata24/gef/tree/dev @pwndbg.commands.Command(parser, category=CommandCategory.KERNEL) @pwndbg.commands.OnlyWhenQemuKernel -@pwndbg.commands.OnlyWithKernelDebugSymbols +@pwndbg.commands.OnlyWithKernelSymbols @pwndbg.commands.OnlyWhenPagingEnabled def kdmabuf(): db_name = "db_list" diff --git a/pwndbg/commands/klookup.py b/pwndbg/commands/klookup.py index 6d82302b1..b91455bd4 100644 --- a/pwndbg/commands/klookup.py +++ b/pwndbg/commands/klookup.py @@ -15,7 +15,15 @@ parser.add_argument( ) -@pwndbg.commands.Command(parser, aliases=["kallsyms", "ks"], category=CommandCategory.KERNEL) +@pwndbg.commands.Command( + parser, + aliases=["kallsyms", "ks"], + category=CommandCategory.KERNEL, + notes=""" +Using `--apply` makes sense for kernel modules. If you want to symbolize the whole kernel, +use vmlinux-to-elf (https://github.com/marin-m/vmlinux-to-elf) or compile it yourself. +""", +) @pwndbg.commands.OnlyWhenQemuKernel @pwndbg.commands.OnlyWhenPagingEnabled def klookup(symbol: str, apply: bool) -> None: diff --git a/pwndbg/commands/kmem_trace.py b/pwndbg/commands/kmem_trace.py index ffe8c663f..1db8483a7 100644 --- a/pwndbg/commands/kmem_trace.py +++ b/pwndbg/commands/kmem_trace.py @@ -276,7 +276,7 @@ steps out of the current function. You may also find `-c finish` and `-c continu only_debuggers={DebuggerType.GDB, DebuggerType.LLDB}, ) @pwndbg.commands.OnlyWhenQemuKernel -@pwndbg.commands.OnlyWithKernelDebugSymbols +@pwndbg.commands.OnlyWithKernelSymbols @pwndbg.commands.OnlyWhenPagingEnabled def kmem_trace(trace_slab: bool, trace_buddy: bool, verbose: bool, command: str, all: bool) -> None: if pwndbg.aglib.regs.retval is None: diff --git a/pwndbg/commands/kmod.py b/pwndbg/commands/kmod.py index c5495cc05..5d080ecdd 100644 --- a/pwndbg/commands/kmod.py +++ b/pwndbg/commands/kmod.py @@ -24,7 +24,7 @@ parser.add_argument("-l", "--load", dest="path", type=str, help="the path of the @pwndbg.commands.Command(parser, category=pwndbg.commands.CommandCategory.KERNEL) @pwndbg.commands.OnlyWhenQemuKernel @pwndbg.commands.OnlyWhenPagingEnabled -@pwndbg.commands.OnlyWithKernelDebugSymbols +@pwndbg.commands.OnlyWithKernelSymbols def kmod(module_name=None, path=None) -> None: # Look up the address of the `modules` symbol, containing the head of the linked list of kernel modules modules_head = pwndbg.aglib.kernel.modules() diff --git a/pwndbg/commands/ksyscalls.py b/pwndbg/commands/ksyscalls.py index a56f7294d..eceda8dda 100644 --- a/pwndbg/commands/ksyscalls.py +++ b/pwndbg/commands/ksyscalls.py @@ -19,7 +19,7 @@ parser.add_argument("syscall_name", nargs="?", type=str, help="A syscall name to @pwndbg.commands.Command(parser, category=pwndbg.commands.CommandCategory.KERNEL) @pwndbg.commands.OnlyWhenQemuKernel @pwndbg.commands.OnlyWhenPagingEnabled -@pwndbg.commands.OnlyWithKernelDebugSymbols +@pwndbg.commands.OnlyWithKernelSymbols def ksyscalls(syscall_name=None) -> None: # Look up the address of the sys_call_table symbol. table_addr = pwndbg.aglib.symbol.lookup_symbol_addr("sys_call_table") diff --git a/pwndbg/commands/paging.py b/pwndbg/commands/paging.py index 2471c34c9..aea213de9 100644 --- a/pwndbg/commands/paging.py +++ b/pwndbg/commands/paging.py @@ -5,9 +5,12 @@ import math import pwndbg.aglib.kernel import pwndbg.aglib.kernel.paging +import pwndbg.aglib.memory import pwndbg.aglib.regs +import pwndbg.chain import pwndbg.color as C import pwndbg.color.message as M +import pwndbg.commands from pwndbg.aglib.kernel.paging import PageTableLevel from pwndbg.commands import CommandCategory @@ -125,7 +128,7 @@ p2v_parser.add_argument("paddr", type=str, help="") @pwndbg.commands.Command(p2v_parser, category=CommandCategory.KERNEL) @pwndbg.commands.OnlyWhenQemuKernel -@pwndbg.commands.OnlyWithKernelDebugSymbols +@pwndbg.commands.OnlyWithKernelSymbols @pwndbg.commands.OnlyWhenPagingEnabled @pwndbg.aglib.proc.OnlyWithArch(["x86-64", "aarch64"]) def p2v(paddr): @@ -147,7 +150,7 @@ v2p_parser.add_argument("vaddr", type=str, help="") @pwndbg.commands.Command(v2p_parser, category=CommandCategory.KERNEL) @pwndbg.commands.OnlyWhenQemuKernel -@pwndbg.commands.OnlyWithKernelDebugSymbols +@pwndbg.commands.OnlyWithKernelSymbols @pwndbg.commands.OnlyWhenPagingEnabled @pwndbg.aglib.proc.OnlyWithArch(["x86-64", "aarch64"]) def v2p(vaddr): @@ -171,7 +174,7 @@ page_parser.add_argument("page", type=str, help="") @pwndbg.commands.Command(page_parser, category=CommandCategory.KERNEL) @pwndbg.commands.OnlyWhenQemuKernel -@pwndbg.commands.OnlyWithKernelDebugSymbols +@pwndbg.commands.OnlyWithKernelSymbols @pwndbg.commands.OnlyWhenPagingEnabled @pwndbg.aglib.proc.OnlyWithArch(["x86-64", "aarch64"]) def pageinfo(page): diff --git a/pwndbg/commands/slab.py b/pwndbg/commands/slab.py index aa2ccd91e..162c0a93c 100644 --- a/pwndbg/commands/slab.py +++ b/pwndbg/commands/slab.py @@ -65,7 +65,7 @@ parser_contains.add_argument("addresses", metavar="addr", type=str, nargs="+", h @pwndbg.commands.Command(parser, category=CommandCategory.KERNEL) @pwndbg.commands.OnlyWhenQemuKernel -@pwndbg.commands.OnlyWithKernelDebugSymbols +@pwndbg.commands.OnlyWithKernelSymbols @pwndbg.commands.OnlyWhenPagingEnabled def slab( command,