diff --git a/docs/commands/index.md b/docs/commands/index.md index cb72d070f..15e995157 100644 --- a/docs/commands/index.md +++ b/docs/commands/index.md @@ -104,7 +104,6 @@ - [pagewalk](kernel/pagewalk.md) - Performs pagewalk. - [slab](kernel/slab.md) - Prints information about the linux kernel's slab allocator SLUB. - [v2p](kernel/v2p.md) - Translate virtual address to its corresponding physmap address. -- [vmlinux](kernel/vmlinux.md) - Load bzImage or vmlinux file to add kernel debug symbols. ## Linux/libc/ELF diff --git a/docs/commands/kernel/vmlinux.md b/docs/commands/kernel/vmlinux.md deleted file mode 100644 index 5f9910b1e..000000000 --- a/docs/commands/kernel/vmlinux.md +++ /dev/null @@ -1,24 +0,0 @@ - -# vmlinux - -```text -usage: vmlinux [-h] [-t TOOL] filepath - -``` - -Load bzImage or vmlinux file to add kernel debug symbols. -### Positional arguments - -|Positional Argument|Help| -| :--- | :--- | -|filepath|Path to the bzImage or vmlinux file to load| - -### Optional arguments - -|Short|Long|Help| -| :--- | :--- | :--- | -|-h|--help|show this help message and exit| -|-t|--tool|Path to the vmlinux-to-elf tool (if not in PATH)| - - - diff --git a/pwndbg/commands/__init__.py b/pwndbg/commands/__init__.py index 197aa887f..fcb819975 100644 --- a/pwndbg/commands/__init__.py +++ b/pwndbg/commands/__init__.py @@ -996,7 +996,6 @@ def load_commands() -> None: import pwndbg.commands.tls import pwndbg.commands.valist import pwndbg.commands.version - import pwndbg.commands.vmlinux import pwndbg.commands.vmmap import pwndbg.commands.windbg import pwndbg.commands.xinfo diff --git a/pwndbg/commands/vmlinux.py b/pwndbg/commands/vmlinux.py deleted file mode 100644 index a9dd84311..000000000 --- a/pwndbg/commands/vmlinux.py +++ /dev/null @@ -1,124 +0,0 @@ -""" -Loads a bzImage or vmlinux file to add kernel debug symbols. This command uses vmlinux-to-elf -to extract the ELF file from a bzImage and then loads it with the kernel base address. -""" - -from __future__ import annotations - -import argparse -import os -import shutil -import subprocess -import tempfile - -import pwndbg.aglib.kernel -import pwndbg.color.message as M -import pwndbg.commands -import pwndbg.dbg -from pwndbg.commands import CommandCategory - -parser = argparse.ArgumentParser( - description="Load bzImage or vmlinux file to add kernel debug symbols." -) -parser.add_argument( - "filepath", - type=str, - help="Path to the bzImage or vmlinux file to load", -) -parser.add_argument( - "-t", - "--tool", - type=str, - help="Path to the vmlinux-to-elf tool (if not in PATH)", -) - - -@pwndbg.commands.Command(parser, category=CommandCategory.KERNEL) -@pwndbg.commands.OnlyWhenQemuKernel -@pwndbg.commands.OnlyWhenPagingEnabled -def vmlinux(filepath: str, tool: str = None) -> None: - # Verify the input file exists - if not os.path.isfile(filepath): - print(M.error(f"File not found: {filepath}")) - return - - # Get the kernel base address - base = pwndbg.aglib.kernel.arch_paginginfo().kbase - if base is None: - print(M.error("Unable to locate the kernel base address")) - return - - print(M.success(f"Found kernel base address: {hex(base)}")) - - # Find vmlinux-to-elf tool - if tool: - # User specified the tool path - vmlinux_tool = tool - if not os.path.isfile(vmlinux_tool): - print(M.error(f"Specified tool not found: {vmlinux_tool}")) - return - if not os.access(vmlinux_tool, os.X_OK): - print(M.error(f"Specified tool is not executable: {vmlinux_tool}")) - return - else: - # GDB may not inherit the full PATH, so check common locations - vmlinux_tool = shutil.which("vmlinux-to-elf") - if not vmlinux_tool: - # Check common user install locations - common_paths = [ - os.path.expanduser("~/.local/bin/vmlinux-to-elf"), - "/usr/local/bin/vmlinux-to-elf", - "/usr/bin/vmlinux-to-elf", - ] - for path in common_paths: - if os.path.isfile(path) and os.access(path, os.X_OK): - vmlinux_tool = path - break - - if not vmlinux_tool: - print( - M.error( - "vmlinux-to-elf tool not found in PATH or common locations.\n" - "Please install it or ensure it's in: ~/.local/bin, /usr/local/bin, or /usr/bin\n" - "You can install it with: pip install --user vmlinux-to-elf\n" - "Or specify the tool path with: vmlinux --tool " - ) - ) - return - - # Create a temporary file for the extracted ELF - with tempfile.NamedTemporaryFile(delete=False, suffix=".elf") as tmpfile: - tmpfile_path = tmpfile.name - - try: - # Run vmlinux-to-elf to extract the ELF file - print(f"Extracting ELF from {filepath} using vmlinux-to-elf...") - result = subprocess.run( - [vmlinux_tool, filepath, tmpfile_path], - capture_output=True, - text=True, - ) - - if result.returncode != 0: - print(M.error(f"vmlinux-to-elf failed with error:\n{result.stderr}")) - return - - print(M.success(f"Successfully extracted ELF to {tmpfile_path}")) - - # Add the symbol file with the kernel base address - print(f"Loading symbols at address {hex(base)}...") - pwndbg.dbg.selected_inferior().add_symbol_file(tmpfile_path, base) - print(M.success(f"Loaded kernel symbols from {filepath} successfully")) - - except FileNotFoundError: - print( - M.error( - "vmlinux-to-elf tool not found. Please ensure it is installed and in your PATH." - ) - ) - except Exception as e: - print(M.error(f"Error loading symbols: {str(e)}")) - finally: - # Note: We don't delete the temp file here because GDB needs it to remain accessible - # for as long as the debugging session is active - pass