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 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",
)

OutputType module-attribute ¤

OutputType = str | Callable[[str], None]

outputs module-attribute ¤

outputs: dict[str, OutputType] = {}

output_settings module-attribute ¤

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

OutputWrapper module-attribute ¤

OutputWrapper = StdOutput | FileOutput | CallOutput

OutputTarget module-attribute ¤

OutputTarget = TextIO | CallOutput

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 = []

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",
    14,
    "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: dict[str, Callable[..., list[str]]] = {
    "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__() -> TextIO

__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__() -> TextIO

__exit__ ¤

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

__hash__ ¤

__hash__()

__eq__ ¤

__eq__(other)

CallOutput ¤

CallOutput(func: Callable[[str], None])

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()

CompactRegsOptions ¤

Bases: Enum

Attributes:

NO class-attribute instance-attribute ¤

NO = 'off'

YES class-attribute instance-attribute ¤

YES = 'on'

VERY class-attribute instance-attribute ¤

VERY = 'very'

HARDCUT class-attribute instance-attribute ¤

HARDCUT = 'hardcut'

RegisterContext ¤

RegisterContext()

Bases: RegisterContextProtocol

Methods:

Attributes:

changed instance-attribute ¤

changed: list[str] = changed

get_prefix ¤

get_prefix(reg: str) -> str

get_register_value ¤

get_register_value(reg: str) -> int | None

flag_register_context ¤

flag_register_context(reg: str, bit_flags: BitFlags) -> str | None

segment_registers_context ¤

segment_registers_context(regs: list[str]) -> str | None

addressing_register_context ¤

addressing_register_context(reg: str, is_virtual: bool) -> str | None

register_context_default ¤

register_context_default(reg: str) -> str | None

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) -> OutputWrapper

Creates a context manager corresponding to configured context output

contextoutput ¤

contextoutput(
    section: str,
    path: OutputType,
    clearing: bool,
    banner: str = "both",
    width: int | None = None,
    height: int | None = None,
)

resetcontextoutput ¤

resetcontextoutput(section: str) -> None

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: int) -> None

contextnext ¤

contextnext(count: int) -> None

contextsearch ¤

contextsearch(needle: str, section: str | None = None) -> None

contextwatch ¤

contextwatch(expression: str, cmd: str = 'eval') -> None

contextunwatch ¤

contextunwatch(num: int) -> None

context_expressions ¤

context_expressions(
    target: OutputTarget = stdout,
    with_banner: bool = True,
    width: int | None = None,
    height: int | None = None,
) -> list[str]

context ¤

context(
    subcontext: list[str] | None = None, enabled: bool | None = None
) -> None

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

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

calculate_padding_to_align ¤

calculate_padding_to_align(length: int, align: int) -> int

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

compact_regs_hardcut ¤

compact_regs_hardcut(
    regs: list[str],
    terminal_width: int,
    column_width: int,
    columns: int,
    separation: int,
) -> list[str]

If the string of any register overflows its column_width, it will be hard cut to the column_width.

Example

