Skip to content

context ¤

Classes:

Functions:

Attributes:

log module-attribute ¤

log = getLogger(__name__)

T module-attribute ¤

T = TypeVar('T')

P module-attribute ¤

P = ParamSpec('P')

c module-attribute ¤

c = ColorConfig(
    "backtrace",
    [
        ColorParamSpec(
            "prefix", "none", "color for prefix of current backtrace label"
        ),
        ColorParamSpec("address", "none", "color for backtrace (address)"),
        ColorParamSpec("symbol", "none", "color for backtrace (symbol)"),
        ColorParamSpec(
            "frame-label", "none", "color for backtrace (frame label)"
        ),
    ],
)

config_reserve_lines module-attribute ¤

config_reserve_lines = add_param(
    "context-reserve-lines",
    "if-ctx-fits",
    "when to reserve lines after the prompt to reduce context shake",
    help_docstring='\nThe "if-ctx-fits" setting only reserves lines if the whole context would still fit vertically in the current terminal window.\nIt doesn\'t take into account line-wrapping due to insufficient terminal width.\n',
    param_class=PARAM_ENUM,
    enum_sequence=["never", "if-ctx-fits", "always"],
)

config_clear_screen module-attribute ¤

config_clear_screen = add_param(
    "context-clear-screen",
    False,
    "whether to clear the screen before printing the context",
)

config_output module-attribute ¤

config_output = add_param(
    "context-output",
    "stdout",
    'where pwndbg should output ("stdout" or file/tty)',
)

config_context_sections module-attribute ¤

config_context_sections = add_param(
    "context-sections",
    "regs disasm code ghidra stack backtrace expressions threads heap_tracker",
    "which context sections are displayed (controls order)",
)

config_max_threads_display module-attribute ¤

config_max_threads_display = add_param(
    "context-max-threads",
    4,
    "maximum number of threads displayed by the context command",
)

outputs module-attribute ¤

outputs: dict[str, str] = {}

output_settings module-attribute ¤

output_settings: DefaultDict[str, dict[str, Any]] = defaultdict(dict)

banner_arg module-attribute ¤

banner_arg = add_argument(
    "banner",
    type=str,
    nargs="?",
    default="both",
    help="Where a banner should be placed: both, top , bottom, none",
)

context_history module-attribute ¤

context_history: DefaultDict[str, list[list[str]]] = defaultdict(list)

selected_history_index module-attribute ¤

selected_history_index: int | None = None

context_history_size module-attribute ¤

context_history_size = add_param(
    "context-history-size", 50, "number of context history entries to store"
)

expressions module-attribute ¤

expressions = []

config_context_ghidra module-attribute ¤

config_context_ghidra = add_param(
    "context-ghidra",
    "never",
    "when to try to decompile the current function with ghidra",
    help_docstring="Doing this is slow and requires radare2/r2pipe or rizin/rzpipe.",
    param_class=PARAM_ENUM,
    enum_sequence=["always", "never", "if-no-source"],
)

parser module-attribute ¤

parser = ArgumentParser(
    description="Print out all registers and enhance the information."
)

disasm_lines module-attribute ¤

disasm_lines = add_param(
    "context-disasm-lines",
    10,
    "number of additional lines to print in the disasm context",
)

source_disasm_lines module-attribute ¤

source_disasm_lines = add_param(
    "context-code-lines",
    10,
    "number of source code lines to print by the context command",
)

should_decompile module-attribute ¤

should_decompile = add_param(
    "context-integration-decompile",
    True,
    "whether context should fall back to decompilation with no source code",
)

stack_lines module-attribute ¤

stack_lines = add_param(
    "context-stack-lines", 8, "number of lines to print in the stack context"
)

backtrace_lines module-attribute ¤

backtrace_lines = add_param(
    "context-backtrace-lines",
    8,
    "number of lines to print in the backtrace context",
)

backtrace_frame_label module-attribute ¤

backtrace_frame_label = add_param(
    "backtrace-frame-label", "", "frame number label for backtrace"
)

last_signal module-attribute ¤

last_signal: list[str] = []

thread_status_messages module-attribute ¤

thread_status_messages = {
    "running": light_green("running"),
    "stopped": yellow("stopped"),
    "exited": gray("exited "),
}

context_sections module-attribute ¤

context_sections = {
    "a": context_args,
    "r": context_regs,
    "d": context_disasm,
    "s": context_stack,
    "b": context_backtrace,
    "c": context_code,
}

StdOutput ¤

A context manager wrapper to give stdout

Methods:

__enter__ ¤

__enter__()

__exit__ ¤

__exit__(*args, **kwargs) -> None

__hash__ ¤

__hash__()

__eq__ ¤

__eq__(other) -> bool

