Skip to content

Commit

Permalink
Add klookup command
Browse files Browse the repository at this point in the history
  • Loading branch information
chrf01 committed Oct 5, 2024
1 parent 5243fe6 commit d04500c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions pwndbg/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ def load_commands() -> None:
import pwndbg.commands.kcmdline
import pwndbg.commands.kconfig
import pwndbg.commands.killthreads
import pwndbg.commands.klookup
import pwndbg.commands.kversion
import pwndbg.commands.linkmap
import pwndbg.commands.memoize
Expand Down
32 changes: 32 additions & 0 deletions pwndbg/commands/klookup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from __future__ import annotations

import argparse

import pwndbg.commands
import pwndbg.gdblib.kernel.kallsyms
from pwndbg.color import message
from pwndbg.commands import CommandCategory

parser = argparse.ArgumentParser(description="Lookup kernel symbols")

parser.add_argument("symbol", type=str, help="Address or symbol name to lookup")


@pwndbg.commands.ArgparsedCommand(parser, category=CommandCategory.KERNEL)
@pwndbg.commands.OnlyWhenQemuKernel
@pwndbg.commands.OnlyWhenPagingEnabled
def klookup(symbol: str) -> None:
ksyms = pwndbg.gdblib.kernel.kallsyms.get()
try:
symbol_addr = int(symbol)
for k, v in ksyms.items():
if v[0] == symbol_addr:
print(message.success(f"{k} = {symbol_addr:#x}"))
return
print(message.error(f"No symbol found at {symbol_addr:#x}"))
except ValueError:
if symbol in ksyms:
addr = ksyms[symbol][0]
print(message.success(f"{symbol} = {addr:#x}"))
else:
print(message.error(f"No symbol found for {symbol}"))

0 comments on commit d04500c

Please sign in to comment.