RAX 0xfffffffffffffdfe R8 0 R14 0 RBX 0 R9 0x7fffffffcbd0 —▸ 0x7fff... R15 0x7ffff7f83e60 (_rl_orig... RCX 0x7ffff7c90efa (__intern... R10 0 RBP 1 RDX 0 R11 0x202 RSP 0x7fffffffcb70 ◂— 0 RDI 1 R12 0x7fffffffccb0 ◂— 1 RIP 0x7ffff7c90efa (__intern... RSI 0x7fffffffccb0 ◂— 1 R13 0 EFLAGS 0x202 [ cf pf af zf sf...

compact_regs_normal ¤

compact_regs_normal(
    regs: list[str],
    terminal_width: int,
    column_width: int,
    columns: int,
    separation: int,
) -> list[str]

Will try to group similar registers together, and may increase the number of rows (as opposed to compact_regs_very) in order to achieve this.

column_width does not include separation.

Example

RAX 0xfffffffffffffdfe R8 0 R14 0 RBX 0 R9 ⏎ R15 ⏎ RCX ⏎ R10 0 RBP 1 RDX 0 R11 0x202 RSP 0x7fffffffcb70 ◂— 0 RDI 1 R12 0x7fffffffccb0 ◂— 1 RIP ⏎ RSI 0x7fffffffccb0 ◂— 1 R13 0 EFLAGS ⏎

↪ R9 0x7fffffffcbd0 —▸ 0x7ffff7f83e60 (_rl_orig_sigset) ◂— 0 ↪ R15 0x7ffff7f83e60 (_rl_orig_sigset) ◂— 0 ↪ RCX 0x7ffff7c90efa (__internal_syscall_cancel+138) ◂— add rsp, 0x18 ↪ RIP 0x7ffff7c90efa (__internal_syscall_cancel+138) ◂— add rsp, 0x18 ↪ EFLAGS 0x202 [ cf pf af zf sf IF df of ac ]

compact_regs_very ¤

compact_regs_very(
    regs: list[str],
    terminal_width: int,
    column_width: int,
    columns: int,
    separation: int,
) -> list[str]

Will try to group similar registers together, but will sacrifice the grouping if it can be more compact.

column_width does not include separation.

Example

RAX 0xfffffffffffffdfe R8 0 R14 0 RBX 0 R9 0x7fffffffcbd0 —▸ 0x7ffff7f83e60 (_rl_orig_sigset) ◂— 0 R15 0x7ffff7f83e60 (_rl_orig_sigset) ◂— 0 RCX 0x7ffff7c90efa (__internal_syscall_cancel+138) ◂— add rsp, 0x18 R10 0 RBP 1 RDX 0 R11 0x202 RSP 0x7fffffffcb70 ◂— 0 RDI 1 R12 0x7fffffffccb0 ◂— 1 RIP 0x7ffff7c90efa (__internal_syscall_cancel+138) ◂— add rsp, 0x18 RSI 0x7fffffffccb0 ◂— 1 R13 0 EFLAGS 0x202 [ cf pf af zf sf IF df of ac ]

compact_regs ¤

compact_regs(
    regs: list[str], width: int | None = None, target: OutputTarget = stdout
) -> list[str]

context_regs ¤

context_regs(
    target: OutputTarget = stdout,
    with_banner: bool = True,
    width: int | None = None,
    height: int | None = None,
) -> list[str]

context_heap_tracker ¤

context_heap_tracker(
    target: OutputTarget = stdout,
    with_banner: bool = True,
    width: int | None = None,
    height: int | None = None,
) -> list[str]

regs ¤

regs(regs: list[str | VisitableRegister | None] | None = None) -> None

Print out all registers and enhance the information.

get_regs ¤

get_regs(
    in_regs: list[str | VisitableRegister | None] | None = None,
) -> list[str]

try_emulate_if_bug_disable ¤

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

context_disasm ¤

context_disasm(
    target: OutputTarget = stdout,
    with_banner: bool = True,
    width: int | None = None,
    height: int | None = None,
) -> list[str]

get_highlight_source ¤

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

get_filename_and_formatted_source ¤

get_filename_and_formatted_source(
    height: int | None = None,
) -> tuple[str, list[str], int]

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

context_code ¤

context_code(
    target: OutputTarget = stdout,
    with_banner: bool = True,
    width: int | None = None,
    height: int | None = None,
) -> list[str]

context_stack ¤

context_stack(
    target: OutputTarget = stdout,
    with_banner: bool = True,
    width: int | None = None,
    height: int | None = None,
) -> list[str]

context_backtrace ¤

context_backtrace(
    with_banner: bool = True,
    target: OutputTarget = stdout,
    width: int | None = None,
    height: int | None = None,
) -> list[str]

context_args ¤

context_args(
    with_banner: bool = True,
    target: OutputTarget = stdout,
    width: int | None = None,
    height: int | None = None,
) -> list[str]

get_thread_status ¤

get_thread_status(thread: InferiorThread) -> str

context_threads ¤

context_threads(
    with_banner: bool = True,
    target: OutputTarget = stdout,
    width: int | None = None,
    height: int | None = None,
) -> list[str]

save_signal ¤

save_signal(signal: Event) -> None

context_last_signal ¤

context_last_signal(
    with_banner: bool = True,
    target: OutputTarget = stdout,
    width: int | None = None,
    height: int | None = None,
) -> list[str]