Skip to content

pretty_print ¤

Classes:

  • Property

    A (property name, property value) pair

Functions:

Attributes:

max_decimal_number module-attribute ¤

max_decimal_number = add_param(
    "max-decimal-number",
    9,
    "show all numbers greater than this in hex",
    param_class=PARAM_ZUINTEGER_UNLIMITED,
    help_docstring="\nFor negative numbers, their absolute value is used.\n\nSet the parameter to 'unlimited' if you want all values in decimal.\nSpecially, set the parameter to zero if you want all values in hex.\n\nThe assembly instruction operands come from capstone, and are thus\nnot controlled by this setting. For consistency with them, leave\nthis setting at 9 (the default).\n",
)

config_property_name_color module-attribute ¤

config_property_name_color = add_color_param(
    "prop-name-color",
    "bold",
    "color used to highlight the name in name-value pairs",
    help_docstring="\nUsed heavily in mallocng commands.\n",
)

config_property_value_color module-attribute ¤

config_property_value_color = add_color_param(
    "prop-value-color",
    "yellow",
    "color used to highlight the value in name-value pairs",
    help_docstring="\nUsed heavily in mallocng commands.\n",
)

config_property_title_color module-attribute ¤

config_property_title_color = add_color_param(
    "prop-title-color",
    "green",
    "color used to highlight the title of name-value pair groups",
    help_docstring="\nUsed heavily in mallocng commands.\n",
)

Property dataclass ¤

Property(
    name: str,
    value: Any,
    alt_value: Any = None,
    extra: str | list[str] = "",
    is_addr: bool = False,
    use_hex: bool = True,
    name_color_func: Callable[[str], str] | None = None,
    value_color_func: Callable[[str], str] | None = None,
)

A (property name, property value) pair with optional extra information.

Used by from_properties().

Attributes:

name instance-attribute ¤

name: str

value instance-attribute ¤

value: Any

alt_value class-attribute instance-attribute ¤

alt_value: Any = None

extra class-attribute instance-attribute ¤

extra: str | list[str] = ''

is_addr class-attribute instance-attribute ¤

is_addr: bool = False

use_hex class-attribute instance-attribute ¤

use_hex: bool = True

name_color_func class-attribute instance-attribute ¤

name_color_func: Callable[[str], str] | None = None

value_color_func class-attribute instance-attribute ¤

value_color_func: Callable[[str], str] | None = None

int_to_string ¤

int_to_string(num: int) -> str

Converts an integer value to string.

Decides whether to format it in decimal or hex depending on the max-decimal-number config.

int_pair_to_string ¤

int_pair_to_string(num1: int, num2: int) -> tuple[str, str]

Converts an integer pair to a string pair.

Decides whether to format them in decimal or hex depending on the max-decimal-number config.

If either value should be hex, both are hex.

from_properties ¤

from_properties(
    title: str,
    properties: list[Property],
    *,
    preamble: str = "",
    value_offset: int = 14,
    extra_offset: int = 16,
    title_color_func: Callable[[str], str] | None = None,
    name_color_func: Callable[[str], str] | None = None,
    value_color_func: Callable[[str], str] | None = None,
    indent_size: int = 2,
) -> str

When you have (property name, property value) pairs that you want to print, each on a new line.

A common usecase is printing a struct.

Example

general start: 0x7ffff7ff6040 user start: 0x7ffff7ff6040 aka p end: 0x7ffff7ff606c start + stride - 4 stride: 0x30 distance between adjacent slots user size: 0x20 aka "nominal size", n slack: 0x0 (0x0) slot's unused memory / 0x10

Parameters:

  • title (str) –

    The title of this property group. An empty string may be provided for a titleless group.

  • properties (list[Property]) –

    The list of properties to format.

  • preamble (str, default: '' ) –

    A string that will be printed between the title and the properties, may be used to denote the address of an object like e.g. @ 0x408000 - 0x408fe0

  • value_offset (int, default: 14 ) –

    The number of characters from the start of the name of a property to the start of its value.

  • extra_offset (int, default: 16 ) –

    The number of characters from the start of the value of a property to the start of its extra text.

  • title_color_func (Callable[[str], str] | None, default: None ) –

    The function to use to color the title.

  • name_color_func (Callable[[str], str] | None, default: None ) –

    The function to use to color names.

  • value_color_func (Callable[[str], str] | None, default: None ) –

    The function to use to color values. This function isn't applied to is_addr=True properties.

  • indent_size (int, default: 2 ) –

    The indentation to use i.e. the offset from the title to the names.