FileOutput ¤

FileOutput(*args)

A context manager wrapper to reopen files on enter

Methods:

Attributes:

args instance-attribute ¤

args = args

handle instance-attribute ¤

handle = None

__enter__ ¤

__enter__()

__exit__ ¤

__exit__(*args, **kwargs) -> None

__hash__ ¤

__hash__()

__eq__ ¤

__eq__(other)

CallOutput ¤

CallOutput(func)

A context manager which calls a function on write

Methods:

Attributes:

func instance-attribute ¤

func = func

__enter__ ¤

__enter__()

__exit__ ¤

__exit__(*args, **kwargs) -> None

__hash__ ¤

__hash__()

__eq__ ¤

__eq__(other)

write ¤

write(data) -> None

writelines ¤

writelines(lines_iterable) -> None

flush ¤

flush()

isatty ¤

isatty()

RegisterContext ¤

RegisterContext()

Methods:

Attributes:

changed instance-attribute ¤

changed: list[str] = changed

get_prefix ¤

get_prefix(reg)

get_register_value ¤

get_register_value(reg)

flag_register_context ¤

flag_register_context(reg, bit_flags)

segment_registers_context ¤

segment_registers_context(regs)

addressing_register_context ¤

addressing_register_context(reg, is_virtual)

register_context_default ¤

register_context_default(reg)

clear_screen ¤

clear_screen(out=stdout) -> None

Clear the screen by moving the cursor to top-left corner and clearing the content. Different terminals may act differently

reserve_lines_maybe ¤

reserve_lines_maybe(cmd_lines: int) -> None

Scroll the terminal up a few lines to reduce shaking when repeatedly printing the context.

Only do this if the context would still fit on the screen.

validate_context_sections ¤

validate_context_sections() -> None

output ¤

output(section: str)

Creates a context manager corresponding to configured context output

contextoutput ¤

contextoutput(section, path, clearing, banner='both', width: int = None)

resetcontextoutput ¤

resetcontextoutput(section)

history_size_changed ¤

history_size_changed() -> None

serve_context_history ¤

serve_context_history(
    function: Callable[P, list[str]],
) -> Callable[P, list[str]]

history_handle_unchanged_contents ¤

history_handle_unchanged_contents() -> None

contextprev ¤

contextprev(count) -> None

contextnext ¤

contextnext(count) -> None

contextsearch ¤

contextsearch(needle, section) -> None

contextwatch ¤

contextwatch(expression, cmd) -> None

contextunwatch ¤

contextunwatch(num) -> None

context_expressions ¤

context_expressions(target=stdout, with_banner=True, width=None)

context_ghidra ¤

context_ghidra(target=stdout, with_banner=True, width=None)

Print out the source of the current function decompiled by ghidra.

The context-ghidra config parameter is used to configure whether to always, never or only show the context if no source is available.

context ¤

context(subcontext=None, enabled=None) -> None

Print out the current register, instruction, and stack context.

Accepts subcommands 'reg', 'disasm', 'code', 'stack', 'backtrace', 'ghidra', 'args', 'threads', 'heap_tracker', 'expressions', and/or 'last_signal'.

calculate_padding_to_align ¤

calculate_padding_to_align(length, align)

Calculates the number of spaces to append to reach the next alignment. The next alignment point is given by "x * align >= length".

compact_regs ¤

compact_regs(regs, width=None, target=stdout)

context_regs ¤

context_regs(target=stdout, with_banner=True, width=None)

context_heap_tracker ¤

context_heap_tracker(target=stdout, with_banner=True, width=None)

regs ¤

regs(regs=[]) -> None

Print out all registers and enhance the information.

get_regs ¤

get_regs(regs: list[str] = None)

try_emulate_if_bug_disable ¤

try_emulate_if_bug_disable(handler: Callable[[], T]) -> T

context_disasm ¤

context_disasm(target=stdout, with_banner=True, width=None)

get_highlight_source ¤

get_highlight_source(filename: str) -> tuple[str, ...]

get_filename_and_formatted_source ¤

get_filename_and_formatted_source()

Returns formatted, lines limited and highlighted source as list or if it isn't there - an empty list

context_code ¤

context_code(target=stdout, with_banner=True, width=None)

context_stack ¤

context_stack(target=stdout, with_banner=True, width=None)

context_backtrace ¤

context_backtrace(with_banner=True, target=stdout, width=None)

context_args ¤

context_args(with_banner=True, target=stdout, width=None)

get_thread_status ¤

get_thread_status(thread)

context_threads ¤

context_threads(with_banner=True, target=stdout, width=None)

save_signal ¤

save_signal(signal) -> None

context_last_signal ¤

context_last_signal(with_banner=True, target=stdout, width=None)